pub struct EmbeddingCache {
pub inner: LruCache<String, Vec<f32>>,
pub hit_count: u64,
pub miss_count: u64,
}Expand description
LRU cache for embedding vectors keyed by a SHA-256 hash of the input text.
Fields§
§inner: LruCache<String, Vec<f32>>Inner LRU cache mapping text digests to embeddings.
hit_count: u64Number of cache hits.
miss_count: u64Number of cache misses.
Implementations§
Source§impl EmbeddingCache
impl EmbeddingCache
Sourcepub fn get(&mut self, text: &str) -> Option<Vec<f32>>
pub fn get(&mut self, text: &str) -> Option<Vec<f32>>
Look up a cached vector for text, returning None on a cache miss.
Sourcepub fn insert(&mut self, text: &str, vector: Vec<f32>)
pub fn insert(&mut self, text: &str, vector: Vec<f32>)
Insert or update a cached vector for text.
Sourcepub fn stats(&self) -> EmbeddingCacheStats
pub fn stats(&self) -> EmbeddingCacheStats
Return a snapshot of cache hit/miss counts and entry count.
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request