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§
Sourcefn 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 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,
Sourcefn 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 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,
Sourcefn 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 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 successfullyErr(LLMError)if clearing failed
Sourcefn memory_type(&self) -> MemoryType
fn memory_type(&self) -> MemoryType
Provided Methods§
Sourcefn needs_summary(&self) -> bool
fn needs_summary(&self) -> bool
Check if memory needs summarization
Sourcefn mark_for_summary(&mut self)
fn mark_for_summary(&mut self)
Mark memory as needing summarization
Sourcefn replace_with_summary(&mut self, _summary: String)
fn replace_with_summary(&mut self, _summary: String)
Replace all messages with a summary
Sourcefn get_event_receiver(&self) -> Option<Receiver<MessageEvent>>
fn get_event_receiver(&self) -> Option<Receiver<MessageEvent>>
Get a receiver for reactive events if this memory supports them
Sourcefn 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 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