๐ง Spector Memory¶
The Cognitive Memory Engine for Autonomous AI Agents.
A biologically-inspired, off-heap memory system that gives AI agents the ability to remember, forget, consolidate, and associate โ with microsecond latency and zero garbage collection pressure. Built on Java Project Panama, SIMD-accelerated vector math, and Virtual Threads.
Why Cognitive Memory?¶
Traditional vector databases treat memories as static documents in a flat index. Real cognition is fundamentally different:
| Traditional Vector DB | Spector Memory |
|---|---|
| Flat document store | 4-tier cognitive architecture (Working โ Episodic โ Semantic โ Procedural) |
| Static similarity search | Fused scoring โ similarity ร importance ร temporal decay in a single SIMD pass |
| No temporal awareness | Reconsolidation โ frequently recalled memories resist forgetting |
| No emotional context | Valence tracking โ memories carry emotional coloring |
| No contextual gating | Synaptic tags โ 64-bit Bloom filter eliminates 99% of candidates in 1 CPU cycle |
| Python + network hops | Zero-GC, off-heap Panama โ microsecond latency, no serialization |
Architecture¶
spector-memory/
โโโ SpectorMemory.java โ Faรงade (Builder pattern entry point)
โโโ pipeline/ โ "Neural Pathways" โ ingestion + recall pipelines
โ โโโ IngestionPipeline.java (10-step remember pipeline)
โ โโโ RecallPipeline.java (parallel tier scanning + scoring)
โ โโโ HebbianCoActivationListener (Observer pattern post-recall)
โ
โโโ cortex/ โ "Cerebral Cortex" โ 4 tier stores
โ โโโ TierStore.java (Strategy interface)
โ โโโ TierRouter.java (Registry + polymorphic dispatch)
โ โโโ WorkingMemoryStore.java (Prefrontal Cortex โ volatile circular buffer)
โ โโโ EpisodicMemoryStore.java (Hippocampus โ time-partitioned mmap)
โ โโโ SemanticMemoryStore.java (Neocortex โ permanent knowledge)
โ โโโ ProceduralMemoryStore.java (Basal Ganglia โ learned procedures)
โ
โโโ synapse/ โ "Synaptic Machinery" โ header layout + scoring
โ โโโ CognitiveRecordLayout.java (32-byte aligned synaptic header)
โ โโโ CognitiveScorer.java (6-phase fused scoring hot-loop)
โ โโโ SynapticTagEncoder.java (64-bit inline Bloom filter)
โ โโโ SynapticHeaderConstants.java (offsets, masks, field sizes)
โ โโโ DecayStrategy.java (SIMD-friendly temporal decay)
โ
โโโ dopamine/ โ "Dopamine System" โ surprise & importance
โ โโโ SurpriseDetector.java (Welford online statistics + Z-score)
โ โโโ FlashbulbPolicy.java (extreme surprise โ pinned memory)
โ โโโ WelfordStats.java (running mean/variance tracker)
โ
โโโ amygdala/ โ "Amygdala" โ emotional valence
โ โโโ ValenceTracker.java (emotional coloring of memories)
โ
โโโ hebbian/ โ "Hebbian Learning" โ associations
โ โโโ CoActivationTracker.java (tag co-occurrence tracking)
โ โโโ HebbianGraph.java (associative memory network)
โ
โโโ hippocampus/ โ "Hippocampus" โ consolidation & cleanup
โ โโโ ReflectDaemon.java (sleep consolidation K-Means)
โ โโโ TombstoneCompactor.java (partition rebuild)
โ
โโโ habituation/ โ "Habituation" โ anti-filter bubble
โ โโโ HabituationPenalty.java (frequency-based score decay)
โ
โโโ inhibition/ โ "Inhibition" โ suppression
โ โโโ SuppressionSet.java (explicit memory blocking)
โ
โโโ interference/ โ "Proactive Interference" โ deduplication
โ โโโ SemanticDeduplicator.java (near-duplicate detection + merge)
โ
โโโ prospective/ โ "Prospective Memory" โ future intents
โ โโโ ProspectiveScheduler.java (time-triggered reminders)
โ โโโ Reminder.java (scheduled memory record)
โ
โโโ metamemory/ โ "Metamemory" โ self-reflection
โ โโโ MemoryIntrospector.java (memory health stats & analytics)
โ
โโโ index/ โ O(1) reverse index
โ โโโ MemoryIndex.java (ConcurrentHashMap forward + reverse)
โ
โโโ sync/ โ Persistence & replication
โโโ MemoryWal.java (Write-Ahead Log)
โโโ CrdtMergeStrategy.java (CRDT merge for distributed sync)
Biological System โ Package Mapping¶
| Brain Region | Package | Java Classes | Function |
|---|---|---|---|
| ๐ง Cerebral Cortex | cortex/ |
TierRouter, TierStore, 4 stores |
4-tier memory storage (Working โ Episodic โ Semantic โ Procedural) |
| ๐ Synapses | synapse/ |
CognitiveScorer, SynapticTagEncoder, CognitiveRecordLayout |
32-byte header, 6-phase scoring, Bloom filter gating |
| โก Dopamine System | dopamine/ |
SurpriseDetector, FlashbulbPolicy |
Surprise detection, auto-importance, flashbulb pinning |
| ๐ฑ Amygdala | amygdala/ |
ValenceTracker |
Emotional coloring (positive/negative/neutral) |
| ๐ Hebbian Learning | hebbian/ |
CoActivationTracker, HebbianGraph |
"Neurons that fire together wire together" |
| ๐๏ธ Hippocampus | hippocampus/ |
ReflectDaemon, TombstoneCompactor |
Sleep consolidation, synaptic pruning, partition rebuild |
| ๐ด Habituation | habituation/ |
HabituationPenalty |
Anti-filter bubble โ penalizes repetitive recall |
| ๐ซ Inhibition | inhibition/ |
SuppressionSet |
Explicit memory suppression (user redaction) |
| ๐ฎ Prospective Memory | prospective/ |
ProspectiveScheduler, Reminder |
Future-oriented intent reminders |
| ๐ช Metamemory | metamemory/ |
MemoryIntrospector |
Self-reflective memory health analytics |
Quick Start¶
// 1. Create a cognitive memory with Ollama embeddings
SpectorMemory memory = SpectorMemory.builder()
.dimensions(4096)
.embeddingProvider(OllamaEmbeddingProvider.create("qwen3-embedding"))
.workingCapacity(100)
.episodicPartitionCapacity(10_000)
.semanticCapacity(5_000)
.proceduralCapacity(500)
.build();
// 2. Remember โ 10-step ingestion pipeline
memory.remember("pref-dark-mode",
"The user strongly prefers dark mode for all IDE editors.",
MemoryType.EPISODIC, MemorySource.USER_STATED,
"ui", "preferences", "coding");
// 3. Recall โ parallel SIMD-accelerated search with cognitive scoring
List<CognitiveResult> results = memory.recall("dark theme settings",
RecallOptions.builder()
.topK(5)
.synapticFilter("preferences") // Bloom filter pre-screen
.minImportance(0.3f) // Skip low-importance memories
.build());
for (CognitiveResult r : results) {
System.out.printf("%.4f [%s] %s%n", r.score(), r.memoryType(), r.text());
}
// 4. Forget โ tombstone a memory
memory.forget("pref-dark-mode");
// 5. Suppress โ temporarily hide from recall
memory.suppress("noisy-memory-id", "Not relevant right now");
// 6. Close โ releases all off-heap memory
memory.close();
The 6-Phase Scoring Pipeline¶
Every recall query executes a SIMD-optimized hot-loop that fuses six filtering and scoring phases into a single sequential scan. Each phase eliminates candidates before the expensive vector math:
Phase 1: Tombstone Check (~1 cycle) โ Skip dead memories
Phase 2: Synaptic Tag Gating (~1 cycle) โ Bloom filter eliminates 99% of irrelevant
Phase 3: Valence Filter (~2 cycles) โ Emotional range filtering
Phase 4: Importance/Decay (~5 cycles) โ Skip old + low-importance
Phase 5: SIMD L2 Distance (~200 cycles) โ Quantized INT8 Euclidean via Vector API
Phase 6: Fused Score (~7 cycles) โ ฮฑยทsimilarity + ฮฒยทimportanceยทdecay
The math: If an agent has 1,000,000 episodic memories but only 10,000 match the active synaptic tags: - Phases 1-4 eliminate 990,000 memories in ~990ยตs (cheap header reads) - Phase 5 computes SIMD distance on only ~10,000 candidates - Total: ~0.13ms for 1M memories vs ~200ms without gating (1,500ร improvement)
Performance¶
Benchmarked on Intel Core Ultra 9 285K, Java 25, AVX2 256-bit:
| Benchmark | Result |
|---|---|
| SIMD L2 Distance (768-dim) | 2.2 ยตs/vector (1.4M vectors/sec) |
| SIMD L2 Distance (128-dim) | 0.8 ยตs/vector (1.2M vectors/sec) |
| Reverse Index Lookup | 180 ns/lookup (O(1) via ConcurrentHashMap) |
| CognitiveScorer (10K ร 128-dim) | 2.9 ms total |
| Batch Habituation (1K IDs) | 101 ยตs total |
| Full Pipeline (1K ingest + 100 recall) | < 50 ms/query |
| Real Embedding (qwen3-embedding 4096-dim) | 31 ms/embed via Ollama |
Test Suite¶
spector-core: 276 tests โ
(includes 15 SIMD kernel tests)
spector-memory: 167 tests โ
(includes 33 perf + index tests)
+ 10 Ollama real embedding E2E tests (gated by OLLAMA_LIVE=true)
Total: 443 tests, 0 failures
Competitive Landscape¶
| Feature | Spector Memory | Mem0 | Letta (MemGPT) | Zep |
|---|---|---|---|---|
| Language | Java 25 | Python | Python | Go/Python |
| Storage | Off-heap Panama | Postgres/pgvector | Postgres/Chroma | Postgres |
| Latency | 0.13ms (1M memories) | ~50-200ms | ~100-500ms | ~20-100ms |
| GC Pressure | Zero | Python GC | Python GC | Go GC |
| Temporal Decay | Fused SIMD | Post-filter | Post-filter | Post-filter |
| Emotional Valence | โ Built-in | โ | โ | โ |
| Synaptic Tag Gating | โ 1-cycle Bloom | โ | โ | โ |
| Sleep Consolidation | โ K-Means | โ | โ | โ |
| Surprise Detection | โ Welford Z-score | โ | โ | โ |
| Habituation | โ Anti-filter bubble | โ | โ | โ |
| MCP Integration | โ Native | โ | โ | โ |
Documentation¶
๐ Full documentation: See the Cognitive Memory Guide for:
- System Architecture โ package hierarchy, data flow, design patterns
- 6-Phase Scoring Pipeline โ deep dive with math and cycle counts
- Biological Systems โ each brain region mapped to code
- Performance & SIMD โ benchmarks, optimization techniques
- Off-Heap Panama Design โ zero-GC architecture
- API Reference โ full method signatures
License¶
This module is licensed under the Business Source License 1.1 (BSL 1.1).
- Permits free use for non-production purposes.
- Permits production use for all purposes except offering it as a managed service or embedding/integrating it in a competing AI cognitive memory product or service.
- Automatically transitions to the Apache License 2.0 on May 27, 2030 (4 years from release).
See the LICENSE file for the full terms and conditions.
Built with โก by Spectrayan