Storage API Reference
Thestorage crate provides the memory persistence layer for Soul Kernel.
Overview
The storage system implements a hybrid approach combining SQLite for reliable persistence and vector storage for semantic search capabilities.Core Types
MemoryEvent
The fundamental unit of memory storage.id- Unique identifier (UUID v4)timestamp- UTC timestamp of event creationauthor- Device or source identifierevent_type- Type of memory eventcontent- Human-readable contentembedding- Vector representation for similarity searchmetadata- Additional JSON metadata
MemoryEventType
MemoryQuery
Parameters for vector similarity search.embedding- Query vector for similarity searchtop_k- Maximum number of results to returnscore_threshold- Minimum similarity score (0.0 to 1.0)filter- Optional filters to apply
MemoryFilter
Traits
MemoryStore
The core trait that all storage implementations must provide.Implementations
HybridMemoryStore
The recommended implementation combining SQLite and vector search.SqliteMemoryStore
Direct SQLite implementation for simple use cases.Error Handling
StorageError
Usage Examples
Basic Usage
Vector Search
Synchronization
Performance Characteristics
| Operation | Performance |
|---|---|
| Single Insert | ~65μs |
| Query (1k events) | ~2.1ms |
| Bulk Insert (10k) | ~92ms |
| Get by ID | ~100μs |
Best Practices
- Batch Inserts: Use transactions for bulk operations
- Embedding Size: Keep embeddings reasonable (384 dims recommended)
- Indexing: Add custom indexes for frequent query patterns
- Compaction: Run
compact()during maintenance windows - Error Handling: Always handle
StorageErrorappropriately
Thread Safety
All storage implementations are thread-safe and can be shared across async tasks usingArc.
Migration Support
The storage layer includes automatic schema migrations:Configuration
SQLite Settings
The SQLite adapter uses these optimizations:- WAL mode for better concurrency
- Normal synchronous mode
- 64MB cache size
- In-memory temp store
Vector Store Settings
When using Qdrant (currently mocked):- HNSW index with M=16, ef=64
- Cosine similarity metric
- Automatic collection creation
See Also
Change Log
- 2025-06-13: Initial API documentation created