pub struct CompactingMemory<M, P, C: Compactor> { /* private fields */ }Expand description
Prepends a rolling summary of demoted history to the policy’s retained window. New evictions are compacted with the previous artifact as carry-over. The summary is outside the policy budget; callers needing a bounded prompt must also bound the compactor’s artifact.
Only one compaction per tracked conversation runs at a time. Concurrent loads return the previous summary and retained window immediately. Errors reach only the compacting caller; unchanged watermarks allow later loads to retry.
Summaries and watermarks are process-local. Restarts or discarded state cause recompaction; compactors with side effects must tolerate repeated input.
use rig_memory::{
CompactingMemory, InMemoryConversationMemory, SlidingWindowMemory,
TemplateCompactor,
};
let memory = CompactingMemory::new(
InMemoryConversationMemory::new(),
SlidingWindowMemory::last_messages(20),
TemplateCompactor::new(),
);Implementations§
Source§impl<M, P, C: Compactor> CompactingMemory<M, P, C>
impl<M, P, C: Compactor> CompactingMemory<M, P, C>
Source§impl<M, P, C: Compactor> CompactingMemory<M, P, C>
impl<M, P, C: Compactor> CompactingMemory<M, P, C>
Sourcepub fn into_inner(self) -> (M, P, C)
pub fn into_inner(self) -> (M, P, C)
Consume the wrapper and return its three components.
Sourcepub fn forget(&self, conversation_id: &ConversationId)
pub fn forget(&self, conversation_id: &ConversationId)
Drop the in-process state for conversation_id.
Entries otherwise persist for the wrapper’s lifetime. Does nothing if the state lock is poisoned. In-flight work is not cancelled.
Sourcepub fn tracked_conversations(&self) -> usize
pub fn tracked_conversations(&self) -> usize
Number of conversations currently tracked in the state map.
Useful for telemetry and leak detection. Returns 0 if the
internal state lock is poisoned.
Trait Implementations§
Source§impl<M, P, C> ConversationMemory for CompactingMemory<M, P, C>
impl<M, P, C> ConversationMemory for CompactingMemory<M, P, C>
Source§fn load<'a>(
&'a self,
conversation_id: &'a ConversationId,
) -> WasmBoxedFuture<'a, Result<Vec<Message>, MemoryError>>
fn load<'a>( &'a self, conversation_id: &'a ConversationId, ) -> WasmBoxedFuture<'a, Result<Vec<Message>, MemoryError>>
conversation_id. Read moreSource§fn append<'a>(
&'a self,
conversation_id: &'a ConversationId,
messages: Vec<Message>,
) -> WasmBoxedFuture<'a, Result<(), MemoryError>>
fn append<'a>( &'a self, conversation_id: &'a ConversationId, messages: Vec<Message>, ) -> WasmBoxedFuture<'a, Result<(), MemoryError>>
Source§fn clear<'a>(
&'a self,
conversation_id: &'a ConversationId,
) -> WasmBoxedFuture<'a, Result<(), MemoryError>>
fn clear<'a>( &'a self, conversation_id: &'a ConversationId, ) -> WasmBoxedFuture<'a, Result<(), MemoryError>>
conversation_id.