pub struct EmbeddingCache { /* private fields */ }Expand description
Thread-safe LRU embedding cache with bytes-based capacity
Implementations§
Source§impl EmbeddingCache
impl EmbeddingCache
Sourcepub fn new(max_bytes: usize) -> Self
pub fn new(max_bytes: usize) -> Self
Create a new cache with the specified byte capacity
§Arguments
max_bytes: Maximum bytes to use for embeddings- Default recommendation: 100MB (~25K embeddings @ 1536 dims)
- Each 1536-dim embedding uses 6144 bytes (1536 * 4)
Sourcepub fn default_capacity() -> Self
pub fn default_capacity() -> Self
Create a cache with default capacity (100MB)
Sourcepub fn get(&self, key: &str) -> Option<Arc<[f32]>>
pub fn get(&self, key: &str) -> Option<Arc<[f32]>>
Get an embedding from the cache
Returns Arc clone (cheap pointer copy, not vector copy)
Sourcepub fn put(&self, key: String, embedding: Vec<f32>)
pub fn put(&self, key: String, embedding: Vec<f32>)
Insert an embedding into the cache
If the key already exists, the embedding is updated and moved to front. If capacity is exceeded, least recently used entries are evicted.
Sourcepub fn stats(&self) -> EmbeddingCacheStats
pub fn stats(&self) -> EmbeddingCacheStats
Get cache statistics
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EmbeddingCache
impl RefUnwindSafe for EmbeddingCache
impl Send for EmbeddingCache
impl Sync for EmbeddingCache
impl Unpin for EmbeddingCache
impl UnsafeUnpin for EmbeddingCache
impl UnwindSafe for EmbeddingCache
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.