pub struct EmbeddingCache {
embedder: Arc<dyn Embedder>,
cache: RwLock<HashMap<String, CacheEntry>>,
max_size: usize,
access_counter: RwLock<u64>,
stats: RwLock<CacheStats>,
}Expand description
Embedding cache with LRU eviction.
Fields§
§embedder: Arc<dyn Embedder>The underlying embedder
cache: RwLock<HashMap<String, CacheEntry>>Cache map: content hash -> embedding
max_size: usizeMaximum cache size
access_counter: RwLock<u64>Global access counter
stats: RwLock<CacheStats>Cache statistics
Implementations§
Source§impl EmbeddingCache
impl EmbeddingCache
Sourcepub fn new(embedder: Arc<dyn Embedder>) -> Self
pub fn new(embedder: Arc<dyn Embedder>) -> Self
Create a new embedding cache with default size.
Sourcepub fn with_capacity(embedder: Arc<dyn Embedder>, max_size: usize) -> Self
pub fn with_capacity(embedder: Arc<dyn Embedder>, max_size: usize) -> Self
Create a new embedding cache with specified capacity.
Sourceasync fn next_access(&self) -> u64
async fn next_access(&self) -> u64
Get the next access count.
Sourceasync fn maybe_evict(&self)
async fn maybe_evict(&self)
Evict oldest entries if cache is full.
Sourcepub async fn embed_text(
&self,
texts: &[&str],
config: &EmbeddingConfig,
) -> Result<Vec<EmbeddingOutput>, EmbedError>
pub async fn embed_text( &self, texts: &[&str], config: &EmbeddingConfig, ) -> Result<Vec<EmbeddingOutput>, EmbedError>
Embed texts with caching.
Sourcepub async fn embed_query(
&self,
query: &str,
config: &EmbeddingConfig,
) -> Result<EmbeddingOutput, EmbedError>
pub async fn embed_query( &self, query: &str, config: &EmbeddingConfig, ) -> Result<EmbeddingOutput, EmbedError>
Embed a single query (always bypasses cache for queries).
Sourcepub async fn stats(&self) -> CacheStats
pub async fn stats(&self) -> CacheStats
Get cache statistics.
Sourcepub fn model_name(&self) -> &str
pub fn model_name(&self) -> &str
Get the model name.
Sourcepub fn modalities(&self) -> &[Modality]
pub fn modalities(&self) -> &[Modality]
Get supported modalities.
Auto Trait Implementations§
impl !Freeze for EmbeddingCache
impl !RefUnwindSafe for EmbeddingCache
impl Send for EmbeddingCache
impl Sync for EmbeddingCache
impl Unpin 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more