Skip to main content

MemoryBackend

Trait MemoryBackend 

Source
pub trait MemoryBackend: Send + Sync {
Show 20 methods // Required methods fn as_any(&self) -> &dyn Any; fn store<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, value: &'life3 str, metadata: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn recall<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<MemoryEntry>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn search<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, query: &'life2 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn forget<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn list<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn store_conversation<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, chat_id: &'life1 str, sender_id: &'life2 str, role: &'life3 str, content: &'life4 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait; fn get_conversation_history<'life0, 'life1, 'async_trait>( &'life0 self, chat_id: &'life1 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, String)>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_sticker_cache<'life0, 'life1, 'async_trait>( &'life0 self, sticker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn store_sticker_cache<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, sticker_id: &'life1 str, file_id: &'life2 str, description: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; // Provided methods fn store_conversation_batch<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, entries: &'life1 [(&'life2 str, &'life3 str, &'life4 str, &'life5 str)], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait { ... } fn clear_conversation<'life0, 'life1, 'async_trait>( &'life0 self, chat_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn search_conversations<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, limit: usize, chat_id: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<ConversationSearchHit>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn store_embedding<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, vector: &'life3 [f32], text: &'life4 str, model: &'life5 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait { ... } fn search_embeddings<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, query_vector: &'life2 [f32], limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<EmbeddingEntry>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn store_file_index<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, hash: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn get_file_index<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<FileIndex>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn store_chunk<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file_path: &'life1 str, start_line: u32, end_line: u32, content: &'life2 str, embedding: Option<&'life3 [f32]>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn get_chunks_for_file<'life0, 'life1, 'async_trait>( &'life0 self, file_path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Chunk>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn delete_chunks_for_file<'life0, 'life1, 'async_trait>( &'life0 self, file_path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... }
}
Expand description

The core MemoryBackend trait.

Required Methods§

Source

fn as_any(&self) -> &dyn Any

For downcasting to concrete types

Source

fn store<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, value: &'life3 str, metadata: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Store a key-value memory

Source

fn recall<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Recall a specific memory by key

Source

fn search<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, query: &'life2 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Search memories by query (semantic or keyword)

Source

fn forget<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete a memory

Source

fn list<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all memories in a namespace

Source

fn store_conversation<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, chat_id: &'life1 str, sender_id: &'life2 str, role: &'life3 str, content: &'life4 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Store a conversation message

Source

fn get_conversation_history<'life0, 'life1, 'async_trait>( &'life0 self, chat_id: &'life1 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, String)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get recent conversation history (returns role, content pairs)

Source

fn get_sticker_cache<'life0, 'life1, 'async_trait>( &'life0 self, sticker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get cached sticker description by ID

Source

fn store_sticker_cache<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, sticker_id: &'life1 str, file_id: &'life2 str, description: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Store sticker cache (sticker_id → description)

Provided Methods§

Source

fn store_conversation_batch<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, entries: &'life1 [(&'life2 str, &'life3 str, &'life4 str, &'life5 str)], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

Store multiple conversation messages in one batch.

Source

fn clear_conversation<'life0, 'life1, 'async_trait>( &'life0 self, chat_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete every stored message for one chat.

Backends opt in: the default errors rather than returning Ok, so a caller is never told a conversation was cleared when nothing was.

Source

fn search_conversations<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, limit: usize, chat_id: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<ConversationSearchHit>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn store_embedding<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, vector: &'life3 [f32], text: &'life4 str, model: &'life5 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

Store a vector embedding for a memory key

model identifies the embedding model that produced vector. It is persisted alongside the vector’s dimension so that later searches can exclude rows that are not comparable with the current query vector.

Source

fn search_embeddings<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, query_vector: &'life2 [f32], limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<EmbeddingEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Search embeddings by cosine similarity (returns nearest matches)

Only rows whose recorded dimension matches query_vector.len() are considered; vectors of a different dimension are not comparable and are never returned.

Source

fn store_file_index<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, hash: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Record that a file has been indexed

Source

fn get_file_index<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<FileIndex>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get file index entry (to check if re-indexing is needed)

Source

fn store_chunk<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, file_path: &'life1 str, start_line: u32, end_line: u32, content: &'life2 str, embedding: Option<&'life3 [f32]>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Store a code chunk with optional embedding

Source

fn get_chunks_for_file<'life0, 'life1, 'async_trait>( &'life0 self, file_path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Chunk>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Search chunks by file path

Source

fn delete_chunks_for_file<'life0, 'life1, 'async_trait>( &'life0 self, file_path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete all chunks for a file (before re-indexing)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§