Memory Storage Tutorial
Learn how to use Soul Kernel’s memory storage system to persist and query memories.Prerequisites
- Rust 1.79+ installed
- Basic understanding of async Rust
- Soul Kernel workspace set up
Overview
In this tutorial, you’ll learn how to:- Initialize the storage system
- Store memory events
- Query memories using vector similarity
- Filter and retrieve specific memories
- Handle synchronization scenarios
Setting Up
First, add the storage crate to yourCargo.toml:
Basic Memory Storage
Let’s start with a simple example that stores and retrieves memories:Working with Embeddings
In a real application, you’ll generate embeddings using an LLM. Here’s a more realistic example:Vector Similarity Search
Find memories similar to a query:Advanced Filtering
Filter memories by type, author, or time range:Memory Context Building
Build context from related memories:Synchronization Support
Implement basic sync functionality:Performance Optimization
Tips for optimal performance:Error Handling
Properly handle storage errors:Complete Example
Here’s a complete example that demonstrates all concepts:Next Steps
- Learn about Memory Sync for cross-device synchronization
- Explore Embedding Generation with LLMs
- Read the Storage API Reference for detailed documentation
Troubleshooting
Common Issues
- Database locked errors: Ensure you’re not opening multiple connections to the same SQLite file
- Performance issues: Check embedding dimensions and consider using batch operations
- Memory growth: Implement retention policies and use
compact()regularly
Performance Tips
- Keep embeddings under 1024 dimensions
- Use batch inserts for bulk operations
- Index frequently queried fields
- Run
compact()during off-peak hours
Change Log
- 2025-06-13: Initial tutorial created with storage implementation examples