Long-Term Potentiation in Code: Making Memories Permanent
Long-Term Potentiation in Code
In the brain, some memories become permanent. Not everything, but the important stuff. We implement the same principle.
What is LTP?
Long-Term Potentiation (LTP) is a biological process where repeated synaptic activation causes lasting strengthening. First observed in rabbit hippocampi by Bliss and Lømo in 1973.
Key properties:
1. **Input specificity**: Only activated synapses strengthen
2. **Cooperativity**: Multiple inputs strengthen more than one
3. **Persistence**: Changes last hours to lifetime
The Problem with Uniform Decay
Simple memory systems apply uniform decay:
// Naive approach
for memory in memories {
memory.strength *= DECAY_RATE; // Everything fades equally
}
This loses important knowledge. The user's core preferences shouldn't decay just because they weren't mentioned today.
Our LTP Implementation
Strength Tracking
Every memory and graph edge tracks:
pub struct MemoryMetadata {
strength: f32, // Current strength (0.0 - 1.0)
access_count: u32, // Total accesses
access_pattern: Vec<Timestamp>, // Recent access times
permanent: bool, // LTP achieved?
}
LTP Criteria
A memory becomes permanent when:
fn check_ltp(memory: &Memory) -> bool {
// Minimum strength threshold
if memory.strength < 0.8 {
return false;
}
// Minimum access count
if memory.access_count < 10 {
return false;
}
// Spaced repetition pattern
let intervals = compute_intervals(&memory.access_pattern);
if !has_spaced_pattern(&intervals) {
return false;
}
true // Achieves LTP
}
The spaced pattern check ensures the memory was accessed over an extended period, not just burst accessed.
Immunity to Decay
Once permanent, the memory is protected:
fn apply_decay(memory: &mut Memory) {
if memory.permanent {
// LTP memories don't decay
// But they can still be forgotten via explicit forget()
return;
}
// Normal decay for non-permanent memories
memory.strength *= calculate_decay_factor(memory);
}
What Becomes Permanent?
In practice, LTP captures:
Ephemeral context naturally fades:
The Consolidation Report
Track what's becoming permanent:
$ shodh-memory consolidation-report
LTP Achieved (last 7 days):
- "User prefers functional programming patterns" (strength: 0.94)
- "Project uses Next.js with App Router" (strength: 0.91)
- "Testing strategy: unit tests with Jest" (strength: 0.88)
Approaching LTP:
- "Prefers explicit error handling over exceptions" (7/10 accesses)
- "Uses Tailwind CSS for styling" (8/10 accesses)
Results
With LTP enabled:
Memory should work like memory. Important things should last.