pub struct CachedEmbeddingService<S> { /* private fields */ }Expand description
Unstable: caching strategy and constructor API may change; foundation-internal use only.
LRU-caching wrapper around an embedding service.
It preserves input order while reusing embeddings with matching model configuration and role.
See docs/service.md for the lookup and fill algorithm.
Implementations§
Source§impl<S: EmbeddingService> CachedEmbeddingService<S>
impl<S: EmbeddingService> CachedEmbeddingService<S>
Sourcepub fn new(inner: Arc<S>, cache_capacity: usize) -> Self
pub fn new(inner: Arc<S>, cache_capacity: usize) -> Self
Unstable: constructor signature may change when cache config becomes a struct.
§Arguments
inner- The underlying embedding servicecache_capacity- Maximum number of embeddings to cache
Sourcepub fn with_default_cache(inner: Arc<S>) -> Self
pub fn with_default_cache(inner: Arc<S>) -> Self
Unstable: constructor signature may change when cache config becomes a struct.
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Unstable: returns internal CacheStats type which is itself Unstable.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Unstable: internal cache management; API subject to change.
Trait Implementations§
Source§impl<S: EmbeddingService + 'static> EmbeddingService for CachedEmbeddingService<S>
impl<S: EmbeddingService + 'static> EmbeddingService for CachedEmbeddingService<S>
Source§fn embed_with_role<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
model: EmbeddingModel,
role: EmbeddingRole,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed_with_role<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
model: EmbeddingModel,
role: EmbeddingRole,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Override: cache under the role key rather than prefixing here.
embed_query and embed_passage reach this through their trait defaults,
so all three role paths share one cache-aware implementation.