pub struct SlidingWindowMemory { /* private fields */ }Expand description
Simple sliding window memory that keeps the N most recent messages.
This implementation uses a FIFO strategy where old messages are automatically removed when the window size limit is reached. It’s suitable for:
- Simple conversation contexts
- Memory-constrained environments
- Cases where only recent context matters
Implementations§
Source§impl SlidingWindowMemory
impl SlidingWindowMemory
Sourcepub fn with_strategy(window_size: usize, strategy: TrimStrategy) -> Self
pub fn with_strategy(window_size: usize, strategy: TrimStrategy) -> Self
Create a new sliding window memory with specified trim strategy
§Arguments
window_size- Maximum number of messages to keep in memorystrategy- How to handle overflow when window is full
Sourcepub fn window_size(&self) -> usize
pub fn window_size(&self) -> usize
Sourcepub fn messages(&self) -> Vec<ChatMessage>
pub fn messages(&self) -> Vec<ChatMessage>
Get all stored messages in chronological order.
§Returns
A vector containing all messages from oldest to newest
Sourcepub fn recent_messages(&self, limit: usize) -> Vec<ChatMessage>
pub fn recent_messages(&self, limit: usize) -> Vec<ChatMessage>
Sourcepub fn needs_summary(&self) -> bool
pub fn needs_summary(&self) -> bool
Check if memory needs summarization
Sourcepub fn mark_for_summary(&mut self)
pub fn mark_for_summary(&mut self)
Mark memory as needing summarization
Sourcepub fn replace_with_summary(&mut self, summary: String)
pub fn replace_with_summary(&mut self, summary: String)
Replace all messages with a summary
§Arguments
summary- The summary text to replace all messages with
Trait Implementations§
Source§impl Clone for SlidingWindowMemory
impl Clone for SlidingWindowMemory
Source§fn clone(&self) -> SlidingWindowMemory
fn clone(&self) -> SlidingWindowMemory
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SlidingWindowMemory
impl Debug for SlidingWindowMemory
Source§impl MemoryProvider for SlidingWindowMemory
impl MemoryProvider for SlidingWindowMemory
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,
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. Read more
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,
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. Read more
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,
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. Read more
Source§fn memory_type(&self) -> MemoryType
fn memory_type(&self) -> MemoryType
Get the type of this memory provider. Read more
Source§fn needs_summary(&self) -> bool
fn needs_summary(&self) -> bool
Check if memory needs summarization
Source§fn mark_for_summary(&mut self)
fn mark_for_summary(&mut self)
Mark memory as needing summarization
Source§fn replace_with_summary(&mut self, summary: String)
fn replace_with_summary(&mut self, summary: String)
Replace all messages with a summary
Source§fn 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
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,
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
Auto Trait Implementations§
impl Freeze for SlidingWindowMemory
impl RefUnwindSafe for SlidingWindowMemory
impl Send for SlidingWindowMemory
impl Sync for SlidingWindowMemory
impl Unpin for SlidingWindowMemory
impl UnwindSafe for SlidingWindowMemory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage