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
impl EmbeddingCache
Sourcepub fn new(capacity: usize) -> Self
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.
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Unstable: convenience constructor; subject to change with cache redesign.
Sourcepub fn compute_key(
&self,
text: &str,
model_config: ModelConfig,
role: EmbeddingRole,
) -> [u8; 32]
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.
Sourcepub fn get(&self, key: &[u8; 32]) -> Option<Arc<[f32]>>
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.
Sourcepub fn put(&self, key: [u8; 32], embedding: Vec<f32>)
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.
Sourcepub fn get_many(&self, keys: &[[u8; 32]]) -> Vec<Option<Arc<[f32]>>>
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).
Sourcepub fn put_many(&self, entries: Vec<([u8; 32], Vec<f32>)>)
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.
Sourcepub fn stats(&self) -> CacheStats
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.
Sourcepub fn per_shard_stats(&self) -> Vec<ShardStats>
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.
Sourcepub fn clear(&self)
pub fn clear(&self)
Unstable: internal cache management; may be removed in favor of capacity-based eviction.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Unstable: internal state query; may be removed when zero-capacity is the only disable path.