-
-
Notifications
You must be signed in to change notification settings - Fork 0
Memory Cortex
Biological Analog: The Cerebral Cortex β the outer layer of the brain responsible for higher-order cognitive functions. Different cortical regions specialize in different types of memory.
Human memory is not a single system. Cognitive science identifies distinct memory systems with different characteristics, durations, and purposes. Spector mirrors this with four tier stores:
graph TB
subgraph "TierRouter β Polymorphic Registry"
direction TB
TR["TierStore interface"]
end
TR --> WM["π§ͺ Working Memory<br/>WorkingMemoryStore<br/>βββββββββββββββββ<br/>Prefrontal Cortex<br/>Volatile circular buffer<br/>~100 records"]
TR --> EM["π Episodic Memory<br/>EpisodicMemoryStore<br/>βββββββββββββββββ<br/>Hippocampus<br/>Time-partitioned mmap<br/>Unbounded"]
TR --> SE["𧬠Semantic Memory<br/>SemanticMemoryStore<br/>βββββββββββββββββ<br/>Neocortex<br/>Permanent knowledge<br/>~5,000 records"]
TR --> PR["βοΈ Procedural Memory<br/>ProceduralMemoryStore<br/>βββββββββββββββββ<br/>Basal Ganglia<br/>Learned procedures<br/>~500 records"]
style WM fill:#e74c3c,color:white
style EM fill:#3498db,color:white
style SE fill:#2ecc71,color:white
style PR fill:#9b59b6,color:white
All four stores implement a common TierStore interface. The TierRouter dispatches operations via an EnumMap<MemoryType, TierStore> β zero switch statements, fully polymorphic.
Adding a new tier (e.g.,
FLASHfor ultra-fast scratch memory) requires only: (1) implementTierStore, (2) register inTierRouter. No changes needed inSpectorMemory,RecallPipeline, orCognitiveIngestionTarget.
Biological Analog: The Prefrontal Cortex maintains a limited workspace for active processing. It holds ~7Β±2 items in biological systems.
| Property | Value |
|---|---|
| Storage | Volatile off-heap segment |
| Capacity | Configurable (default: 100) |
| Eviction | Circular buffer β oldest entries overwritten |
| Persistence | None β lost on JVM shutdown |
| Use case | Current task context, recent conversation |
Working memory operates as a circular buffer: when the buffer is full, the oldest entry is overwritten by the newest. This mirrors the human prefrontal cortex where only the most recent context is actively maintained.
Special capability: Synaptic tag search without vector math β Working Memory supports finding memories by tag alone using the 64-bit Bloom filter field, useful for fast context lookups without embedding the query.
Biological Analog: The Hippocampus encodes autobiographical events as time-ordered traces. New events are appended rapidly (one-trial learning), and during sleep the hippocampus replays sequences for consolidation into cortical memory.
| Property | Value |
|---|---|
| Storage | Memory-mapped files (FileChannel.map()) |
| Capacity | Unbounded (1 partition per day, each up to 10,000 records) |
| Eviction | Tombstone + compaction |
| Persistence | Full β survives JVM restarts |
| Use case | "What error did we debug yesterday?", "What did the user say last week?" |
Each episodic partition is a memory-mapped file with a 64-byte metadata header:
ββββ Partition File ββββββββββββββββββββββββββββββββββββββββββ
β [64B Metadata Header] β
β βββ 4B magic (0x45504943 = "EPIC") β
β βββ 4B version (1) β
β βββ 4B count (live records) β
β βββ 4B tombstoneCount β
β βββ 4B capacity β
β βββ 4B state (ACTIVE/SEALED/REFLECTABLE/TOMBSTONED/...) β
β βββ 4B stride β
β βββ 36B reserved β
βββ [Record 0: 64B header + NB vector] βββββββββββββββββββββββ€
βββ [Record 1: 64B header + NB vector] βββββββββββββββββββββββ€
β ... β
βββ [Record N-1] ββββββββββββββββββββββββββββββββββββββββββββ
Partition state machine:
stateDiagram-v2
[*] --> ACTIVE: Create partition
ACTIVE --> SEALED: Day rolls over
SEALED --> REFLECTABLE: ReflectDaemon marks eligible
REFLECTABLE --> TOMBSTONED: High tombstone ratio
TOMBSTONED --> COMPACTED: TombstoneCompactor rebuilds
COMPACTED --> [*]: Old partition swapped out
Biological Analog: The Neocortex stores distilled, permanent world knowledge β facts, concepts, and generalized rules extracted from repeated experience.
| Property | Value |
|---|---|
| Storage | Rolling semantic-NNN.mem files |
| Capacity per partition | Configurable (default: 10,000 records) |
| Total capacity | Unbounded (new partitions roll automatically) |
| Eviction | Tombstone + per-partition compaction |
| Persistence | Full β mmap-backed files survive restarts |
| Recall | Parallel per-partition scan via virtual threads |
| Use case | "The user prefers dark mode", "Java uses garbage collection" |
.spector/memory/semantic/
semantic-000.mem β partition 0 (10K records, oldest)
semantic-001.mem β partition 1 (created when 0 fills up)
semantic-002.mem β partition 2 (active β accepts writes)
Concurrency model:
-
Reads:
CopyOnWriteArrayListprovides lock-free snapshot iteration. Each partition is searched independently on its own virtual thread -
Writes:
ReadWriteLockβ read lock for normal appends, write lock only when rolling to a new partition - Compaction: Per-partition rebuild. Other partitions remain readable during compaction
Creation: Semantic memories are created either:
-
Directly by the user (
MemoryType.SEMANTIC) -
By consolidation β the
ReflectDaemonclusters similar episodic memories during "sleep" and promotes the cluster centroid to semantic memory
Migration: Existing single-file stores are automatically migrated to the partitioned format on first startup.
| Property | Value |
|---|---|
| Storage | Fixed-capacity off-heap slab |
| Capacity | Configurable (default: 5,000) |
| Use case | Small deployments or in-memory mode |
Biological Analog: The Basal Ganglia stores learned motor programs and habitual behaviors β "how to ride a bicycle" type knowledge that operates below conscious awareness.
| Property | Value |
|---|---|
| Storage | Linear off-heap segment |
| Capacity | Configurable (default: 500) |
| Eviction | None (append-only) |
| Persistence | Via WAL replay |
| Use case | "Always use exponential backoff", "Format SQL with uppercase keywords" |
Procedural memories represent rules and patterns that the agent has internalized. They are typically higher-importance, persistent, and rarely forgotten.
- :material-sleep: [[Hippocampus β Sleep Consolidation|Memory--Hippocampus]] β how episodic memories are consolidated into semantic knowledge
- :material-flash: [[Synapse β Tags & Scoring|Memory--Synapse]] β the 64-byte header and Bloom filter
- :material-lightning-bolt: [[6-Phase Scoring Pipeline|Memory--Scoring-Pipeline]] β the SIMD hot-loop
- 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