Skip to main content

Memory Graph System

The Memory Graph is Soul Kernel’s core system for storing, retrieving, and synchronizing memories across devices.

Overview

Each Soul maintains a personal memory graph that:
  • Stores experiences as interconnected nodes
  • Enables semantic search and retrieval
  • Syncs across devices while preserving privacy
  • Maintains temporal and causal relationships

Architecture

Storage Layers

The memory graph uses a hybrid storage approach implemented in the storage crate:
  1. SQLite - Primary storage for memory events and metadata
    • WAL mode enabled for better concurrency
    • Automatic schema migrations
    • Indexes on timestamp and author fields
  2. Qdrant - Vector store for semantic search (currently mocked)
    • HNSW index for fast similarity search
    • Cosine similarity for relevance scoring
    • Filterable by event type, author, and time range
  3. Event Log - Append-only history for sync
    • Immutable event sourcing pattern
    • Supports CRDT-style reconciliation

Memory Types

Implementation

Storage Crate Structure

The memory persistence layer is implemented in kernel/storage/:

Memory Event Structure

Storage API

The MemoryStore trait provides the core interface:

Key Features

Vector similarity search with configurable parameters:

2. Temporal Awareness

Chronological queries for sync and history:

3. Performance

Benchmarked performance metrics:
  • Single insert: ~65 microseconds
  • Query top-k from 1000 events: ~2.1ms
  • Bulk insert 10k events: ~92ms

4. Thread Safety

All storage operations are thread-safe using Arc<Mutex<Connection>> for SQLite.

Usage Examples

Basic Memory Storage

Complex Queries

Memory Sync

Database Schema

The SQLite schema for memory storage:

Privacy & Security

  • Memories stored locally by default
  • Optional encryption at rest (future enhancement)
  • User controls sync preferences per memory type
  • GDPR-compliant deletion via event ID

Best Practices

  1. Generate Quality Embeddings - Use appropriate models for your domain
  2. Index Strategically - Add indexes for common query patterns
  3. Batch Operations - Use bulk inserts for better performance
  4. Monitor Storage Size - Implement retention policies
  5. Test Sync Logic - Ensure CRDT convergence properties

Performance Optimization

  • WAL Mode: Better concurrent read/write performance
  • Connection Pooling: Reuse database connections
  • Embedding Dimensions: Balance accuracy vs storage (384 dims default)
  • Compaction: Run compact() periodically to optimize storage

Next Steps

Change Log

  • 2025-06-13: Updated with actual storage implementation details
  • 2025-06-13: Added performance benchmarks and code examples
  • 2025-06-12: Initial memory graph architecture documentation