pub struct ContextCacheTracker { /* private fields */ }Expand description
Per-session, per-model prefix overlap tracker.
The baseline is keyed by (session_id, provider, model). Changing the
provider or model clears that key’s previous baseline so the first request
after a switch reports a low (zero) prefix hit rate.
Implementations§
Source§impl ContextCacheTracker
impl ContextCacheTracker
pub fn new() -> Self
Sourcepub fn estimate(
&mut self,
session_id: Option<&str>,
provider: &str,
model: &str,
context: &PiContext,
) -> PrefixHitEstimate
pub fn estimate( &mut self, session_id: Option<&str>, provider: &str, model: &str, context: &PiContext, ) -> PrefixHitEstimate
Compare context against the stored baseline for the active key, then
store this context as the new baseline.
Call this immediately before sending the request, after all context transforms have been applied.
Sourcepub fn finalize(
&self,
estimate: &PrefixHitEstimate,
total_input_tokens: u64,
) -> PrefixHitResult
pub fn finalize( &self, estimate: &PrefixHitEstimate, total_input_tokens: u64, ) -> PrefixHitResult
Compute the token-level prefix estimate once the provider reports total input tokens for the request.
Sourcepub fn clear_session(&mut self, session_id: Option<&str>)
pub fn clear_session(&mut self, session_id: Option<&str>)
Drop all baselines for a session (e.g. session reset/clear).
Trait Implementations§
Source§impl Clone for ContextCacheTracker
impl Clone for ContextCacheTracker
Source§fn clone(&self) -> ContextCacheTracker
fn clone(&self) -> ContextCacheTracker
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContextCacheTracker
impl Debug for ContextCacheTracker
Source§impl Default for ContextCacheTracker
impl Default for ContextCacheTracker
Source§fn default() -> ContextCacheTracker
fn default() -> ContextCacheTracker
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ContextCacheTracker
impl RefUnwindSafe for ContextCacheTracker
impl Send for ContextCacheTracker
impl Sync for ContextCacheTracker
impl Unpin for ContextCacheTracker
impl UnsafeUnpin for ContextCacheTracker
impl UnwindSafe for ContextCacheTracker
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