{
  "schema_version": 2,
  "id": "develop/ai/redisvl/api/cache",
  "title": "LLM Cache",
  "url": "https://redis.io/docs/latest/develop/ai/redisvl/0.26.0/api/cache/",
  "summary": "",
  "content": "\n\n## SemanticCache\n\n\u003ca id=\"semantic-cache-api\"\u003e\u003c/a\u003e\n\n### `class SemanticCache(name='llmcache', distance_threshold=0.1, ttl=None, vectorizer=None, filterable_fields=None, redis_client=None, redis_url='redis://localhost:6379', connection_kwargs={}, overwrite=False, create_index=True, **kwargs)`\n\nBases: `BaseLLMCache`\n\nSemantic Cache for Large Language Models.\n\nSemantic Cache for Large Language Models.\n\n* **Parameters:**\n  * **name** (*str* *,* *optional*) – The name of the semantic cache search index.\n    Defaults to \"llmcache\".\n  * **distance_threshold** (*float* *,* *optional*) – Semantic distance threshold for the\n    cache in Redis COSINE units [0-2], where lower values indicate stricter\n    matching. Defaults to 0.1.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live for records cached\n    in Redis. Defaults to None.\n  * **vectorizer** (*Optional* *[* *BaseVectorizer* *]* *,* *optional*) – The vectorizer for the cache.\n    Defaults to HFTextVectorizer.\n  * **filterable_fields** (*Optional* *[* *List* *[* *Dict* *[* *str* *,* *Any* *]* *]* *]*) – An optional list of RedisVL fields\n    that can be used to customize cache retrieval with filters.\n  * **redis_client** (*Optional* *[* *Redis* *]* *,* *optional*) – A redis client connection instance.\n    Defaults to None.\n  * **redis_url** (*str* *,* *optional*) – The redis url. Defaults to redis://localhost:6379.\n  * **connection_kwargs** (*Dict* *[* *str* *,* *Any* *]*) – The connection arguments\n    for the redis client. Defaults to empty {}.\n  * **overwrite** (*bool*) – Whether or not to force overwrite the schema for\n    the semantic cache index. Defaults to false.\n  * **create_index** (*bool*) – Whether RedisVL creates and validates the index.\n    When True, the constructor runs `FT.INFO` to check whether the\n    index exists, compares the live schema against this one, and runs\n    `FT.CREATE` if it is absent. When False it does none of these\n    and issues no index command at all: the index must already exist\n    with a compatible schema. A live index whose prefix or storage\n    type differs from this schema is not detected and produces empty\n    results rather than an error. Use this when the index is managed\n    externally, or when the credential cannot run `FT.INFO`. See\n    [Install RedisVL](https://redis.io/docs/latest/../user_guide/installation) for the ACL details. Defaults to\n    true.\n* **Raises:**\n  * **TypeError** – If an invalid vectorizer is provided.\n  * **TypeError** – If the TTL value is not an int.\n  * **ValueError** – If the threshold is not between 0 and 2 (Redis COSINE distance).\n  * **ValueError** – If existing schema does not match new schema and overwrite is False.\n  * **ValueError** – If both create_index is False and overwrite is True.\n\n```python\nfrom redisvl.extensions.cache.llm import SemanticCache\n\n# RedisVL creates the index if it is missing\ncache = SemanticCache(name=\"llmcache\", redis_url=\"redis://localhost:6379\")\n\n# the index is managed externally, or this credential cannot run\n# FT.INFO -- assume the index exists and issue no index command\ncache = SemanticCache(\n    name=\"llmcache\",\n    redis_url=\"redis://localhost:6379\",\n    create_index=False,\n)\n```\n\n#### `async acheck(prompt=None, vector=None, num_results=1, return_fields=None, filter_expression=None, distance_threshold=None)`\n\nAsync check the semantic cache for results similar to the specified prompt\nor vector.\n\nThis method searches the cache using vector similarity with\neither a raw text prompt (converted to a vector) or a provided vector as\ninput. It checks for semantically similar prompts and fetches the cached\nLLM responses.\n\n* **Parameters:**\n  * **prompt** (*Optional* *[* *str* *]* *,* *optional*) – The text prompt to search for in\n    the cache.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]* *,* *optional*) – The vector representation\n    of the prompt to search for in the cache.\n  * **num_results** (*int* *,* *optional*) – The number of cached results to return.\n    Defaults to 1.\n  * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]* *,* *optional*) – The fields to include\n    in each returned result. If None, defaults to all available\n    fields in the cached entry.\n  * **filter_expression** (*Optional* *[*[*FilterExpression*](https://redis.io/docs/latest/filter/#filterexpression) *]*) – Optional filter expression\n    that can be used to filter cache results. Defaults to None and\n    the full cache will be searched.\n  * **distance_threshold** (*Optional* *[* *float* *]*) – The threshold for semantic\n    vector distance.\n* **Returns:**\n  A list of dicts containing the requested\n  : return fields for each similar cached response.\n* **Return type:**\n  List[Dict[str, Any]]\n* **Raises:**\n  * **ValueError** – If neither a prompt nor a vector is specified.\n  * **ValueError** – if ‘vector’ has incorrect dimensions.\n  * **TypeError** – If return_fields is not a list when provided.\n\n```python\nresponse = await cache.acheck(\n    prompt=\"What is the capital city of France?\"\n)\n```\n\n#### `async aclear()`\n\nAsync clear all cache keys when RedisVL manages the index lifecycle.\n\n* **Return type:**\n  None\n\n#### `async adelete()`\n\nAsync delete the cache and its index entirely.\n\n* **Return type:**\n  None\n\n#### `async adisconnect()`\n\nAsynchronously disconnect from Redis and search index.\n\nCloses all Redis connections and index connections.\n\n#### `async adrop(ids=None, keys=None)`\n\nAsync drop specific entries from the cache by ID or Redis key.\n\n* **Parameters:**\n  * **ids** (*Optional* *[* *List* *[* *str* *]* *]*) – List of entry IDs to remove from the cache.\n    Entry IDs are the unique identifiers without the cache prefix.\n  * **keys** (*Optional* *[* *List* *[* *str* *]* *]*) – List of full Redis keys to remove from the cache.\n    Keys are the complete Redis keys including the cache prefix.\n* **Return type:**\n  None\n\n\nAt least one of ids or keys must be provided.\n\n\n* **Raises:**\n  **ValueError** – If neither ids nor keys is provided.\n* **Parameters:**\n  * **ids** (*list* *[* *str* *]*  *|* *None*)\n  * **keys** (*list* *[* *str* *]*  *|* *None*)\n* **Return type:**\n  None\n\n#### `async aexpire(key, ttl=None)`\n\nAsynchronously set or refresh the expiration time for a key in the cache.\n\n* **Parameters:**\n  * **key** (*str*) – The Redis key to set the expiration on.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live in seconds. If None,\n    uses the default TTL configured for this cache instance.\n    Defaults to None.\n* **Return type:**\n  None\n\n\nIf neither the provided TTL nor the default TTL is set (both are None),\nthis method will have no effect.\n\n\n#### `async astore(prompt, response, vector=None, metadata=None, filters=None, ttl=None)`\n\nAsync stores the specified key-value pair in the cache along with metadata.\n\n* **Parameters:**\n  * **prompt** (*str*) – The user prompt to cache.\n  * **response** (*str*) – The LLM response to cache.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]* *,* *optional*) – The prompt vector to\n    cache. Defaults to None, and the prompt vector is generated on\n    demand.\n  * **metadata** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]* *,* *optional*) – The optional metadata to cache\n    alongside the prompt and response. Defaults to None.\n  * **filters** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – The optional tag to assign to the cache entry.\n    Defaults to None.\n  * **ttl** (*Optional* *[* *int* *]*) – The optional TTL override to use on this individual cache\n    entry. Defaults to the global TTL setting.\n* **Returns:**\n  The Redis key for the entries added to the semantic cache.\n* **Return type:**\n  str\n* **Raises:**\n  * **ValueError** – If neither prompt nor vector is specified.\n  * **ValueError** – if vector has incorrect dimensions.\n  * **TypeError** – If provided metadata is not a dictionary.\n\n```python\nkey = await cache.astore(\n    prompt=\"What is the capital city of France?\",\n    response=\"Paris\",\n    metadata={\"city\": \"Paris\", \"country\": \"France\"}\n)\n```\n\n#### `async aupdate(key, **kwargs)`\n\nAsync update specific fields within an existing cache entry. If no fields\nare passed, then only the document TTL is refreshed.\n\n* **Parameters:**\n  **key** (*str*) – the key of the document to update using kwargs.\n* **Raises:**\n  * **ValueError if an incorrect mapping is provided as a kwarg.** – \n  * **TypeError if metadata is provided and not** **of** **type dict.** – \n* **Return type:**\n  None\n\n```python\nkey = await cache.astore('this is a prompt', 'this is a response')\nawait cache.aupdate(\n    key,\n    metadata={\"hit_count\": 1, \"model_name\": \"Llama-2-7b\"}\n)\n```\n\n#### `check(prompt=None, vector=None, num_results=1, return_fields=None, filter_expression=None, distance_threshold=None)`\n\nChecks the semantic cache for results similar to the specified prompt\nor vector.\n\nThis method searches the cache using vector similarity with\neither a raw text prompt (converted to a vector) or a provided vector as\ninput. It checks for semantically similar prompts and fetches the cached\nLLM responses.\n\n* **Parameters:**\n  * **prompt** (*Optional* *[* *str* *]* *,* *optional*) – The text prompt to search for in\n    the cache.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]* *,* *optional*) – The vector representation\n    of the prompt to search for in the cache.\n  * **num_results** (*int* *,* *optional*) – The number of cached results to return.\n    Defaults to 1.\n  * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]* *,* *optional*) – The fields to include\n    in each returned result. If None, defaults to all available\n    fields in the cached entry.\n  * **filter_expression** (*Optional* *[*[*FilterExpression*](https://redis.io/docs/latest/filter/#filterexpression) *]*) – Optional filter expression\n    that can be used to filter cache results. Defaults to None and\n    the full cache will be searched.\n  * **distance_threshold** (*Optional* *[* *float* *]*) – The threshold for semantic\n    vector distance.\n* **Returns:**\n  A list of dicts containing the requested\n  : return fields for each similar cached response.\n* **Return type:**\n  List[Dict[str, Any]]\n* **Raises:**\n  * **ValueError** – If neither a prompt nor a vector is specified.\n  * **ValueError** – if ‘vector’ has incorrect dimensions.\n  * **TypeError** – If return_fields is not a list when provided.\n\n```python\nresponse = cache.check(\n    prompt=\"What is the capital city of France?\"\n)\n```\n\n#### `clear()`\n\nClear all cache keys when RedisVL manages the index lifecycle.\n\n* **Return type:**\n  None\n\n#### `delete()`\n\nDelete the cache and its index entirely.\n\n* **Return type:**\n  None\n\n#### `disconnect()`\n\nDisconnect from Redis and search index.\n\nCloses all Redis connections and index connections.\n\n#### `drop(ids=None, keys=None)`\n\nDrop specific entries from the cache by ID or Redis key.\n\n* **Parameters:**\n  * **ids** (*Optional* *[* *List* *[* *str* *]* *]*) – List of entry IDs to remove from the cache.\n    Entry IDs are the unique identifiers without the cache prefix.\n  * **keys** (*Optional* *[* *List* *[* *str* *]* *]*) – List of full Redis keys to remove from the cache.\n    Keys are the complete Redis keys including the cache prefix.\n* **Return type:**\n  None\n\n\nAt least one of ids or keys must be provided.\n\n\n* **Raises:**\n  **ValueError** – If neither ids nor keys is provided.\n* **Parameters:**\n  * **ids** (*list* *[* *str* *]*  *|* *None*)\n  * **keys** (*list* *[* *str* *]*  *|* *None*)\n* **Return type:**\n  None\n\n#### `expire(key, ttl=None)`\n\nSet or refresh the expiration time for a key in the cache.\n\n* **Parameters:**\n  * **key** (*str*) – The Redis key to set the expiration on.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live in seconds. If None,\n    uses the default TTL configured for this cache instance.\n    Defaults to None.\n* **Return type:**\n  None\n\n\nIf neither the provided TTL nor the default TTL is set (both are None),\nthis method will have no effect.\n\n\n#### `set_threshold(distance_threshold)`\n\nSets the semantic distance threshold for the cache.\n\n* **Parameters:**\n  **distance_threshold** (*float*) – The semantic distance threshold for\n  the cache.\n* **Raises:**\n  **ValueError** – If the threshold is not between 0 and 2 (Redis COSINE distance).\n* **Return type:**\n  None\n\n#### `set_ttl(ttl=None)`\n\nSet the default TTL, in seconds, for entries in the cache.\n\n* **Parameters:**\n  **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The optional time-to-live expiration\n  for the cache, in seconds.\n* **Raises:**\n  **ValueError** – If the time-to-live value is not an integer.\n* **Return type:**\n  None\n\n#### `store(prompt, response, vector=None, metadata=None, filters=None, ttl=None)`\n\nStores the specified key-value pair in the cache along with metadata.\n\n* **Parameters:**\n  * **prompt** (*str*) – The user prompt to cache.\n  * **response** (*str*) – The LLM response to cache.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]* *,* *optional*) – The prompt vector to\n    cache. Defaults to None, and the prompt vector is generated on\n    demand.\n  * **metadata** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]* *,* *optional*) – The optional metadata to cache\n    alongside the prompt and response. Defaults to None.\n  * **filters** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – The optional tag to assign to the cache entry.\n    Defaults to None.\n  * **ttl** (*Optional* *[* *int* *]*) – The optional TTL override to use on this individual cache\n    entry. Defaults to the global TTL setting.\n* **Returns:**\n  The Redis key for the entries added to the semantic cache.\n* **Return type:**\n  str\n* **Raises:**\n  * **ValueError** – If neither prompt nor vector is specified.\n  * **ValueError** – if vector has incorrect dimensions.\n  * **TypeError** – If provided metadata is not a dictionary.\n\n```python\nkey = cache.store(\n    prompt=\"What is the capital city of France?\",\n    response=\"Paris\",\n    metadata={\"city\": \"Paris\", \"country\": \"France\"}\n)\n```\n\n#### `update(key, **kwargs)`\n\nUpdate specific fields within an existing cache entry. If no fields\nare passed, then only the document TTL is refreshed.\n\n* **Parameters:**\n  **key** (*str*) – the key of the document to update using kwargs.\n* **Raises:**\n  * **ValueError if an incorrect mapping is provided as a kwarg.** – \n  * **TypeError if metadata is provided and not** **of** **type dict.** – \n* **Return type:**\n  None\n\n```python\nkey = cache.store('this is a prompt', 'this is a response')\ncache.update(key, metadata={\"hit_count\": 1, \"model_name\": \"Llama-2-7b\"})\n```\n\n#### `property aindex: `[`AsyncSearchIndex`](https://redis.io/docs/latest/searchindex/#asyncsearchindex)`  | None`\n\nThe underlying AsyncSearchIndex for the cache.\n\n* **Returns:**\n  The async search index.\n* **Return type:**\n  [AsyncSearchIndex](https://redis.io/docs/latest/searchindex/#asyncsearchindex)\n\n#### `property distance_threshold: float`\n\nThe semantic distance threshold for the cache.\n\n* **Returns:**\n  The semantic distance threshold.\n* **Return type:**\n  float\n\n#### `property index: `[`SearchIndex`](https://redis.io/docs/latest/searchindex/#searchindex)` `\n\nThe underlying SearchIndex for the cache.\n\n* **Returns:**\n  The search index.\n* **Return type:**\n  [SearchIndex](https://redis.io/docs/latest/searchindex/#searchindex)\n\n#### `property ttl: int | None`\n\nThe default TTL, in seconds, for entries in the cache.\n\n## LangCacheSemanticCache\n\n\u003ca id=\"langcache-semantic-cache-api\"\u003e\u003c/a\u003e\n\n### `class LangCacheSemanticCache(name='langcache', server_url='https://aws-us-east-1.langcache.redis.io', cache_id='', api_key='', ttl=None, use_exact_search=True, use_semantic_search=True, distance_scale='normalized', **kwargs)`\n\nBases: `BaseLLMCache`\n\nLLM Cache implementation using the LangCache managed service.\n\nThis cache uses the LangCache API service for semantic caching of LLM\nresponses. It requires a LangCache account and API key.\n\n### `Example`\n\n```python\nfrom redisvl.extensions.cache.llm import LangCacheSemanticCache\n\ncache = LangCacheSemanticCache(\n    name=\"my_cache\",\n    server_url=\"https://api.langcache.com\",\n    cache_id=\"your-cache-id\",\n    api_key=\"your-api-key\",\n    ttl=3600\n)\n\n# Store a response\ncache.store(\n    prompt=\"What is the capital of France?\",\n    response=\"Paris\"\n)\n\n# Check for cached responses\nresults = cache.check(prompt=\"What is the capital of France?\")\n```\n\nInitialize a LangCache semantic cache.\n\n* **Parameters:**\n  * **name** (*str*) – The name of the cache. Defaults to \"langcache\".\n  * **server_url** (*str*) – The LangCache server URL.\n  * **cache_id** (*str*) – The LangCache cache ID.\n  * **api_key** (*str*) – The LangCache API key.\n  * **ttl** (*Optional* *[* *int* *]*) – Time-to-live for cache entries in seconds.\n  * **use_exact_search** (*bool*) – Whether to use exact matching. Defaults to True.\n  * **use_semantic_search** (*bool*) – Whether to use semantic search. Defaults to True.\n  * **distance_scale** (*str*) – Threshold scale for distance_threshold:\n    - \"normalized\": 0–1 semantic distance (lower is better)\n    - \"redis\": Redis COSINE distance 0–2 (lower is better)\n* **Raises:**\n  * **ImportError** – If the langcache package is not installed.\n  * **ValueError** – If cache_id or api_key is not provided.\n\n#### `async acheck(prompt=None, vector=None, num_results=1, return_fields=None, filter_expression=None, distance_threshold=None, attributes=None)`\n\nAsync check the cache for semantically similar prompts.\n\n* **Parameters:**\n  * **prompt** (*Optional* *[* *str* *]*) – The text prompt to search for.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]*) – Not supported by LangCache API.\n  * **num_results** (*int*) – Number of results to return. Defaults to 1.\n  * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]*) – Not used (for compatibility).\n  * **filter_expression** (*Optional* *[*[*FilterExpression*](https://redis.io/docs/latest/filter/#filterexpression) *]*) – Not supported.\n  * **distance_threshold** (*Optional* *[* *float* *]*) – Maximum distance threshold.\n    Converted to similarity_threshold according to distance_scale:\n    If \"redis\", uses norm_cosine_distance(distance_threshold) ([0,2] -\u003e [0,1]).\n    If \"normalized\", uses (1.0 - distance_threshold) ([0,1] -\u003e [0,1]).\n  * **attributes** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – LangCache attributes to filter by.\n    Note: Attributes must be pre-configured in your LangCache instance.\n* **Returns:**\n  List of matching cache entries.\n* **Return type:**\n  List[Dict[str, Any]]\n* **Raises:**\n  **ValueError** – If prompt is not provided.\n\n#### `async aclear()`\n\nAsync clear the cache of all entries.\n\nThis is an alias for adelete() to match the BaseCache interface.\n\n* **Return type:**\n  None\n\n#### `async adelete()`\n\nAsync delete the entire cache.\n\nThis deletes all entries in the cache by calling the flush API.\n\n* **Return type:**\n  None\n\n#### `async adelete_by_attributes(attributes)`\n\nAsync delete cache entries matching the given attributes.\n\n* **Parameters:**\n  **attributes** (*Dict* *[* *str* *,* *Any* *]*) – Attributes to match for deletion.\n  Cannot be empty.\n* **Returns:**\n  Result of the deletion operation.\n* **Return type:**\n  Dict[str, Any]\n* **Raises:**\n  **ValueError** – If attributes is an empty dictionary.\n\n#### `async adelete_by_id(entry_id)`\n\nAsync delete a single cache entry by ID.\n\n* **Parameters:**\n  **entry_id** (*str*) – The ID of the entry to delete.\n* **Return type:**\n  None\n\n#### `async adisconnect()`\n\nAsync disconnect from Redis.\n\n* **Return type:**\n  None\n\n#### `async aexpire(key, ttl=None)`\n\nAsynchronously set or refresh the expiration time for a key in the cache.\n\n* **Parameters:**\n  * **key** (*str*) – The Redis key to set the expiration on.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live in seconds. If None,\n    uses the default TTL configured for this cache instance.\n    Defaults to None.\n* **Return type:**\n  None\n\n\nIf neither the provided TTL nor the default TTL is set (both are None),\nthis method will have no effect.\n\n\n#### `async astore(prompt, response, vector=None, metadata=None, filters=None, ttl=None)`\n\nAsync store a prompt-response pair in the cache.\n\n* **Parameters:**\n  * **prompt** (*str*) – The user prompt to cache.\n  * **response** (*str*) – The LLM response to cache.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]*) – Not supported by LangCache API.\n  * **metadata** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Optional metadata (stored as attributes).\n  * **filters** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Not supported.\n  * **ttl** (*Optional* *[* *int* *]*) – Optional TTL override in seconds.\n* **Returns:**\n  The entry ID for the cached entry.\n* **Return type:**\n  str\n* **Raises:**\n  **ValueError** – If prompt or response is empty.\n\n#### `async aupdate(key, **kwargs)`\n\nAsync update specific fields within an existing cache entry.\n\nNote: LangCache API does not support updating individual entries.\nThis method will raise NotImplementedError.\n\n* **Parameters:**\n  * **key** (*str*) – The key of the document to update.\n  * **\\*\\*kwargs** – Field-value pairs to update.\n* **Raises:**\n  **NotImplementedError** – LangCache does not support entry updates.\n* **Return type:**\n  None\n\n#### `check(prompt=None, vector=None, num_results=1, return_fields=None, filter_expression=None, distance_threshold=None, attributes=None)`\n\nCheck the cache for semantically similar prompts.\n\n* **Parameters:**\n  * **prompt** (*Optional* *[* *str* *]*) – The text prompt to search for.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]*) – Not supported by LangCache API.\n  * **num_results** (*int*) – Number of results to return. Defaults to 1.\n  * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]*) – Not used (for compatibility).\n  * **filter_expression** (*Optional* *[*[*FilterExpression*](https://redis.io/docs/latest/filter/#filterexpression) *]*) – Not supported.\n  * **distance_threshold** (*Optional* *[* *float* *]*) – Maximum distance threshold.\n    Converted to similarity_threshold according to distance_scale:\n    If \"redis\", uses norm_cosine_distance(distance_threshold) ([0,2] -\u003e [0,1]).\n    If \"normalized\", uses (1.0 - distance_threshold) ([0,1] -\u003e [0,1]).\n  * **attributes** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – LangCache attributes to filter by.\n    Note: Attributes must be pre-configured in your LangCache instance.\n* **Returns:**\n  List of matching cache entries.\n* **Return type:**\n  List[Dict[str, Any]]\n* **Raises:**\n  **ValueError** – If prompt is not provided.\n\n#### `clear()`\n\nClear the cache of all entries.\n\nThis is an alias for delete() to match the BaseCache interface.\n\n* **Return type:**\n  None\n\n#### `delete()`\n\nDelete the entire cache.\n\nThis deletes all entries in the cache by calling the flush API.\n\n* **Return type:**\n  None\n\n#### `delete_by_attributes(attributes)`\n\nDelete cache entries matching the given attributes.\n\n* **Parameters:**\n  **attributes** (*Dict* *[* *str* *,* *Any* *]*) – Attributes to match for deletion.\n  Cannot be empty.\n* **Returns:**\n  Result of the deletion operation.\n* **Return type:**\n  Dict[str, Any]\n* **Raises:**\n  **ValueError** – If attributes is an empty dictionary.\n\n#### `delete_by_id(entry_id)`\n\nDelete a single cache entry by ID.\n\n* **Parameters:**\n  **entry_id** (*str*) – The ID of the entry to delete.\n* **Return type:**\n  None\n\n#### `disconnect()`\n\nDisconnect from Redis.\n\n* **Return type:**\n  None\n\n#### `expire(key, ttl=None)`\n\nSet or refresh the expiration time for a key in the cache.\n\n* **Parameters:**\n  * **key** (*str*) – The Redis key to set the expiration on.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live in seconds. If None,\n    uses the default TTL configured for this cache instance.\n    Defaults to None.\n* **Return type:**\n  None\n\n\nIf neither the provided TTL nor the default TTL is set (both are None),\nthis method will have no effect.\n\n\n#### `set_ttl(ttl=None)`\n\nSet the default TTL, in seconds, for entries in the cache.\n\n* **Parameters:**\n  **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The optional time-to-live expiration\n  for the cache, in seconds.\n* **Raises:**\n  **ValueError** – If the time-to-live value is not an integer.\n* **Return type:**\n  None\n\n#### `store(prompt, response, vector=None, metadata=None, filters=None, ttl=None)`\n\nStore a prompt-response pair in the cache.\n\n* **Parameters:**\n  * **prompt** (*str*) – The user prompt to cache.\n  * **response** (*str*) – The LLM response to cache.\n  * **vector** (*Optional* *[* *List* *[* *float* *]* *]*) – Not supported by LangCache API.\n  * **metadata** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Optional metadata (stored as attributes).\n  * **filters** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Not supported.\n  * **ttl** (*Optional* *[* *int* *]*) – Optional TTL override in seconds.\n* **Returns:**\n  The entry ID for the cached entry.\n* **Return type:**\n  str\n* **Raises:**\n  **ValueError** – If prompt or response is empty.\n\n#### `update(key, **kwargs)`\n\nUpdate specific fields within an existing cache entry.\n\nNote: LangCache API does not support updating individual entries.\nThis method will raise NotImplementedError.\n\n* **Parameters:**\n  * **key** (*str*) – The key of the document to update.\n  * **\\*\\*kwargs** – Field-value pairs to update.\n* **Raises:**\n  **NotImplementedError** – LangCache does not support entry updates.\n* **Return type:**\n  None\n\n#### `property ttl: int | None`\n\nThe default TTL, in seconds, for entries in the cache.\n\n## Cache Schema Classes\n\n### `CacheEntry`\n\n\u003ca id=\"cache-entry-api\"\u003e\u003c/a\u003e\n\n### `class CacheEntry(*, entry_id=None, prompt, response, prompt_vector, inserted_at=\u003cfactory\u003e, updated_at=\u003cfactory\u003e, metadata=None, filters=None)`\n\nBases: `BaseModel`\n\nA single cache entry in Redis\n\nCreate a new model by parsing and validating input data from keyword arguments.\n\nRaises [ValidationError][pydantic_core.ValidationError] if the input data cannot be\nvalidated to form a valid model.\n\nself is explicitly positional-only to allow self as a field name.\n\n* **Parameters:**\n  * **entry_id** (*str* *|* *None*)\n  * **prompt** (*str*)\n  * **response** (*str*)\n  * **prompt_vector** (*list* *[* *float* *]*)\n  * **inserted_at** (*float*)\n  * **updated_at** (*float*)\n  * **metadata** (*dict* *[* *str* *,* *Any* *]*  *|* *None*)\n  * **filters** (*dict* *[* *str* *,* *Any* *]*  *|* *None*)\n\n#### `entry_id: str | None`\n\nCache entry identifier\n\n#### `filters: dict[str, Any] | None`\n\nOptional filter data stored on the cache entry for customizing retrieval\n\n#### `inserted_at: float`\n\nTimestamp of when the entry was added to the cache\n\n#### `metadata: dict[str, Any] | None`\n\nOptional metadata stored on the cache entry\n\n#### `model_config: ClassVar[ConfigDict] = {}`\n\nConfiguration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].\n\n#### `prompt: str`\n\nInput prompt or question cached in Redis\n\n#### `prompt_vector: list[float]`\n\nText embedding representation of the prompt\n\n#### `response: str`\n\nResponse or answer to the question, cached in Redis\n\n#### `updated_at: float`\n\nTimestamp of when the entry was updated in the cache\n\n### `CacheHit`\n\n\u003ca id=\"cache-hit-api\"\u003e\u003c/a\u003e\n\n### `class CacheHit(*, entry_id, prompt, response, vector_distance, inserted_at, updated_at, metadata=None, filters=None, **extra_data)`\n\nBases: `BaseModel`\n\nA cache hit based on some input query\n\nCreate a new model by parsing and validating input data from keyword arguments.\n\nRaises [ValidationError][pydantic_core.ValidationError] if the input data cannot be\nvalidated to form a valid model.\n\nself is explicitly positional-only to allow self as a field name.\n\n* **Parameters:**\n  * **entry_id** (*str*)\n  * **prompt** (*str*)\n  * **response** (*str*)\n  * **vector_distance** (*float*)\n  * **inserted_at** (*float*)\n  * **updated_at** (*float*)\n  * **metadata** (*dict* *[* *str* *,* *Any* *]*  *|* *None*)\n  * **filters** (*dict* *[* *str* *,* *Any* *]*  *|* *None*)\n  * **extra_data** (*Any*)\n\n#### `to_dict()`\n\nConvert this model to a dictionary, merging filters into the result.\n\n* **Return type:**\n  dict[str, *Any*]\n\n#### `entry_id: str`\n\nCache entry identifier\n\n#### `filters: dict[str, Any] | None`\n\nOptional filter data stored on the cache entry for customizing retrieval\n\n#### `inserted_at: float`\n\nTimestamp of when the entry was added to the cache\n\n#### `metadata: dict[str, Any] | None`\n\nOptional metadata stored on the cache entry\n\n#### `model_config: ClassVar[ConfigDict] = {'extra': 'allow'}`\n\nConfiguration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].\n\n#### `prompt: str`\n\nInput prompt or question cached in Redis\n\n#### `response: str`\n\nResponse or answer to the question, cached in Redis\n\n#### `updated_at: float`\n\nTimestamp of when the entry was updated in the cache\n\n#### `vector_distance: float`\n\nThe semantic distance between the query vector and the stored prompt vector\n\n# Embeddings Cache\n\n## EmbeddingsCache\n\n\u003ca id=\"embeddings-cache-api\"\u003e\u003c/a\u003e\n\n### `class EmbeddingsCache(name='embedcache', ttl=None, redis_client=None, async_redis_client=None, redis_url='redis://localhost:6379', connection_kwargs={})`\n\nBases: `BaseCache`\n\nEmbeddings Cache for storing embedding vectors with exact key matching.\n\nInitialize an embeddings cache.\n\n* **Parameters:**\n  * **name** (*str*) – The name of the cache. Defaults to \"embedcache\".\n  * **ttl** (*Optional* *[* *int* *]*) – The time-to-live for cached embeddings. Defaults to None.\n  * **redis_client** (*Optional* *[* *SyncRedisClient* *]*) – Redis client instance. Defaults to None.\n  * **redis_url** (*str*) – Redis URL for connection. Defaults to \"redis://localhost:6379\".\n  * **connection_kwargs** (*Dict* *[* *str* *,* *Any* *]*) – Redis connection arguments. Defaults to {}.\n  * **async_redis_client** (*Redis* *|* *RedisCluster* *|* *None*)\n* **Raises:**\n  **ValueError** – If vector dimensions are invalid\n\n```python\ncache = EmbeddingsCache(\n    name=\"my_embeddings_cache\",\n    ttl=3600,  # 1 hour\n    redis_url=\"redis://localhost:6379\"\n)\n```\n\n#### `async aclear()`\n\nAsync clear the cache of all keys.\n\n* **Return type:**\n  None\n\n#### `async adisconnect()`\n\nAsync disconnect from Redis.\n\n* **Return type:**\n  None\n\n#### `async adrop(content, model_name)`\n\nAsync remove an embedding from the cache.\n\nAsynchronously removes an embedding from the cache.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Return type:**\n  None\n\n```python\nawait cache.adrop(\n    content=\"What is machine learning?\",\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `async adrop_by_key(key)`\n\nAsync remove an embedding from the cache by its Redis key.\n\nAsynchronously removes an embedding from the cache by its Redis key.\n\n* **Parameters:**\n  **key** (*str*) – The full Redis key for the embedding.\n* **Return type:**\n  None\n\n```python\nawait cache.adrop_by_key(\"embedcache:1234567890abcdef\")\n```\n\n#### `async aexists(content, model_name)`\n\nAsync check if an embedding exists.\n\nAsynchronously checks if an embedding exists for the given content and model.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  True if the embedding exists in the cache, False otherwise.\n* **Return type:**\n  bool\n\n```python\nif await cache.aexists(\"What is machine learning?\", \"text-embedding-ada-002\"):\n    print(\"Embedding is in cache\")\n```\n\n#### `async aexists_by_key(key)`\n\nAsync check if an embedding exists for the given Redis key.\n\nAsynchronously checks if an embedding exists for the given Redis key.\n\n* **Parameters:**\n  **key** (*str*) – The full Redis key for the embedding.\n* **Returns:**\n  True if the embedding exists in the cache, False otherwise.\n* **Return type:**\n  bool\n\n```python\nif await cache.aexists_by_key(\"embedcache:1234567890abcdef\"):\n    print(\"Embedding is in cache\")\n```\n\n#### `async aexpire(key, ttl=None)`\n\nAsynchronously set or refresh the expiration time for a key in the cache.\n\n* **Parameters:**\n  * **key** (*str*) – The Redis key to set the expiration on.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live in seconds. If None,\n    uses the default TTL configured for this cache instance.\n    Defaults to None.\n* **Return type:**\n  None\n\n\nIf neither the provided TTL nor the default TTL is set (both are None),\nthis method will have no effect.\n\n\n#### `async aget(content, model_name)`\n\nAsync get embedding by content and model name.\n\nAsynchronously retrieves a cached embedding for the given content and model name.\nIf found, refreshes the TTL of the entry.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  Embedding cache entry or None if not found.\n* **Return type:**\n  Optional[Dict[str, Any]]\n\n```python\nembedding_data = await cache.aget(\n    content=\"What is machine learning?\",\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `async aget_by_key(key)`\n\nAsync get embedding by its full Redis key.\n\nAsynchronously retrieves a cached embedding for the given Redis key.\nIf found, refreshes the TTL of the entry.\n\n* **Parameters:**\n  **key** (*str*) – The full Redis key for the embedding.\n* **Returns:**\n  Embedding cache entry or None if not found.\n* **Return type:**\n  Optional[Dict[str, Any]]\n\n```python\nembedding_data = await cache.aget_by_key(\"embedcache:1234567890abcdef\")\n```\n\n#### `async amdrop(contents, model_name)`\n\nAsync remove multiple embeddings from the cache by their contents and model name.\n\nAsynchronously removes multiple embeddings in a single operation.\n\n* **Parameters:**\n  * **contents** (*Iterable* *[* *bytes* *|* *str* *]*) – Iterable of content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Return type:**\n  None\n\n```python\n# Remove multiple embeddings asynchronously\nawait cache.amdrop(\n    contents=[\"What is machine learning?\", \"What is deep learning?\"],\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `async amdrop_by_keys(keys)`\n\nAsync remove multiple embeddings from the cache by their Redis keys.\n\nAsynchronously removes multiple embeddings in a single operation.\n\n* **Parameters:**\n  **keys** (*List* *[* *str* *]*) – List of Redis keys to remove.\n* **Return type:**\n  None\n\n```python\n# Remove multiple embeddings asynchronously\nawait cache.amdrop_by_keys([\"embedcache:key1\", \"embedcache:key2\"])\n```\n\n#### `async amexists(contents, model_name)`\n\nAsync check if multiple embeddings exist by their contents and model name.\n\nAsynchronously checks existence of multiple embeddings in a single operation.\n\n* **Parameters:**\n  * **contents** (*Iterable* *[* *bytes* *|* *str* *]*) – Iterable of content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  List of boolean values indicating whether each embedding exists.\n* **Return type:**\n  List[bool]\n\n```python\n# Check if multiple embeddings exist asynchronously\nexists_results = await cache.amexists(\n    contents=[\"What is machine learning?\", \"What is deep learning?\"],\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `async amexists_by_keys(keys)`\n\nAsync check if multiple embeddings exist by their Redis keys.\n\nAsynchronously checks existence of multiple keys in a single operation.\n\n* **Parameters:**\n  **keys** (*List* *[* *str* *]*) – List of Redis keys to check.\n* **Returns:**\n  List of boolean values indicating whether each key exists.\n  The order matches the input keys order.\n* **Return type:**\n  List[bool]\n\n```python\n# Check if multiple keys exist asynchronously\nexists_results = await cache.amexists_by_keys([\"embedcache:key1\", \"embedcache:key2\"])\n```\n\n#### `async amget(contents, model_name)`\n\nAsync get multiple embeddings by their contents and model name.\n\nAsynchronously retrieves multiple cached embeddings in a single operation.\nIf found, refreshes the TTL of each entry.\n\n* **Parameters:**\n  * **contents** (*Iterable* *[* *bytes* *|* *str* *]*) – Iterable of content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  List of embedding cache entries or None for contents not found.\n* **Return type:**\n  List[Optional[Dict[str, Any]]]\n\n```python\n# Get multiple embeddings asynchronously\nembedding_data = await cache.amget(\n    contents=[\"What is machine learning?\", \"What is deep learning?\"],\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `async amget_by_keys(keys)`\n\nAsync get multiple embeddings by their Redis keys.\n\nAsynchronously retrieves multiple cached embeddings in a single network roundtrip.\nIf found, refreshes the TTL of each entry.\n\n* **Parameters:**\n  **keys** (*List* *[* *str* *]*) – List of Redis keys to retrieve.\n* **Returns:**\n  List of embedding cache entries or None for keys not found.\n  The order matches the input keys order.\n* **Return type:**\n  List[Optional[Dict[str, Any]]]\n\n```python\n# Get multiple embeddings asynchronously\nembedding_data = await cache.amget_by_keys([\n    \"embedcache:key1\",\n    \"embedcache:key2\"\n])\n```\n\n#### `async amset(items, ttl=None)`\n\nAsync store multiple embeddings in a batch operation.\n\nEach item in the input list should be a dictionary with the following fields:\n- ‘content’: The content that was embedded\n- ‘model_name’: The name of the embedding model\n- ‘embedding’: The embedding vector\n- ‘metadata’: Optional metadata to store with the embedding\n\n* **Parameters:**\n  * **items** (*list* *[* *dict* *[* *str* *,* *Any* *]* *]*) – List of dictionaries, each containing content, model_name, embedding, and optional metadata.\n  * **ttl** (*int* *|* *None*) – Optional TTL override for these entries.\n* **Returns:**\n  List of Redis keys where the embeddings were stored.\n* **Return type:**\n  List[str]\n\n```python\n# Store multiple embeddings asynchronously\nkeys = await cache.amset([\n    {\n        \"content\": \"What is ML?\",\n        \"model_name\": \"text-embedding-ada-002\",\n        \"embedding\": [0.1, 0.2, 0.3],\n        \"metadata\": {\"source\": \"user\"}\n    },\n    {\n        \"content\": \"What is AI?\",\n        \"model_name\": \"text-embedding-ada-002\",\n        \"embedding\": [0.4, 0.5, 0.6],\n        \"metadata\": {\"source\": \"docs\"}\n    }\n])\n```\n\n#### `async aset(content, model_name, embedding, metadata=None, ttl=None)`\n\nAsync store an embedding with its content and model name.\n\nAsynchronously stores an embedding with its content and model name.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n  * **embedding** (*List* *[* *float* *]*) – The embedding vector to store.\n  * **metadata** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Optional metadata to store with the embedding.\n  * **ttl** (*Optional* *[* *int* *]*) – Optional TTL override for this specific entry.\n* **Returns:**\n  The Redis key where the embedding was stored.\n* **Return type:**\n  str\n\n```python\nkey = await cache.aset(\n    content=\"What is machine learning?\",\n    model_name=\"text-embedding-ada-002\",\n    embedding=[0.1, 0.2, 0.3, ...],\n    metadata={\"source\": \"user_query\"}\n)\n```\n\n#### `clear()`\n\nClear the cache of all keys.\n\n* **Return type:**\n  None\n\n#### `disconnect()`\n\nDisconnect from Redis.\n\n* **Return type:**\n  None\n\n#### `drop(content, model_name)`\n\nRemove an embedding from the cache.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Return type:**\n  None\n\n```python\ncache.drop(\n    content=\"What is machine learning?\",\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `drop_by_key(key)`\n\nRemove an embedding from the cache by its Redis key.\n\n* **Parameters:**\n  **key** (*str*) – The full Redis key for the embedding.\n* **Return type:**\n  None\n\n```python\ncache.drop_by_key(\"embedcache:1234567890abcdef\")\n```\n\n#### `exists(content, model_name)`\n\nCheck if an embedding exists for the given content and model.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  True if the embedding exists in the cache, False otherwise.\n* **Return type:**\n  bool\n\n```python\nif cache.exists(\"What is machine learning?\", \"text-embedding-ada-002\"):\n    print(\"Embedding is in cache\")\n```\n\n#### `exists_by_key(key)`\n\nCheck if an embedding exists for the given Redis key.\n\n* **Parameters:**\n  **key** (*str*) – The full Redis key for the embedding.\n* **Returns:**\n  True if the embedding exists in the cache, False otherwise.\n* **Return type:**\n  bool\n\n```python\nif cache.exists_by_key(\"embedcache:1234567890abcdef\"):\n    print(\"Embedding is in cache\")\n```\n\n#### `expire(key, ttl=None)`\n\nSet or refresh the expiration time for a key in the cache.\n\n* **Parameters:**\n  * **key** (*str*) – The Redis key to set the expiration on.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The time-to-live in seconds. If None,\n    uses the default TTL configured for this cache instance.\n    Defaults to None.\n* **Return type:**\n  None\n\n\nIf neither the provided TTL nor the default TTL is set (both are None),\nthis method will have no effect.\n\n\n#### `get(content, model_name)`\n\nGet embedding by content and model name.\n\nRetrieves a cached embedding for the given content and model name.\nIf found, refreshes the TTL of the entry.\n\n* **Parameters:**\n  * **content** (*bytes* *|* *str*) – The content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  Embedding cache entry or None if not found.\n* **Return type:**\n  Optional[Dict[str, Any]]\n\n```python\nembedding_data = cache.get(\n    content=\"What is machine learning?\",\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `get_by_key(key)`\n\nGet embedding by its full Redis key.\n\nRetrieves a cached embedding for the given Redis key.\nIf found, refreshes the TTL of the entry.\n\n* **Parameters:**\n  **key** (*str*) – The full Redis key for the embedding.\n* **Returns:**\n  Embedding cache entry or None if not found.\n* **Return type:**\n  Optional[Dict[str, Any]]\n\n```python\nembedding_data = cache.get_by_key(\"embedcache:1234567890abcdef\")\n```\n\n#### `mdrop(contents, model_name)`\n\nRemove multiple embeddings from the cache by their contents and model name.\n\nEfficiently removes multiple embeddings in a single operation.\n\n* **Parameters:**\n  * **contents** (*Iterable* *[* *bytes* *|* *str* *]*) – Iterable of content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Return type:**\n  None\n\n```python\n# Remove multiple embeddings\ncache.mdrop(\n    contents=[\"What is machine learning?\", \"What is deep learning?\"],\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `mdrop_by_keys(keys)`\n\nRemove multiple embeddings from the cache by their Redis keys.\n\nEfficiently removes multiple embeddings in a single operation.\n\n* **Parameters:**\n  **keys** (*List* *[* *str* *]*) – List of Redis keys to remove.\n* **Return type:**\n  None\n\n```python\n# Remove multiple embeddings\ncache.mdrop_by_keys([\"embedcache:key1\", \"embedcache:key2\"])\n```\n\n#### `mexists(contents, model_name)`\n\nCheck if multiple embeddings exist by their contents and model name.\n\nEfficiently checks existence of multiple embeddings in a single operation.\n\n* **Parameters:**\n  * **contents** (*Iterable* *[* *bytes* *|* *str* *]*) – Iterable of content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  List of boolean values indicating whether each embedding exists.\n* **Return type:**\n  List[bool]\n\n```python\n# Check if multiple embeddings exist\nexists_results = cache.mexists(\n    contents=[\"What is machine learning?\", \"What is deep learning?\"],\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `mexists_by_keys(keys)`\n\nCheck if multiple embeddings exist by their Redis keys.\n\nEfficiently checks existence of multiple keys in a single operation.\n\n* **Parameters:**\n  **keys** (*List* *[* *str* *]*) – List of Redis keys to check.\n* **Returns:**\n  List of boolean values indicating whether each key exists.\n  The order matches the input keys order.\n* **Return type:**\n  List[bool]\n\n```python\n# Check if multiple keys exist\nexists_results = cache.mexists_by_keys([\"embedcache:key1\", \"embedcache:key2\"])\n```\n\n#### `mget(contents, model_name)`\n\nGet multiple embeddings by their content and model name.\n\nEfficiently retrieves multiple cached embeddings in a single operation.\nIf found, refreshes the TTL of each entry.\n\n* **Parameters:**\n  * **contents** (*Iterable* *[* *bytes* *|* *str* *]*) – Iterable of content that was embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n* **Returns:**\n  List of embedding cache entries or None for contents not found.\n* **Return type:**\n  List[Optional[Dict[str, Any]]]\n\n```python\n# Get multiple embeddings\nembedding_data = cache.mget(\n    contents=[\"What is machine learning?\", \"What is deep learning?\"],\n    model_name=\"text-embedding-ada-002\"\n)\n```\n\n#### `mget_by_keys(keys)`\n\nGet multiple embeddings by their Redis keys.\n\nEfficiently retrieves multiple cached embeddings in a single network roundtrip.\nIf found, refreshes the TTL of each entry.\n\n* **Parameters:**\n  **keys** (*List* *[* *str* *]*) – List of Redis keys to retrieve.\n* **Returns:**\n  List of embedding cache entries or None for keys not found.\n  The order matches the input keys order.\n* **Return type:**\n  List[Optional[Dict[str, Any]]]\n\n```python\n# Get multiple embeddings\nembedding_data = cache.mget_by_keys([\n    \"embedcache:key1\",\n    \"embedcache:key2\"\n])\n```\n\n#### `mset(items, ttl=None)`\n\nStore multiple embeddings in a batch operation.\n\nEach item in the input list should be a dictionary with the following fields:\n- ‘content’: The input that was embedded\n- ‘model_name’: The name of the embedding model\n- ‘embedding’: The embedding vector\n- ‘metadata’: Optional metadata to store with the embedding\n\n* **Parameters:**\n  * **items** (*list* *[* *dict* *[* *str* *,* *Any* *]* *]*) – List of dictionaries, each containing content, model_name, embedding, and optional metadata.\n  * **ttl** (*int* *|* *None*) – Optional TTL override for these entries.\n* **Returns:**\n  List of Redis keys where the embeddings were stored.\n* **Return type:**\n  List[str]\n\n```python\n# Store multiple embeddings\nkeys = cache.mset([\n    {\n        \"content\": \"What is ML?\",\n        \"model_name\": \"text-embedding-ada-002\",\n        \"embedding\": [0.1, 0.2, 0.3],\n        \"metadata\": {\"source\": \"user\"}\n    },\n    {\n        \"content\": \"What is AI?\",\n        \"model_name\": \"text-embedding-ada-002\",\n        \"embedding\": [0.4, 0.5, 0.6],\n        \"metadata\": {\"source\": \"docs\"}\n    }\n])\n```\n\n#### `set(content, model_name, embedding, metadata=None, ttl=None)`\n\nStore an embedding with its content and model name.\n\n* **Parameters:**\n  * **content** (*Union* *[* *bytes* *,* *str* *]*) – The content to be embedded.\n  * **model_name** (*str*) – The name of the embedding model.\n  * **embedding** (*List* *[* *float* *]*) – The embedding vector to store.\n  * **metadata** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Optional metadata to store with the embedding.\n  * **ttl** (*Optional* *[* *int* *]*) – Optional TTL override for this specific entry.\n* **Returns:**\n  The Redis key where the embedding was stored.\n* **Return type:**\n  str\n\n```python\nkey = cache.set(\n    content=\"What is machine learning?\",\n    model_name=\"text-embedding-ada-002\",\n    embedding=[0.1, 0.2, 0.3, ...],\n    metadata={\"source\": \"user_query\"}\n)\n```\n\n#### `set_ttl(ttl=None)`\n\nSet the default TTL, in seconds, for entries in the cache.\n\n* **Parameters:**\n  **ttl** (*Optional* *[* *int* *]* *,* *optional*) – The optional time-to-live expiration\n  for the cache, in seconds.\n* **Raises:**\n  **ValueError** – If the time-to-live value is not an integer.\n* **Return type:**\n  None\n\n#### `property ttl: int | None`\n\nThe default TTL, in seconds, for entries in the cache.\n",
  "tags": [],
  "last_updated": "2026-09-03T16:12:40+02:00"
}
