MemoryKit models human cognition to create efficient memory systems for LLM applications. This document explains the neuroscience-inspired architecture.
Role: Executive function and attention control
The prefrontal cortex:
- Makes decisions about what to focus on
- Plans complex behaviors
- Evaluates alternatives
- Manages working memory
Software Implementation:
public interface IPrefrontalController
{
Task<QueryPlan> BuildQueryPlanAsync(string query, ConversationState state);
Task<QueryType> ClassifyQueryAsync(string query);
List<MemoryLayer> DetermineLayersToUse(QueryType type, ConversationState state);
}Query Planning Strategy:
- Continuation → Layer 3 only (fast)
- Fact Retrieval → Layers 2-3 (balanced)
- Deep Recall → Layers 1-3 (thorough)
- Complex → All layers (comprehensive)
- Procedural → Layers 3 + P (routine)
Role: Emotional tagging and importance scoring
The amygdala:
- Tags experiences with emotional significance
- Influences what gets consolidated to long-term memory
- Modulates memory strength based on emotional arousal
Software Implementation:
public interface IAmygdalaImportanceEngine : IImportanceEngine
{
Task<double> CalculateImportanceAsync(Message message);
Task<(double Score, string Sentiment)> AnalyzeSentimentAsync(string text);
bool ContainsDecisionLanguage(string text);
bool HasExplicitImportanceMarkers(string text);
}Importance Scoring Algorithm:
FinalScore = (BaseScore × 0.4) +
(EmotionalWeight × 0.3) +
(NoveltyBoost × 0.2) +
(RecencyFactor × 0.1)
Importance Triggers:
- User questions (1.5x boost)
- Decisions/commitments (2.0x boost)
- Emotional language (1.3x boost)
- Novel information (1.5x boost)
- Explicit importance markers (2.5x boost)
Role: Temporary storage and consolidation initiation
The hippocampus:
- Rapidly encodes new information
- Indexes memories for later retrieval
- Initiates consolidation to cortical storage
Software Implementation:
public interface IHippocampusIndexer
{
Task<string> EncodeAsync(Message message);
Task MarkForConsolidationAsync(string messageId);
Task ConsolidateAsync(string userId);
}Consolidation Process:
- Encoding: Initial capture in working memory
- Indexing: Create search indices
- Importance Scoring: Amygdala processing
- Consolidation: Move to appropriate layer
- High importance → Layer 1 (episodic)
- Facts → Layer 2 (semantic)
- Patterns → Layer P (procedural)
Role: Procedural memory and habitual responses
The basal ganglia:
- Store learned procedures and routines
- Execute habitual behaviors
- Learn from reward and feedback
Software Implementation:
public interface IProceduralMemoryService
{
Task<ProceduralPattern?> MatchPatternAsync(string userId, string query);
Task DetectAndStorePatternAsync(string userId, Message message);
Task<ProceduralPattern[]> GetUserPatternsAsync(string userId);
}Pattern Learning:
- Detect: Extract rules from user instructions
- Store: Save as procedural patterns
- Reinforce: Increase confidence with each use
- Decay: Reduce confidence if unused
Role: Long-term semantic knowledge
The neocortex:
- Stores consolidated semantic knowledge
- Integrates information across domains
- Supports reasoning and generalization
Software Implementation: Azure Table Storage with semantic indexing
Capacity: ~7±2 items Substrate: Redis cache Latency: <5ms Duration: ~30 seconds to minutes Function: Active processing
Capacity: Unlimited Substrate: Azure Table Storage + embeddings Latency: ~30ms Duration: Long-term Function: Facts, concepts, relationships
Capacity: Full history Substrate: Azure Blob + AI Search Latency: ~120ms Duration: Long-term Function: Specific events and experiences
Capacity: Learned patterns Substrate: Azure Table Storage Latency: ~50ms Duration: Long-term Function: Skills and routines
Unlike human sleep, MemoryKit performs continuous consolidation:
Event → Working Memory → Importance Scoring →
Consolidation Decision → Target Layer Storage
Consolidation Rules:
- High importance + specific facts → Layer 1
- General knowledge → Layer 2
- Repeated procedures → Layer P
- Low importance → Discard after TTL
Selective Attention: The PrefrontalController manages attention by:
- Classifying query type
- Determining relevant layers
- Filtering irrelevant information
- Assembling minimal context
Token Efficiency:
- Continuation: ~100 tokens
- Fact Retrieval: ~300-500 tokens
- Deep Recall: ~1000-1500 tokens
- Complex: ~2000 tokens
- Procedural patterns increase confidence with use
- Importance thresholds adjust based on retention
- Layer selection optimizes based on query latency
- Entity embeddings capture relationships
- Fact importance updates as accessed
- Procedural rules strengthen with application
Emotional Arousal: Increases importance
- Explicit markers: "important", "critical"
- Sentiment analysis: high positive/negative
- Decision language: commitments, promises
- Novelty: new information
Emotional Decay: Importance fades over time
- Recent events more salient
- Exponential decay function
- Can be reinforced through repeated access
- Repeated access reinforces memories
- Intervals optimize consolidation
- Implemented through access tracking
- Recent items prioritized
- Reflected in working memory LRU
- Temporal weighting in retrieval
- First occurrences marked as novel
- Initial importance boost
- Entity tracking captures first mention
- Context influences recall
- MemoryContext reassembles information
- Query influences what's retrieved
- Procedural patterns enable transfer
- Semantic knowledge generalizes
- Relationships captured in embeddings
Problem: Too many recent items Solution: LRU eviction, importance-based retention
Problem: False or outdated facts Solution: Versioning, update tracking, confidence scores
Problem: Patterns too strict, not adapting Solution: Dynamic confidence thresholds, decay for unused patterns
Problem: Important information lost Solution: Redundant storage, importance-based TTL
- Monitor own performance
- Adjust learning strategies
- Self-aware uncertainty
- Learn from emotional responses
- Adjust importance scoring over time
- Empathetic responses
- Better query planning
- Confidence calibration
- Multi-step reasoning
- Learn across domains
- Apply patterns broadly
- Generalize from experience
- Kandel, E.R., et al. "Principles of Neural Science"
- LeDoux, J. "The Emotional Brain"
- Squire, L.R. "Memory and the Hippocampus"
- Baddeley, A. "Working Memory: Theories, Models, and Controversies"
- Tulving, E. "Elements of Episodic Memory"
- Anderson, J.R. "Cognitive Psychology and its Implications"
- Vaswani, A., et al. "Attention is All You Need"
- Brown, T.B., et al. "Language Models are Few-Shot Learners"
- Wei, J., et al. "Emergent Abilities of Large Language Models"