Skip to main content

Module index

Module index 

Source
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

BackendUse CaseFeatures
SqliteBackendDefault; embeddedFTS5 with BM25 ranking
PostgresBackendMulti-userts_rank with stemming
RediSearchBackendHigh throughputPrefix/fuzzy matching

§Error Modes and Guarantees

All backends return Result<T> with errors propagated via crate::Error.

§Indexing Behavior

BackendAtomicityIndex LagRebuild Cost
SQLiteTransactionalImmediateO(n)
PostgreSQLTransactionalImmediateO(n log n)
RediSearchEventual<100msO(n)

§Error Recovery

Error TypeRecovery Strategy
Error::StorageCheck DB connection; retry
Error::InvalidInputQuery syntax error; validate before calling
Error::OperationFailedIndex 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§

IndexBackend
Trait for index layer backends.