Skip to main content

EmbeddingCache

Struct EmbeddingCache 

Source
pub struct EmbeddingCache { /* private fields */ }
Expand description

Unstable: the sharding and eviction implementation may change.

Thread-safe, sharded LRU cache for computed embeddings. A capacity of zero disables storage operations. See docs/design.md for key identity, locking, and capacity semantics.

Implementations§

Source§

impl EmbeddingCache

Source

pub fn new(capacity: usize) -> Self

Unstable: constructor signature may change when shard count becomes configurable.

Creates a cache with the requested capacity; zero disables storage. Nonzero capacity is rounded up independently across its fixed shards. See docs/design.md for sharding and eviction behavior.

Source

pub fn with_default_capacity() -> Self

Unstable: convenience constructor; subject to change with cache redesign.

Source

pub fn compute_key( &self, text: &str, model_config: ModelConfig, role: EmbeddingRole, ) -> [u8; 32]

Unstable: the key scheme may change; do not persist keys across sessions.

Hashes text, model identity, active dimension, and retrieval role into a cache key. See docs/design.md for identity and collision-isolation details.

Source

pub fn get(&self, key: &[u8; 32]) -> Option<Arc<[f32]>>

Unstable: return type (Arc<[f32]>) may change to a newtype; internal cache API.

Returns Some(Arc<[f32]>) if found (cheap refcount bump), None otherwise. Updates per-shard hit/miss counters for metrics.

Source

pub fn put(&self, key: [u8; 32], embedding: Vec<f32>)

Unstable: internal cache storage method; interface may change.

Converts the Vec into Arc<[f32]> for shared-ownership storage. If the shard is at capacity, its least recently used entry is evicted.

Source

pub fn get_many(&self, keys: &[[u8; 32]]) -> Vec<Option<Arc<[f32]>>>

Unstable: batch cache access; return type may change with cache redesign.

Returns a vector of Option<Arc<[f32]>> for each key, in the same order. Each hit is an O(1) refcount bump (no data copy).

Source

pub fn put_many(&self, entries: Vec<([u8; 32], Vec<f32>)>)

Unstable: batch cache storage; interface may change with cache redesign.

Converts each Vec into Arc<[f32]> for shared-ownership storage.

Source

pub fn stats(&self) -> CacheStats

Unstable: returns CacheStats which is itself Unstable; metrics shape may evolve.

Aggregates per-shard counters. The size field is the sum of all shard sizes.

Source

pub fn per_shard_stats(&self) -> Vec<ShardStats>

Unstable: internal monitoring hook; shard count and ShardStats shape may change.

Returns a vector of (size, hits, misses) tuples, one per shard.

Source

pub fn clear(&self)

Unstable: internal cache management; may be removed in favor of capacity-based eviction.

Source

pub fn is_enabled(&self) -> bool

Unstable: internal state query; may be removed when zero-capacity is the only disable path.

Trait Implementations§

Source§

impl Default for EmbeddingCache

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more