pub struct CompactionManager { /* private fields */ }Expand description
Context manager that handles compaction automatically
Implementations§
Source§impl CompactionManager
impl CompactionManager
Sourcepub fn new(strategy: CompactionStrategy, context_window: usize) -> Self
pub fn new(strategy: CompactionStrategy, context_window: usize) -> Self
Create a new compaction manager
Sourcepub fn with_config(
strategy: CompactionStrategy,
context_window: usize,
config: CompactionConfig,
) -> Self
pub fn with_config( strategy: CompactionStrategy, context_window: usize, config: CompactionConfig, ) -> Self
Create a new compaction manager with custom config
Sourcepub fn with_compactor<C: Compactor + 'static>(self, compactor: Arc<C>) -> Self
pub fn with_compactor<C: Compactor + 'static>(self, compactor: Arc<C>) -> Self
Set the compactor to use
Sourcepub fn set_compactor(&mut self, compactor: Arc<dyn Compactor>)
pub fn set_compactor(&mut self, compactor: Arc<dyn Compactor>)
Set the compactor from a trait object
Sourcepub fn should_compact(&self, context_tokens: usize, iteration: usize) -> bool
pub fn should_compact(&self, context_tokens: usize, iteration: usize) -> bool
Check if compaction should be triggered
Sourcepub fn strategy(&self) -> &CompactionStrategy
pub fn strategy(&self) -> &CompactionStrategy
Get the current strategy
Sourcepub fn config(&self) -> &CompactionConfig
pub fn config(&self) -> &CompactionConfig
Get the compaction configuration
Sourcepub fn set_config(&mut self, config: CompactionConfig)
pub fn set_config(&mut self, config: CompactionConfig)
Set compaction configuration
Sourcepub fn context_window(&self) -> usize
pub fn context_window(&self) -> usize
Get the context window this manager computes thresholds against.
Sourcepub fn set_context_window(&mut self, context_window: usize)
pub fn set_context_window(&mut self, context_window: usize)
Update the context window (e.g. after a model switch changed the
real capacity). Affects subsequent should_compact checks.
Sourcepub async fn compact_if_needed(
&self,
messages: &[Message],
instruction: Option<&str>,
context_tokens: usize,
iteration: usize,
) -> Result<Option<CompactedContext>, CompactionError>
pub async fn compact_if_needed( &self, messages: &[Message], instruction: Option<&str>, context_tokens: usize, iteration: usize, ) -> Result<Option<CompactedContext>, CompactionError>
Compact the given messages if appropriate
Sourcepub async fn compact_now(
&self,
messages: &[Message],
instruction: Option<&str>,
) -> Result<CompactedContext, CompactionError>
pub async fn compact_now( &self, messages: &[Message], instruction: Option<&str>, ) -> Result<CompactedContext, CompactionError>
Force compaction regardless of strategy
Sourcepub fn estimate_tokens(&self, messages: &[Message]) -> usize
pub fn estimate_tokens(&self, messages: &[Message]) -> usize
Get estimated token count for messages
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CompactionManager
impl !UnwindSafe for CompactionManager
impl Freeze for CompactionManager
impl Send for CompactionManager
impl Sync for CompactionManager
impl Unpin for CompactionManager
impl UnsafeUnpin for CompactionManager
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