pub trait EmbeddingCache: Send + Sync {
// Required methods
fn get(&self, key: &str) -> Option<Vec<f32>>;
fn set(
&self,
key: &str,
embedding: Vec<f32>,
ttl: Option<Duration>,
) -> Result<()>;
fn invalidate(&self, key: &str) -> Result<()>;
fn clear(&self) -> Result<()>;
fn stats(&self) -> CacheStats;
fn is_enabled(&self) -> bool;
// Provided method
fn compute_key(&self, text: &str, model: &str) -> String { ... }
}Expand description
Trait for embedding cache implementations
This trait defines the interface for caching embeddings. Implementations can use different backends (in-memory, Redis, disk, etc.).
Required Methods§
Sourcefn set(
&self,
key: &str,
embedding: Vec<f32>,
ttl: Option<Duration>,
) -> Result<()>
fn set( &self, key: &str, embedding: Vec<f32>, ttl: Option<Duration>, ) -> Result<()>
Store an embedding in the cache with optional TTL
Sourcefn invalidate(&self, key: &str) -> Result<()>
fn invalidate(&self, key: &str) -> Result<()>
Remove an entry from the cache
Sourcefn stats(&self) -> CacheStats
fn stats(&self) -> CacheStats
Get cache statistics
Sourcefn is_enabled(&self) -> bool
fn is_enabled(&self) -> bool
Check if the cache is enabled
Provided Methods§
Sourcefn compute_key(&self, text: &str, model: &str) -> String
fn compute_key(&self, text: &str, model: &str) -> String
Compute a cache key for the given text and model