pub struct EmbeddingsCache {
pub config: CacheConfig,
}Expand description
Redis-backed cache for deterministic content/model embedding lookups.
Fields§
§config: CacheConfigCache configuration.
Implementations§
Source§impl EmbeddingsCache
impl EmbeddingsCache
Sourcepub fn new(config: CacheConfig) -> Self
pub fn new(config: CacheConfig) -> Self
Creates a new embeddings cache configuration.
Sourcepub fn make_entry_id(&self, content: &str, model_name: &str) -> String
pub fn make_entry_id(&self, content: &str, model_name: &str) -> String
Generates the deterministic cache entry id for a content/model pair.
Sourcepub fn make_cache_key(&self, content: &str, model_name: &str) -> String
pub fn make_cache_key(&self, content: &str, model_name: &str) -> String
Generates the full Redis key for a content/model pair.
Sourcepub fn get(
&self,
content: &str,
model_name: &str,
) -> Result<Option<EmbeddingCacheEntry>>
pub fn get( &self, content: &str, model_name: &str, ) -> Result<Option<EmbeddingCacheEntry>>
Retrieves a cached embedding by content and model name.
Sourcepub fn get_by_key(&self, key: &str) -> Result<Option<EmbeddingCacheEntry>>
pub fn get_by_key(&self, key: &str) -> Result<Option<EmbeddingCacheEntry>>
Retrieves a cached embedding by its Redis key.
Sourcepub fn mget<I, S>(
&self,
contents: I,
model_name: &str,
) -> Result<Vec<Option<EmbeddingCacheEntry>>>
pub fn mget<I, S>( &self, contents: I, model_name: &str, ) -> Result<Vec<Option<EmbeddingCacheEntry>>>
Retrieves multiple cached embeddings by content and model name.
Sourcepub fn mget_by_keys<I, S>(
&self,
keys: I,
) -> Result<Vec<Option<EmbeddingCacheEntry>>>
pub fn mget_by_keys<I, S>( &self, keys: I, ) -> Result<Vec<Option<EmbeddingCacheEntry>>>
Retrieves multiple cached embeddings by Redis key.
Sourcepub fn set(
&self,
content: &str,
model_name: &str,
embedding: &[f32],
metadata: Option<Value>,
ttl_seconds: Option<u64>,
) -> Result<String>
pub fn set( &self, content: &str, model_name: &str, embedding: &[f32], metadata: Option<Value>, ttl_seconds: Option<u64>, ) -> Result<String>
Stores a cached embedding and returns its Redis key.
Sourcepub fn mset(
&self,
items: &[EmbeddingCacheItem],
ttl_seconds: Option<u64>,
) -> Result<Vec<String>>
pub fn mset( &self, items: &[EmbeddingCacheItem], ttl_seconds: Option<u64>, ) -> Result<Vec<String>>
Stores multiple cached embeddings and returns their Redis keys.
Sourcepub fn exists(&self, content: &str, model_name: &str) -> Result<bool>
pub fn exists(&self, content: &str, model_name: &str) -> Result<bool>
Checks whether a cached embedding exists for a content/model pair.
Sourcepub fn exists_by_key(&self, key: &str) -> Result<bool>
pub fn exists_by_key(&self, key: &str) -> Result<bool>
Checks whether a cached embedding exists for a Redis key.
Sourcepub fn mexists<I, S>(&self, contents: I, model_name: &str) -> Result<Vec<bool>>
pub fn mexists<I, S>(&self, contents: I, model_name: &str) -> Result<Vec<bool>>
Checks whether multiple cached embeddings exist for content/model pairs.
Sourcepub fn mexists_by_keys<I, S>(&self, keys: I) -> Result<Vec<bool>>
pub fn mexists_by_keys<I, S>(&self, keys: I) -> Result<Vec<bool>>
Checks whether multiple cached embeddings exist for Redis keys.
Sourcepub fn drop(&self, content: &str, model_name: &str) -> Result<()>
pub fn drop(&self, content: &str, model_name: &str) -> Result<()>
Removes a cached embedding by content and model name.
Sourcepub fn drop_by_key(&self, key: &str) -> Result<()>
pub fn drop_by_key(&self, key: &str) -> Result<()>
Removes a cached embedding by Redis key.
Sourcepub fn mdrop<I, S>(&self, contents: I, model_name: &str) -> Result<()>
pub fn mdrop<I, S>(&self, contents: I, model_name: &str) -> Result<()>
Removes multiple cached embeddings by content and model name.
Sourcepub fn mdrop_by_keys<I, S>(&self, keys: I) -> Result<()>
pub fn mdrop_by_keys<I, S>(&self, keys: I) -> Result<()>
Removes multiple cached embeddings by Redis key.
Sourcepub async fn aget(
&self,
content: &str,
model_name: &str,
) -> Result<Option<EmbeddingCacheEntry>>
pub async fn aget( &self, content: &str, model_name: &str, ) -> Result<Option<EmbeddingCacheEntry>>
Retrieves a cached embedding by content and model name asynchronously.
Sourcepub async fn aget_by_key(
&self,
key: &str,
) -> Result<Option<EmbeddingCacheEntry>>
pub async fn aget_by_key( &self, key: &str, ) -> Result<Option<EmbeddingCacheEntry>>
Retrieves a cached embedding by its Redis key asynchronously.
Sourcepub async fn amget<I, S>(
&self,
contents: I,
model_name: &str,
) -> Result<Vec<Option<EmbeddingCacheEntry>>>
pub async fn amget<I, S>( &self, contents: I, model_name: &str, ) -> Result<Vec<Option<EmbeddingCacheEntry>>>
Retrieves multiple cached embeddings by content and model name asynchronously.
Sourcepub async fn amget_by_keys<I, S>(
&self,
keys: I,
) -> Result<Vec<Option<EmbeddingCacheEntry>>>
pub async fn amget_by_keys<I, S>( &self, keys: I, ) -> Result<Vec<Option<EmbeddingCacheEntry>>>
Retrieves multiple cached embeddings by Redis key asynchronously.
Sourcepub async fn aset(
&self,
content: &str,
model_name: &str,
embedding: &[f32],
metadata: Option<Value>,
ttl_seconds: Option<u64>,
) -> Result<String>
pub async fn aset( &self, content: &str, model_name: &str, embedding: &[f32], metadata: Option<Value>, ttl_seconds: Option<u64>, ) -> Result<String>
Stores a cached embedding asynchronously and returns its Redis key.
Sourcepub async fn amset(
&self,
items: &[EmbeddingCacheItem],
ttl_seconds: Option<u64>,
) -> Result<Vec<String>>
pub async fn amset( &self, items: &[EmbeddingCacheItem], ttl_seconds: Option<u64>, ) -> Result<Vec<String>>
Stores multiple cached embeddings asynchronously and returns their Redis keys.
Sourcepub async fn aexists(&self, content: &str, model_name: &str) -> Result<bool>
pub async fn aexists(&self, content: &str, model_name: &str) -> Result<bool>
Checks whether a cached embedding exists for a content/model pair asynchronously.
Sourcepub async fn aexists_by_key(&self, key: &str) -> Result<bool>
pub async fn aexists_by_key(&self, key: &str) -> Result<bool>
Checks whether a cached embedding exists for a Redis key asynchronously.
Sourcepub async fn amexists<I, S>(
&self,
contents: I,
model_name: &str,
) -> Result<Vec<bool>>
pub async fn amexists<I, S>( &self, contents: I, model_name: &str, ) -> Result<Vec<bool>>
Checks whether multiple cached embeddings exist for content/model pairs asynchronously.
Sourcepub async fn amexists_by_keys<I, S>(&self, keys: I) -> Result<Vec<bool>>
pub async fn amexists_by_keys<I, S>(&self, keys: I) -> Result<Vec<bool>>
Checks whether multiple cached embeddings exist for Redis keys asynchronously.
Sourcepub async fn adrop(&self, content: &str, model_name: &str) -> Result<()>
pub async fn adrop(&self, content: &str, model_name: &str) -> Result<()>
Removes a cached embedding by content and model name asynchronously.
Sourcepub async fn adrop_by_key(&self, key: &str) -> Result<()>
pub async fn adrop_by_key(&self, key: &str) -> Result<()>
Removes a cached embedding by Redis key asynchronously.
Sourcepub async fn amdrop<I, S>(&self, contents: I, model_name: &str) -> Result<()>
pub async fn amdrop<I, S>(&self, contents: I, model_name: &str) -> Result<()>
Removes multiple cached embeddings by content and model name asynchronously.
Sourcepub async fn amdrop_by_keys<I, S>(&self, keys: I) -> Result<()>
pub async fn amdrop_by_keys<I, S>(&self, keys: I) -> Result<()>
Removes multiple cached embeddings by Redis key asynchronously.
Trait Implementations§
Source§impl Clone for EmbeddingsCache
impl Clone for EmbeddingsCache
Source§fn clone(&self) -> EmbeddingsCache
fn clone(&self) -> EmbeddingsCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EmbeddingsCache
impl Debug for EmbeddingsCache
Auto Trait Implementations§
impl Freeze for EmbeddingsCache
impl RefUnwindSafe for EmbeddingsCache
impl Send for EmbeddingsCache
impl Sync for EmbeddingsCache
impl Unpin for EmbeddingsCache
impl UnsafeUnpin for EmbeddingsCache
impl UnwindSafe for EmbeddingsCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().