Skip to main content
Glama
orneryd

M.I.M.I.R - Multi-agent Intelligent Memory & Insight Repository

by orneryd
memory-decay.md5.19 kB
# Memory Decay **Time-based importance scoring inspired by human memory.** ## Overview NornicDB implements a memory decay system that naturally reduces the importance of older, unused information while preserving frequently accessed and important data. ## Memory Tiers Inspired by cognitive science, memories are classified into three tiers: | Tier | Half-Life | Use Case | |------|-----------|----------| | Episodic | ~7 days | Recent events, conversations | | Semantic | ~69 days | Facts, knowledge, concepts | | Procedural | ~693 days | Skills, habits, core knowledge | ## How It Works ### Decay Formula Memory strength decays exponentially over time: ``` strength(t) = initial_strength × e^(-λt) ``` Where: - `λ` = decay constant (varies by tier) - `t` = time since last access ### Access Reinforcement Each access reinforces the memory: ```go // Memory is reinforced on access memory := db.Recall(ctx, "mem-123") // memory.DecayScore is increased // memory.LastAccessed is updated // memory.AccessCount is incremented ``` ### Tier Promotion Frequently accessed memories are promoted to more stable tiers: ``` Episodic → Semantic → Procedural ``` ## Configuration ### Enable Memory Decay ```yaml # nornicdb.yaml decay: enabled: true recalculate_interval: 1h archive_threshold: 0.1 # Archive below 10% strength ``` ### Code Configuration ```go config := nornicdb.DefaultConfig() config.DecayEnabled = true config.DecayRecalculateInterval = time.Hour config.DecayArchiveThreshold = 0.1 db, err := nornicdb.Open("/data", config) ``` ## API Usage ### Store with Tier ```go // Create episodic memory (fast decay) memory := &Memory{ Content: "User said hello today", Tier: TierEpisodic, } db.Store(ctx, memory) // Create semantic memory (slow decay) // Note: TierSemantic is the DEFAULT if no tier is specified memory := &Memory{ Content: "User's favorite color is blue", Tier: TierSemantic, // Optional - this is the default } db.Store(ctx, memory) // Create procedural memory (very slow decay) memory := &Memory{ Content: "User prefers dark mode", Tier: TierProcedural, } db.Store(ctx, memory) ``` ### Check Decay Score ```go memory, err := db.Recall(ctx, "mem-123") fmt.Printf("Decay score: %.2f%%\n", memory.DecayScore * 100) // Decay score: 85.00% ``` ### Query by Decay ```cypher // Find strong memories MATCH (m:Memory) WHERE m.decay_score > 0.5 RETURN m ORDER BY m.decay_score DESC // Find fading memories MATCH (m:Memory) WHERE m.decay_score < 0.2 RETURN m ``` ## Decay Statistics ### View Stats ```bash nornicdb decay stats ``` Output: ``` Memory Decay Statistics ======================= Total memories: 15,234 By tier: Episodic: 5,123 (33.6%) Semantic: 8,456 (55.5%) Procedural: 1,655 (10.9%) Decay distribution: Strong (>80%): 4,234 Medium (20-80%): 8,567 Weak (<20%): 2,433 Archived: 1,234 ``` ### API Stats ```bash curl http://localhost:7474/nornicdb/decay/stats \ -H "Authorization: Bearer $TOKEN" ``` ## Archiving ### Automatic Archiving Memories below the threshold are automatically archived: ```yaml decay: archive_threshold: 0.1 # Archive below 10% archive_action: soft_delete # soft_delete, move, delete ``` ### Manual Archiving ```bash # Archive weak memories nornicdb decay archive --threshold 0.2 # Restore archived memories nornicdb decay restore --id mem-123 ``` ## Use Cases ### Conversational AI ```go // Store conversation as episodic memory memory := &Memory{ Content: fmt.Sprintf("User: %s\nAssistant: %s", userMsg, response), Tier: TierEpisodic, Tags: []string{"conversation", sessionID}, } db.Store(ctx, memory) // Old conversations naturally fade // Important topics get reinforced through re-access ``` ### Knowledge Base ```go // Store facts as semantic memory memory := &Memory{ Content: "The capital of France is Paris", Tier: TierSemantic, Tags: []string{"geography", "facts"}, } db.Store(ctx, memory) ``` ### User Preferences ```go // Store preferences as procedural memory memory := &Memory{ Content: "User prefers formal communication style", Tier: TierProcedural, Tags: []string{"preferences", "communication"}, } db.Store(ctx, memory) ``` ## Integration with Search Decay scores are used in search ranking: ```go // Search considers decay in relevance results, err := db.Remember(ctx, queryEmbedding, 10) // Results are ranked by: similarity × decay_score ``` ### Custom Weighting ```cypher // Custom decay-aware query MATCH (m:Memory) WHERE m.content CONTAINS 'project' RETURN m, m.decay_score * cosineSimilarity(m.embedding, $query) as score ORDER BY score DESC LIMIT 10 ``` ## Disable Decay For use cases where decay isn't appropriate: ```yaml decay: enabled: false ``` Or per-memory: ```go memory := &Memory{ Content: "Critical system information", Properties: map[string]any{ "no_decay": true, }, } ``` ## See Also - **[Vector Search](../user-guides/vector-search.md)** - Search with decay - **[GPU Acceleration](gpu-acceleration.md)** - Performance - **[Architecture](../architecture/system-design.md)** - System design

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/orneryd/Mimir'

If you have feedback or need assistance with the MCP directory API, please join our Discord server