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 thestorage crate:
-
SQLite - Primary storage for memory events and metadata
- WAL mode enabled for better concurrency
- Automatic schema migrations
- Indexes on timestamp and author fields
-
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
-
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 inkernel/storage/:
Memory Event Structure
Storage API
TheMemoryStore trait provides the core interface:
Key Features
1. Semantic Search
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 usingArc<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
- Generate Quality Embeddings - Use appropriate models for your domain
- Index Strategically - Add indexes for common query patterns
- Batch Operations - Use bulk inserts for better performance
- Monitor Storage Size - Implement retention policies
- 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
- Learn about Skill System integration with memories
- Explore Shell Integration for platform-specific memory handling
- Read the Storage API Reference for detailed documentation
- See Memory Sync Tutorial for cross-device setup
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