MemoryProvider

Trait MemoryProvider 

Source
pub trait MemoryProvider: Send + Sync {
    // 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;

    // 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 { ... }
}
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

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

Implementors§