pub struct ShortTermMemory { /* private fields */ }Expand description
Short-term memory for recent conversation context
Implementations§
Source§impl ShortTermMemory
impl ShortTermMemory
pub fn new(capacity: usize, ttl: Duration) -> Self
Sourcepub fn add(&self, content: impl Into<String>, source: MemorySource)
pub fn add(&self, content: impl Into<String>, source: MemorySource)
Add a new memory item
Sourcepub fn add_item(&self, item: MemoryItem)
pub fn add_item(&self, item: MemoryItem)
Add a memory item
Sourcepub fn get_all(&self) -> Vec<MemoryItem>
pub fn get_all(&self) -> Vec<MemoryItem>
Get all current memories (not expired)
Sourcepub fn get_recent(&self, n: usize) -> Vec<MemoryItem>
pub fn get_recent(&self, n: usize) -> Vec<MemoryItem>
Get the N most recent memories
Sourcepub fn search(&self, query: &str) -> Vec<MemoryItem>
pub fn search(&self, query: &str) -> Vec<MemoryItem>
Search for memories containing text
pub fn is_empty(&self) -> bool
Sourcepub fn as_context(&self, max_items: usize) -> String
pub fn as_context(&self, max_items: usize) -> String
Get as formatted context string
Auto Trait Implementations§
impl !Freeze for ShortTermMemory
impl !RefUnwindSafe for ShortTermMemory
impl Send for ShortTermMemory
impl Sync for ShortTermMemory
impl Unpin for ShortTermMemory
impl UnsafeUnpin for ShortTermMemory
impl UnwindSafe for ShortTermMemory
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> 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 more