Package com.redis.vl.extensions.cache
Class EmbeddingsCache
java.lang.Object
com.redis.vl.extensions.cache.BaseCache
com.redis.vl.extensions.cache.EmbeddingsCache
Cache for storing and retrieving text embeddings.
This cache stores exact embeddings for text inputs, allowing retrieval of previously computed embeddings.
-
Field Summary
Fields inherited from class com.redis.vl.extensions.cache.BaseCache
name, prefix, redisClient, ttl -
Constructor Summary
ConstructorsConstructorDescriptionEmbeddingsCache(String name, UnifiedJedis redisClient) Creates a new EmbeddingsCache instance without TTL.EmbeddingsCache(String name, UnifiedJedis redisClient, Integer ttl) Creates a new EmbeddingsCache instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete an embedding for a text.booleanCheck if an embedding exists for a text.Optional<float[]> Retrieve an embedding for a text.voidDelete multiple embeddings in batch.Check existence of multiple embeddings in batch.Retrieve multiple embeddings in batch.voidStore multiple embeddings in batch.voidStore an embedding for a text.voidsetWithTTL(String text, String modelName, float[] embedding, int ttl) Store an embedding with a specific TTL.voidUpdate the TTL for an existing embedding.Methods inherited from class com.redis.vl.extensions.cache.BaseCache
clear, disconnect, expire, finalize, getName, getPrefix, getTtl, isConnected, makeKey, setTtl, setWithTtl, setWithTtl, size
-
Constructor Details
-
EmbeddingsCache
Creates a new EmbeddingsCache instance.- Parameters:
name- The name of the cacheredisClient- The Redis client connectionttl- Default time-to-live in seconds for cache entries (null for no expiration)
-
EmbeddingsCache
Creates a new EmbeddingsCache instance without TTL.- Parameters:
name- The name of the cacheredisClient- The Redis client connection
-
-
Method Details
-
set
Store an embedding for a text.- Parameters:
text- The input textmodelName- The name of the embedding modelembedding- The embedding vector
-
setWithTTL
Store an embedding with a specific TTL.- Parameters:
text- The input textmodelName- The name of the embedding modelembedding- The embedding vectorttl- Time-to-live in seconds
-
get
Retrieve an embedding for a text.- Parameters:
text- The input textmodelName- The name of the embedding model- Returns:
- Optional containing the embedding if found, empty otherwise
-
exists
Check if an embedding exists for a text.- Parameters:
text- The input textmodelName- The name of the embedding model- Returns:
- true if the embedding exists, false otherwise
-
drop
Delete an embedding for a text.- Parameters:
text- The input textmodelName- The name of the embedding model
-
updateTTL
Update the TTL for an existing embedding.- Parameters:
text- The input textmodelName- The name of the embedding modelttl- New time-to-live in seconds
-
mset
Store multiple embeddings in batch.- Parameters:
embeddings- Map of text to embedding vectorsmodelName- The name of the embedding model
-
mget
Retrieve multiple embeddings in batch.- Parameters:
texts- List of input textsmodelName- The name of the embedding model- Returns:
- Map of text to embedding vectors (only includes found embeddings)
-
mexists
Check existence of multiple embeddings in batch.- Parameters:
texts- List of input textsmodelName- The name of the embedding model- Returns:
- Map of text to existence boolean
-
mdrop
Delete multiple embeddings in batch.- Parameters:
texts- List of input textsmodelName- The name of the embedding model
-