Skip to main content

EmbeddingCache

Trait EmbeddingCache 

Source
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§

Source

fn get(&self, key: &str) -> Option<Vec<f32>>

Get an embedding from the cache

Source

fn set( &self, key: &str, embedding: Vec<f32>, ttl: Option<Duration>, ) -> Result<()>

Store an embedding in the cache with optional TTL

Source

fn invalidate(&self, key: &str) -> Result<()>

Remove an entry from the cache

Source

fn clear(&self) -> Result<()>

Clear all entries from the cache

Source

fn stats(&self) -> CacheStats

Get cache statistics

Source

fn is_enabled(&self) -> bool

Check if the cache is enabled

Provided Methods§

Source

fn compute_key(&self, text: &str, model: &str) -> String

Compute a cache key for the given text and model

Implementors§