pub struct SummaryMemory { /* private fields */ }Expand description
Summary memory implementation
This struct is responsible for generating and managing conversation summaries. It can automatically generate summaries when the conversation reaches a certain length, and load previous summaries when needed.
Implementations§
Source§impl SummaryMemory
impl SummaryMemory
Sourcepub async fn new(
session_id: String,
data_dir: PathBuf,
summary_threshold: usize,
) -> Result<Self>
pub async fn new( session_id: String, data_dir: PathBuf, summary_threshold: usize, ) -> Result<Self>
Create a new summary memory instance
Create a new summary memory instance with shared message history
Sourcepub fn with_summary_prompt_template(self, template: String) -> Self
pub fn with_summary_prompt_template(self, template: String) -> Self
Set summary prompt template
Sourcepub fn with_recent_messages_count(self, count: usize) -> Self
pub fn with_recent_messages_count(self, count: usize) -> Self
Set the number of recent messages to keep
Sourcepub async fn load_context(&self) -> Result<Vec<String>>
pub async fn load_context(&self) -> Result<Vec<String>>
Load context from memory
Sourcepub async fn load_summary(&self) -> Result<SummaryData>
pub async fn load_summary(&self) -> Result<SummaryData>
Load summary
Sourcepub async fn check_and_generate_summary(&self) -> Result<bool>
pub async fn check_and_generate_summary(&self) -> Result<bool>
Check if summary needs to be generated and generate if needed
Sourcepub fn get_session_id(&self) -> &str
pub fn get_session_id(&self) -> &str
Get session ID
Sourcepub async fn get_memory_stats(&self) -> Result<Value>
pub async fn get_memory_stats(&self) -> Result<Value>
Get memory statistics
Trait Implementations§
Source§impl BaseMemory for SummaryMemory
impl BaseMemory for SummaryMemory
fn memory_variables(&self) -> Vec<String>
fn load_memory_variables<'a>( &'a self, _inputs: &'a HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, Error>> + Send + 'a>>
fn save_context<'a>( &'a self, inputs: &'a HashMap<String, Value>, outputs: &'a HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
fn clear<'a>( &'a self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
fn clone_box(&self) -> Box<dyn BaseMemory>
fn get_session_id(&self) -> Option<&str>
fn set_session_id(&mut self, session_id: String)
fn get_token_count(&self) -> Result<usize, Error>
fn as_any(&self) -> &dyn Any
Source§impl Clone for SummaryMemory
impl Clone for SummaryMemory
Auto Trait Implementations§
impl Freeze for SummaryMemory
impl !RefUnwindSafe for SummaryMemory
impl Send for SummaryMemory
impl Sync for SummaryMemory
impl Unpin for SummaryMemory
impl !UnwindSafe for SummaryMemory
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