Node Details

  • Name: redisEmbeddingsCache
  • Type: RedisEmbeddingsCache
  • Category: [[Cache]]
  • Version: 1.0

Parameters

  1. Embeddings (Required)

    • Type: Embeddings
    • Description: The embedding model to be used for generating embeddings.
  2. Credential (Optional)

    • Type: credential
    • Credential Names: redisCacheApi, redisCacheUrlApi
    • Description: The credentials required to connect to the Redis server.
  3. Time to Live (ms) (Optional)

    • Type: number
    • Name: ttl
    • Description: The time-to-live for cached embeddings in milliseconds.
    • Default: 3600000 (1 hour)
    • Step: 10
    • Additional Params: true
  4. Namespace (Optional)

    • Type: string
    • Description: A unique identifier for the cache, useful for organizing different caches.
    • Additional Params: true

Input

The node doesn’t require direct input from the user. It integrates into the embedding generation flow automatically.

Output

The node returns a CacheBackedEmbeddings object, which wraps the original embedding model with Redis-based caching functionality.

How It Works

  1. The node initializes a connection to the Redis server using the provided credentials.
  2. When an embedding request is made:
    • The cache checks if an identical request has been processed before.
    • If found, it returns the cached embedding immediately.
    • If not found, the embedding is generated using the provided embedding model, stored in the Redis cache, and then returned.
  3. The cache uses a combination of the input text and namespace (if provided) to create unique cache keys.
  4. If a TTL is specified, cached embeddings will expire after the set duration.

Use Cases

  • Improving response times for applications that frequently generate embeddings
  • Reducing API costs by minimizing redundant embedding generation calls
  • Enhancing performance in scenarios with repetitive text inputs or similar queries
  • Optimizing vector search operations by caching frequently used embeddings
  • Sharing cached embeddings across multiple processes or servers

Special Features

  • Distributed Caching: Utilizes Redis for cross-instance caching of embeddings.
  • Configurable TTL: Supports setting Time-To-Live for cached embeddings.
  • Namespace Support: Allows for organization of multiple caches within the same Redis instance.
  • Flexible Connection: Supports both direct Redis configuration and URL-based connection.
  • SSL Support: Offers secure connections to Redis servers.
  • LangChain Integration: Built on top of LangChain’s CacheBackedEmbeddings for reliability and consistency.

Notes

  • Requires access to a Redis server, either self-hosted or cloud-based.
  • The cache persists across application restarts, ensuring continuity of cached embeddings.
  • This caching mechanism is particularly useful for scenarios where the same or similar texts are likely to be embedded multiple times across different sessions or application instances.
  • While improving performance, it’s important to consider Redis memory usage, especially for large numbers of unique embeddings.
  • The effectiveness of the cache depends on the nature of the embedding requests and the likelihood of repetition across different users or sessions.
  • Supports both standalone Redis setups and clustered environments.

The Redis Embeddings Cache node provides a powerful solution for optimizing embedding-based applications in distributed environments. By leveraging Redis’s fast in-memory data store, it offers efficient caching capabilities that can significantly enhance both the performance and cost-effectiveness of systems that rely heavily on embeddings. This node is particularly valuable in applications where quick embedding generation is crucial across multiple instances or where similar texts are likely to be processed multiple times from different users or sessions.