Skip to content

Memory System

Your Name edited this page Feb 4, 2026 · 3 revisions

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.


Memory Architecture

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

Graph-Based Memory (Neo4j)

Luna utilizes Neo4j to implement a memory system where memory strength is determined by connection density, not just storage.

Core Principles

  • 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 & Edges

  • Nodes: Represent concepts (entities, topics, preferences, events, emotions).
  • Edges: Represent relationships (co-occurrence, semantic, causal, temporal, same_as).

Memory Layers (Three-Tier Consolidation)

Luna integrates with MemoryCore to implement three-tier memory consolidation:

1. Working Memory

  • Storage: Redis (30-min TTL)
  • Scale: Seconds to minutes
  • Purpose: Real-time session state, immediate context, and attention tracking.

2. Episodic Memory

  • Storage: PostgreSQL (90-day retention)
  • Scale: Hours to days
  • Purpose: Recent experiences, session summaries, and emerging behavioral patterns.

3. Semantic Memory

  • Storage: PostgreSQL + Neo4j (Permanent)
  • Scale: Permanent
  • Purpose: User proficiency models, deep learning patterns, and long-term personality traits.

The Consolidation Flow (NeuralSleep)

Memory is consolidated through a process called NeuralSleep, which mimics biological sleep:

  1. Immediate (Session End): Session data moves from Working to Episodic memory. Summaries are generated, and facts are extracted.
  2. Daily (2 AM): Episodic events are consolidated into Semantic patterns. Edge decay is applied in the graph database.
  3. Weekly (3 AM Sunday): Deep semantic updates and meta-pattern extraction occur. Weak or isolated nodes are pruned.

Fact Extraction & Origin Tracking

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.

Fact Categories

  • 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

Intent Persistence

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.


Consciousness Metrics

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.

Privacy & Security

  • 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.

API & Testing

Graph Memory

  • GET /api/graph/nodes: List graph nodes
  • GET /api/graph/edges: List relationship edges

MemoryCore

  • GET /api/consciousness/metrics/:userId: Get current consciousness metrics
  • POST /api/chat/sessions/:id/end: Manually trigger session consolidation

Checking 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;"

Clone this wiki locally