pub trait MemoryProvider: Send + Sync {
Show 16 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 remember_many<'life0, 'life1, 'async_trait>(
&'life0 mut self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
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§
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
Sourcefn clone_box(&self) -> Box<dyn MemoryProvider>
fn clone_box(&self) -> Box<dyn MemoryProvider>
Clone the memory provider into a new Box This is needed for persistence across requests
Provided Methods§
Sourcefn remember_many<'life0, 'life1, 'async_trait>(
&'life0 mut self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remember_many<'life0, 'life1, 'async_trait>(
&'life0 mut self,
messages: &'life1 [ChatMessage],
) -> Pin<Box<dyn Future<Output = Result<(), LLMError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store multiple messages as one logical write.
Providers can override this when they need to preflight capacity or preserve invariants across related messages.
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
Sourcefn id(&self) -> Option<String>
fn id(&self) -> Option<String>
Get a unique identifier for this memory instance Used for caching and persistence
Sourcefn preload(&mut self, _data: Vec<ChatMessage>) -> bool
fn preload(&mut self, _data: Vec<ChatMessage>) -> bool
Preload memory from a cache or storage Returns true if memory was successfully preloaded
Sourcefn export(&self) -> Vec<ChatMessage>
fn export(&self) -> Vec<ChatMessage>
Export memory data for caching or persistence Returns the messages that should be persisted
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".