pub struct ConversationTokenBufferMemory { /* private fields */ }Expand description
A memory strategy that keeps messages within a token budget.
Uses a simple estimator (~4 chars per token) to approximate token counts.
On load, removes the oldest messages until the total estimated tokens
fit within max_tokens.
Implementations§
Source§impl ConversationTokenBufferMemory
impl ConversationTokenBufferMemory
Sourcepub fn new(store: Arc<dyn MemoryStore>, max_tokens: usize) -> Self
pub fn new(store: Arc<dyn MemoryStore>, max_tokens: usize) -> Self
Create a new token buffer memory wrapping the given store.
Sourcepub fn estimate_tokens(text: &str) -> usize
pub fn estimate_tokens(text: &str) -> usize
Estimate the number of tokens in a text string.
Uses the simple heuristic of ~4 characters per token, with a minimum of 1.
Trait Implementations§
Source§impl MemoryStore for ConversationTokenBufferMemory
impl MemoryStore for ConversationTokenBufferMemory
fn append<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<(), SynapticError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, SynapticError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn clear<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), SynapticError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for ConversationTokenBufferMemory
impl !RefUnwindSafe for ConversationTokenBufferMemory
impl Send for ConversationTokenBufferMemory
impl Sync for ConversationTokenBufferMemory
impl Unpin for ConversationTokenBufferMemory
impl UnsafeUnpin for ConversationTokenBufferMemory
impl !UnwindSafe for ConversationTokenBufferMemory
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