pub struct DemotingPolicyMemory<M, P, H> { /* private fields */ }Expand description
Applies a policy and delivers newly demoted prefixes to a hook before returning
retained history. The policy must report demotions through
MemoryPolicy::apply_with_demoted.
Only one delivery per tracked conversation runs at a time. Concurrent loads return retained history immediately without waiting for the hook, so success does not guarantee durable demotion. Hook errors reach only the delivering caller; unchanged watermarks allow later loads to retry.
Watermarks are process-local. Hooks must tolerate redelivery after restarts,
cancellation, or discarded tracking state, following DemotionHook.
use rig_memory::{
DemotingPolicyMemory, DemotionHook, InMemoryConversationMemory,
MemoryError, NoopDemotionHook, SlidingWindowMemory,
};
let memory = DemotingPolicyMemory::new(
InMemoryConversationMemory::new(),
SlidingWindowMemory::last_messages(20),
NoopDemotionHook,
);Implementations§
Source§impl<M, P, H> DemotingPolicyMemory<M, P, H>
impl<M, P, H> DemotingPolicyMemory<M, P, H>
Source§impl<M, P, H> DemotingPolicyMemory<M, P, H>
impl<M, P, H> DemotingPolicyMemory<M, P, H>
Sourcepub fn into_inner(self) -> (M, P, H)
pub fn into_inner(self) -> (M, P, H)
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, H> ConversationMemory for DemotingPolicyMemory<M, P, H>
impl<M, P, H> ConversationMemory for DemotingPolicyMemory<M, P, H>
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.