Overview
SqliteMemory is a production-ready implementation of the Memory trait using SQLite for persistent storage. It features:
- FTS5 Full-Text Search: Fast keyword search with Unicode support
- Temporal Indexing: B-tree indexes for efficient time-range queries
- Vector Storage: Optional embedding storage for semantic search (TIP-040)
- Thread-Safe: Uses
Mutex<Connection>for concurrent access
Struct Definition
sqlite.rs:14
Constructors
new()
SqliteMemory instance with a database file at the specified path. Creates parent directories if they don’t exist.
Example:
sqlite.rs:20
in_memory()
sqlite.rs:37
Database Schema
Tables
memory_entries
sqlite.rs:54
memory_fts (FTS5 Virtual Table)
sqlite.rs:74
Indexes
idx_memory_created_at: B-tree index oncreated_atfor temporal range queriesidx_memory_priority: Index onpriorityfor filteringidx_memory_source: Index onsourcefield
sqlite.rs:65
Triggers
Automatic triggers keep the FTS5 table synchronized withmemory_entries:
memory_ai: After INSERT - adds to FTS5memory_ad: After DELETE - removes from FTS5memory_au: After UPDATE - updates FTS5
sqlite.rs:83
FTS5 Full-Text Search
SqliteMemory uses SQLite’s FTS5 (Full-Text Search 5) extension for keyword search.
Features
- Unicode Support:
unicode61tokenizer handles international text - Diacritic Removal: Searches ignore accents (e.g., “cafe” matches “café”)
- Ranking: Results ranked by FTS5’s BM25 algorithm
- Automatic Sync: Triggers maintain FTS5 index consistency
Example
sqlite.rs:189
Search Implementation
FTS5 Query Builder
sqlite.rs:460
Filtered Query (No FTS)
Whenquery.text is empty, uses a simpler filtered query:
sqlite.rs:487
Vector Storage (TIP-040)
SqliteMemory implements the VectorMemory trait for semantic search.
Migration
Vector columns are added via idempotent migration on first initialization:embedding: BLOB storing f32 vectors (little-endian)embedding_model: Model name (e.g., “nomic-embed-text”)embedding_dim: Dimensionality of the embedding
sqlite.rs:108
Example
sqlite.rs:267
See Vector Search API for vector search methods.
Implementation Details
Thread Safety
sqlite.rs:133
Row Conversion
MemoryEntry structs.
Source: sqlite.rs:422
Performance Characteristics
- FTS5 Search: O(log n) for keyword lookup with BM25 ranking
- Temporal Range: O(log n) via B-tree index on
created_at - Vector Search: O(n) brute-force cosine scan (future: ANN index)
- Concurrent Access: Thread-safe but single-writer (SQLite limitation)