-
Notifications
You must be signed in to change notification settings - Fork 0
Memory System
Luna's memory system is a biologically-inspired, multi-layered architecture that enables true long-term relationships through sophisticated fact extraction, semantic search, and graph-based relationship tracking.
Luna uses a Hybrid Memory System that combines structured data, vector embeddings, and graph-based relationships.
| Layer | Technology | Purpose |
|---|---|---|
| Fact Storage | PostgreSQL | Structured facts (personal, work, preferences) |
| Semantic Memory | PostgreSQL (pgvector) | Semantic similarity search across past conversations |
| Graph Memory | Neo4j | Biologically-inspired connection density tracking |
| Working Memory | Redis | Real-time session state and attention tracking |
Luna utilizes Neo4j to implement a memory system where memory strength is determined by connection density, not just storage.
- Hebbian Learning: "Neurons that fire together, wire together" — reinforcement increases connection strength.
- Decay & Reinforcement: Memories with no connections decay naturally over time, while repeated concepts gain edges and survive longer.
- Origin Tracking: Strictly distinguishes between user-originated facts (high trust) and model-inferred insights (lower trust) to prevent hallucination loops.
- Nodes: Represent concepts (entities, topics, preferences, events, emotions).
- Edges: Represent relationships (co-occurrence, semantic, causal, temporal, same_as).
Luna integrates with MemoryCore to implement three-tier memory consolidation:
- Storage: Redis (30-min TTL)
- Scale: Seconds to minutes
- Purpose: Real-time session state, immediate context, and attention tracking.
- Storage: PostgreSQL (90-day retention)
- Scale: Hours to days
- Purpose: Recent experiences, session summaries, and emerging behavioral patterns.
- Storage: PostgreSQL + Neo4j (Permanent)
- Scale: Permanent
- Purpose: User proficiency models, deep learning patterns, and long-term personality traits.
Memory is consolidated through a process called NeuralSleep, which mimics biological sleep:
- Immediate (Session End): Session data moves from Working to Episodic memory. Summaries are generated, and facts are extracted.
- Daily (2 AM): Episodic events are consolidated into Semantic patterns. Edge decay is applied in the graph database.
- Weekly (3 AM Sunday): Deep semantic updates and meta-pattern extraction occur. Weak or isolated nodes are pruned.
Luna automatically extracts facts from conversations, but tracks their Origin to maintain trust:
- User Origin: Directly stated by the user ("I live in Stockholm"). High trust.
- Model Origin: Inferred by the LLM ("User seems to like Swedish weather"). Lower trust.
- Personal: Name, birthday, location, background
- Work: Job title, company, profession, industry
- Preference: Likes, dislikes, favorites
- Hobby: Interests, activities, skills
- Relationship: Family, friends, pets
- Goal: Aspirations, objectives, plans
Luna tracks Active Intents — what you are currently trying to accomplish — separately from long-term memory.
- Active: Currently being worked on (max 5).
- Suspended: Paused due to topic switch.
- Resolved: Completed or abandoned.
- Decayed: Auto-archived after 7 days of inactivity.
This allows Luna to understand ambiguous references like "let's try that again" or "it worked!" across different sessions.
When NeuralSleep services are active, Luna tracks consciousness metrics based on Integrated Information Theory (IIT):
| Metric | Description |
|---|---|
| Phi (Φ) | How interconnected memory representations are. |
| Temporal Integration | How well past experiences shape current processing. |
| Self-Reference Depth | recursive self-modeling capability. |
| Causal Density | Information flow between memory tiers. |
- Local-First: In local mode, all embeddings (BGE-M3) and graph traversals (Neo4j) happen on your hardware.
- Audit Trail: Every fact extraction and node creation is logged with source message references.
- User Control: View, edit, or delete any fact or memory node via Settings > Memory.
-
GET /api/graph/nodes: List graph nodes -
GET /api/graph/edges: List relationship edges
-
GET /api/consciousness/metrics/:userId: Get current consciousness metrics -
POST /api/chat/sessions/:id/end: Manually trigger session consolidation
# Check consolidation logs in MemoryCore
docker exec memorycore-postgres psql -U memorycore -d memorycore \
-c "SELECT * FROM consolidation_logs ORDER BY timestamp DESC LIMIT 5;"