Class EmbeddingsCache

java.lang.Object
com.redis.vl.extensions.cache.BaseCache
com.redis.vl.extensions.cache.EmbeddingsCache

public class EmbeddingsCache extends BaseCache
Cache for storing and retrieving text embeddings.

This cache stores exact embeddings for text inputs, allowing retrieval of previously computed embeddings.

  • Constructor Details

    • EmbeddingsCache

      public EmbeddingsCache(String name, UnifiedJedis redisClient, Integer ttl)
      Creates a new EmbeddingsCache instance.
      Parameters:
      name - The name of the cache
      redisClient - The Redis client connection
      ttl - Default time-to-live in seconds for cache entries (null for no expiration)
    • EmbeddingsCache

      public EmbeddingsCache(String name, UnifiedJedis redisClient)
      Creates a new EmbeddingsCache instance without TTL.
      Parameters:
      name - The name of the cache
      redisClient - The Redis client connection
  • Method Details

    • set

      public void set(String text, String modelName, float[] embedding)
      Store an embedding for a text.
      Parameters:
      text - The input text
      modelName - The name of the embedding model
      embedding - The embedding vector
    • setWithTTL

      public void setWithTTL(String text, String modelName, float[] embedding, int ttl)
      Store an embedding with a specific TTL.
      Parameters:
      text - The input text
      modelName - The name of the embedding model
      embedding - The embedding vector
      ttl - Time-to-live in seconds
    • get

      public Optional<float[]> get(String text, String modelName)
      Retrieve an embedding for a text.
      Parameters:
      text - The input text
      modelName - The name of the embedding model
      Returns:
      Optional containing the embedding if found, empty otherwise
    • exists

      public boolean exists(String text, String modelName)
      Check if an embedding exists for a text.
      Parameters:
      text - The input text
      modelName - The name of the embedding model
      Returns:
      true if the embedding exists, false otherwise
    • drop

      public void drop(String text, String modelName)
      Delete an embedding for a text.
      Parameters:
      text - The input text
      modelName - The name of the embedding model
    • updateTTL

      public void updateTTL(String text, String modelName, int ttl)
      Update the TTL for an existing embedding.
      Parameters:
      text - The input text
      modelName - The name of the embedding model
      ttl - New time-to-live in seconds
    • mset

      public void mset(Map<String,float[]> embeddings, String modelName)
      Store multiple embeddings in batch.
      Parameters:
      embeddings - Map of text to embedding vectors
      modelName - The name of the embedding model
    • mget

      public Map<String,float[]> mget(List<String> texts, String modelName)
      Retrieve multiple embeddings in batch.
      Parameters:
      texts - List of input texts
      modelName - The name of the embedding model
      Returns:
      Map of text to embedding vectors (only includes found embeddings)
    • mexists

      public Map<String,Boolean> mexists(List<String> texts, String modelName)
      Check existence of multiple embeddings in batch.
      Parameters:
      texts - List of input texts
      modelName - The name of the embedding model
      Returns:
      Map of text to existence boolean
    • mdrop

      public void mdrop(List<String> texts, String modelName)
      Delete multiple embeddings in batch.
      Parameters:
      texts - List of input texts
      modelName - The name of the embedding model