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,
) -> CompactionManager
pub fn new( strategy: CompactionStrategy, context_window: usize, ) -> CompactionManager
Create a new compaction manager
Sourcepub fn with_config(
strategy: CompactionStrategy,
context_window: usize,
config: CompactionConfig,
) -> CompactionManager
pub fn with_config( strategy: CompactionStrategy, context_window: usize, config: CompactionConfig, ) -> CompactionManager
Create a new compaction manager with custom config
Sourcepub fn with_compactor<C>(self, compactor: Arc<C>) -> CompactionManagerwhere
C: Compactor + 'static,
pub fn with_compactor<C>(self, compactor: Arc<C>) -> CompactionManagerwhere
C: Compactor + 'static,
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 set_config(&mut self, config: CompactionConfig)
pub fn set_config(&mut self, config: CompactionConfig)
Set compaction configuration
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§
Source§impl Default for CompactionManager
impl Default for CompactionManager
Source§fn default() -> CompactionManager
fn default() -> CompactionManager
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CompactionManager
impl !RefUnwindSafe for CompactionManager
impl Send for CompactionManager
impl Sync for CompactionManager
impl Unpin for CompactionManager
impl UnsafeUnpin for CompactionManager
impl !UnwindSafe 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