IndexBackend

Trait IndexBackend 

Source
pub trait IndexBackend: Send + Sync {
    // Required methods
    fn index(&mut self, memory: &Memory) -> Result<()>;
    fn remove(&mut self, id: &MemoryId) -> Result<bool>;
    fn search(
        &self,
        query: &str,
        filter: &SearchFilter,
        limit: usize,
    ) -> Result<Vec<(MemoryId, f32)>>;
    fn clear(&mut self) -> Result<()>;
    fn list_all(
        &self,
        filter: &SearchFilter,
        limit: usize,
    ) -> Result<Vec<(MemoryId, f32)>>;
    fn get_memory(&self, id: &MemoryId) -> Result<Option<Memory>>;

    // Provided method
    fn reindex(&mut self, memories: &[Memory]) -> Result<()> { ... }
}
Expand description

Trait for index layer backends.

Index backends provide full-text search capabilities using BM25 or similar algorithms.

Required Methods§

Source

fn index(&mut self, memory: &Memory) -> Result<()>

Indexes a memory for full-text search.

§Errors

Returns an error if the indexing operation fails.

Source

fn remove(&mut self, id: &MemoryId) -> Result<bool>

Removes a memory from the index.

§Errors

Returns an error if the removal operation fails.

Source

fn search( &self, query: &str, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Searches for memories matching a text query.

Returns memory IDs with their BM25 scores, ordered by relevance.

§Errors

Returns an error if the search operation fails.

Source

fn clear(&mut self) -> Result<()>

Clears the entire index.

§Errors

Returns an error if the clear operation fails.

Source

fn list_all( &self, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Lists all indexed memories, optionally filtered.

Unlike search, this doesn’t require a query and returns all entries.

§Errors

Returns an error if the operation fails.

Source

fn get_memory(&self, id: &MemoryId) -> Result<Option<Memory>>

Retrieves a memory by ID.

§Errors

Returns an error if the operation fails.

Provided Methods§

Source

fn reindex(&mut self, memories: &[Memory]) -> Result<()>

Re-indexes all memories.

§Errors

Returns an error if any memory fails to index.

Implementors§