Skip to main content

SpeculativeCache

Struct SpeculativeCache 

Source
pub struct SpeculativeCache { /* private fields */ }

Implementations§

Source§

impl SpeculativeCache

Source

pub fn new( max_size: usize, keyword_threshold: f32, embedding_threshold: f32, ) -> Self

Source

pub fn pre_assemble( &mut self, predictions: Vec<String>, builder: impl Fn(&str) -> Option<(String, Vec<MemoryId>, Option<Vec<f32>>)>, )

Source

pub fn try_hit( &mut self, query: &str, query_embedding: Option<&[f32]>, ) -> Option<CacheEntry>

Try to find a cached context for this query. Uses cosine similarity on embeddings when available, falls back to keyword overlap only when no embeddings exist.

Source

pub fn evict_stale(&mut self, max_age_us: u64, now: Timestamp)

Source

pub fn stats(&self) -> CacheStats

Source

pub fn entries(&self) -> &[CacheEntry]

The current cache entries (predicted topic, pre-assembled context, source memories, hit count, age), for introspection and display.

Source§

impl SpeculativeCache

Source

pub fn save(&self, path: &Path, min_hits: u32) -> Result<()>

Save cache entries with at least min_hits to a JSON file. Entries below the threshold are considered stale and dropped. Uses atomic write (temp file + rename) to avoid corruption.

Source

pub fn load(&mut self, path: &Path) -> Result<()>

Load cache entries from a JSON file, merging into the current cache. Preserves the configured max_size and thresholds. Resets last_accessed timestamps so LRU eviction works correctly after reload.

Trait Implementations§

Source§

impl Default for SpeculativeCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.