pub struct ConversationSummaryBufferMemory<M: BaseChatModel> { /* private fields */ }Expand description
Conversation Summary Buffer Memory
Combines summary and full conversation:
- Keeps the last k rounds of full conversation (ensuring fluency)
- Summarizes older conversations (saving tokens)
§Example
ⓘ
use lc_memory::ConversationSummaryBufferMemory;
use lc_providers::OpenAIChat;
let llm = OpenAIChat::new(config);
let memory = ConversationSummaryBufferMemory::new(llm, 5); // Keep last 5 rounds
// After 20 rounds:
// - First 15 rounds -> summary
// - Last 5 rounds -> full conversationImplementations§
Source§impl<M: BaseChatModel> ConversationSummaryBufferMemory<M>
impl<M: BaseChatModel> ConversationSummaryBufferMemory<M>
pub fn new(llm: M, max_token_limit: usize) -> Self
pub fn with_input_key(self, key: impl Into<String>) -> Self
pub fn with_output_key(self, key: impl Into<String>) -> Self
pub fn with_memory_key(self, key: impl Into<String>) -> Self
pub fn with_summary_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_return_messages(self, return_messages: bool) -> Self
pub fn chat_memory(&self) -> &ChatMessageHistory
pub fn chat_memory_mut(&mut self) -> &mut ChatMessageHistory
pub fn max_token_limit(&self) -> usize
pub async fn buffer(&self) -> String
Trait Implementations§
Source§impl<M: BaseChatModel + Send + Sync + 'static> BaseMemory for ConversationSummaryBufferMemory<M>
impl<M: BaseChatModel + Send + Sync + 'static> BaseMemory for ConversationSummaryBufferMemory<M>
Source§fn load_memory_variables<'life0, 'life1, 'async_trait>(
&'life0 self,
_inputs: &'life1 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_memory_variables<'life0, 'life1, 'async_trait>(
&'life0 self,
_inputs: &'life1 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Load memory variables Read more
Source§fn save_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
inputs: &'life1 HashMap<String, String>,
outputs: &'life2 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn save_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
inputs: &'life1 HashMap<String, String>,
outputs: &'life2 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Save context Read more
Auto Trait Implementations§
impl<M> Freeze for ConversationSummaryBufferMemory<M>where
M: Freeze,
impl<M> RefUnwindSafe for ConversationSummaryBufferMemory<M>where
M: RefUnwindSafe,
impl<M> Send for ConversationSummaryBufferMemory<M>
impl<M> Sync for ConversationSummaryBufferMemory<M>
impl<M> Unpin for ConversationSummaryBufferMemory<M>where
M: Unpin,
impl<M> UnsafeUnpin for ConversationSummaryBufferMemory<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for ConversationSummaryBufferMemory<M>where
M: UnwindSafe,
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