-
-
Notifications
You must be signed in to change notification settings - Fork 0
Memory Dopamine
Biological Analog: The dopaminergic system signals prediction error β the difference between what the brain expected and what actually happened. When a stimulus is surprising (high prediction error), dopamine release strengthens memory encoding. This is why we vividly remember surprising events (flashbulb memories) but quickly forget routine ones.
Without surprise detection, an AI agent treats all memories as equally important. A routine "code compiled successfully" gets the same importance as "production database corrupted." This leads to:
- Important memories drowning in noise
- Critical errors being forgotten as quickly as routine events
- No adaptive importance β every memory starts at the same baseline
The surprise detector maintains a running statistical model of "normal" memory vectors using Welford's online algorithm (numerically stable one-pass mean/variance). When a new memory arrives, its L2 distance from the running centroid is converted to a Z-score:
flowchart LR
A["New Memory<br/>L2 norm = 3.7"] --> B["Running Stats<br/>ΞΌ=2.1, Ο=0.6"]
B --> C["Z-score<br/>(3.7 - 2.1) / 0.6 = 2.67"]
C -->|"Z > 2.0"| D["β‘ Surprising!<br/>importance = 0.85"]
C -->|"Z < 0.5"| E["π Normal<br/>importance = 0.4"]
style D fill:#e74c3c,color:white
style E fill:#95a5a6,color:white
Importance is computed from two independent surprise dimensions:
Where
| Dimension | Signal | Weight |
|---|---|---|
| Spatial surprise | Z-score of L2 norm vs. running statistics | 0.6 (default) |
| Temporal surprise | Time since last memory with matching tags | 0.4 (default) |
flowchart TD
VEC["Memory embedding vector"] --> SPATIAL["Spatial Surprise<br/><i>Z-score vs running centroid</i>"]
TAGS["Synaptic tag pattern"] --> TEMPORAL["Temporal Surprise<br/><i>time since last matching tags</i>"]
SPATIAL --> FUSE["Fused Importance<br/><b>Ξ± Γ spatial + Ξ² Γ temporal</b>"]
TEMPORAL --> FUSE
FUSE --> FLASH{"Z-score β₯ 3.0?"}
FLASH -->|"No"| NORMAL["Normal importance<br/><i>0.0 β 0.99</i>"]
FLASH -->|"Yes"| FLASHBULB["β‘ Flashbulb Memory!<br/><b>importance = 1.0, pinned</b>"]
style FLASHBULB fill:#e74c3c,color:white
style FUSE fill:#f39c12,color:white
tip: Why Welford's Algorithm? Naive variance computation (
Ξ£(x-ΞΌ)Β²/n) requires two passes or suffers from catastrophic cancellation with floating-point arithmetic. Welford's algorithm maintains numerical stability with a single pass β critical for an always-running system that processes millions of memories over its lifetime.
Biological analog: Flashbulb memories are vivid, long-lasting memories formed during moments of extreme surprise or emotional intensity (e.g., hearing about a major world event). The amygdala signals the hippocampus to strengthen encoding.
When the Z-score exceeds a threshold (default: 3.0), the flashbulb policy activates:
Effects:
- Importance is set to 1.0 (maximum)
- The pinned flag is set β this memory is exempt from temporal decay in Phase 4 of the scoring pipeline
- The memory will persist indefinitely unless explicitly
forget()'d
example: Use Case An AI coding agent encounters
OutOfMemoryErrorfor the first time (Z-score: 4.2). This triggers flashbulb encoding β the error memory is pinned at maximum importance and will always surface when the agent encounters memory-related issues.
Surprise detection happens at Step 3 of the ingestion pipeline:
flowchart LR
EMBED["Step 1: Embed text<br/><i>β vector</i>"] --> TAGS["Step 2: Encode tags<br/><i>β Bloom filter</i>"]
TAGS --> SURPRISE["Step 3: Surprise Detection<br/><b>Z-score β importance</b>"]
SURPRISE --> FLASH["Step 4: Flashbulb Check<br/><i>pin if extreme</i>"]
FLASH --> DEDUP["Step 5: Deduplication"]
DEDUP --> WRITE["Step 6: Write to tier"]
style SURPRISE fill:#f39c12,color:white
style FLASH fill:#e74c3c,color:white
- :material-emoticon: [[Amygdala β Emotional Valence|Memory--Amygdala]] β emotional coloring of memories
- :material-flash: [[Synapse β Tags & Scoring|Memory--Synapse]] β the 64-byte header
- :material-sleep: [[Hippocampus β Sleep Consolidation|Memory--Hippocampus]] β what happens to important memories
- Home
- Getting Started
-
Cognitive Memory
- Overview
- Getting Started
- Use Cases & Configuration
- API Reference
- Architecture
- The 6-Phase Scoring Pipeline
- Cognitive Profiles
- Salience & Importance
-
Biological Systems
- Overview
- Cortex β Tier Stores
- Hippocampus β Sleep Consolidation
- Synapse β Tags & Scoring
- Dopamine β Surprise Detection
- Amygdala β Emotional Valence
- 3-Layer Cognitive Graph
- Habituation β Anti-Filter Bubble
- Inhibition β Suppression
- Interference β Deduplication
- Prospective β Future Intents
- Metamemory β Self-Reflection
- Sync β Persistence & Replication
- Performance & Internals
- Cognitive Evaluation
-
Architecture
- System Overview
- Core Concepts
- Ingestion Pipeline
- RAG Pipeline
- MCP Integration
- Distributed Mode
- Event Notifications
- Namespace Sharding
- GPU Acceleration
- Performance Tuning
- Test Framework & LLM Judge
- JDK API Status
- Security & Data
- Deep Dives
- Cortex Dashboard
-
Community
- Contributing
- FAQ
- Roadmap
- π¬ Labs