Expand description
Index backend trait.
The index layer provides full-text search capabilities using BM25 or similar algorithms. It enables keyword-based retrieval of memories.
§Available Implementations
| Backend | Use Case | Features |
|---|---|---|
SqliteBackend | Default; embedded | FTS5 with BM25 ranking |
PostgresBackend | Multi-user | ts_rank with stemming |
RediSearchBackend | High throughput | Prefix/fuzzy matching |
§Error Modes and Guarantees
All backends return Result<T> with errors propagated via crate::Error.
§Indexing Behavior
| Backend | Atomicity | Index Lag | Rebuild Cost |
|---|---|---|---|
SQLite | Transactional | Immediate | O(n) |
| PostgreSQL | Transactional | Immediate | O(n log n) |
RediSearch | Eventual | <100ms | O(n) |
§Error Recovery
| Error Type | Recovery Strategy |
|---|---|
Error::Storage | Check DB connection; retry |
Error::InvalidInput | Query syntax error; validate before calling |
Error::OperationFailed | Index corruption; call reindex() |
§Consistency with Persistence Layer
The index is a derived view of the persistence layer. If the index becomes
stale or corrupted, call reindex() to rebuild from the authoritative persistence store.
§Performance Characteristics
- Search complexity: O(log n) for indexed queries
- Batch efficiency:
get_memories_batch()avoids N+1 query pattern - FTS tokenization: Whitespace + punctuation split (
SQLite), language-aware (PostgreSQL)
Traits§
- Index
Backend - Trait for index layer backends.