MemoryProvider

Trait MemoryProvider 

Source
pub trait MemoryProvider: Send + Sync {
Show 15 methods // Required methods fn remember<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn recall<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, limit: Option<usize>, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn clear<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn memory_type(&self) -> MemoryType; fn size(&self) -> usize; fn clone_box(&self) -> Box<dyn MemoryProvider>; // Provided methods fn is_empty(&self) -> bool { ... } fn needs_summary(&self) -> bool { ... } fn mark_for_summary(&mut self) { ... } fn replace_with_summary(&mut self, _summary: String) { ... } fn get_event_receiver(&self) -> Option<Receiver<MessageEvent>> { ... } fn remember_with_role<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 ChatMessage, _role: String, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn id(&self) -> Option<String> { ... } fn preload(&mut self, _data: Vec<ChatMessage>) -> bool { ... } fn export(&self) -> Vec<ChatMessage> { ... }
}
Expand description

Trait for memory providers that can store and retrieve conversation history.

Memory providers enable LLMs to maintain context across conversations by:

  • Storing messages as they are exchanged
  • Retrieving relevant past messages based on queries
  • Managing memory size and cleanup

Required Methods§

Source

fn remember<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store a message in memory.

§Arguments
  • message - The chat message to store
§Returns
  • Ok(()) if the message was stored successfully
  • Err(LLMError) if storage failed
Source

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

Retrieve relevant messages from memory based on a query.

§Arguments
  • query - The query string to search for relevant messages
  • limit - Optional maximum number of messages to return
§Returns
  • Ok(Vec<ChatMessage>) containing relevant messages
  • Err(LLMError) if retrieval failed
Source

fn clear<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear all stored messages from memory.

§Returns
  • Ok(()) if memory was cleared successfully
  • Err(LLMError) if clearing failed
Source

fn memory_type(&self) -> MemoryType

Get the type of this memory provider.

§Returns

The memory type enum variant

Source

fn size(&self) -> usize

Get the current number of stored messages.

§Returns

The number of messages currently in memory

Source

fn clone_box(&self) -> Box<dyn MemoryProvider>

Clone the memory provider into a new Box This is needed for persistence across requests

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the memory is empty.

§Returns

true if no messages are stored, false otherwise

Source

fn needs_summary(&self) -> bool

Check if memory needs summarization

Source

fn mark_for_summary(&mut self)

Mark memory as needing summarization

Source

fn replace_with_summary(&mut self, _summary: String)

Replace all messages with a summary

Source

fn get_event_receiver(&self) -> Option<Receiver<MessageEvent>>

Get a receiver for reactive events if this memory supports them

Source

fn remember_with_role<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 ChatMessage, _role: String, ) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remember a message with a specific role for reactive memory

Source

fn id(&self) -> Option<String>

Get a unique identifier for this memory instance Used for caching and persistence

Source

fn preload(&mut self, _data: Vec<ChatMessage>) -> bool

Preload memory from a cache or storage Returns true if memory was successfully preloaded

Source

fn export(&self) -> Vec<ChatMessage>

Export memory data for caching or persistence Returns the messages that should be persisted

Implementors§