langchain_community.cache.AstraDBCache¶
class langchain_community.cache.AstraDBCache(*, collection_name: str = 'langchain_astradb_cache', token: Optional[str] = None, api_endpoint: Optional[str] = None, astra_db_client: Optional[Any] = None, namespace: Optional[str] = None)[source]¶
Cache that uses Astra DB as a backend.
It uses a single collection as a kv store
The lookup keys, combined in the _id of the documents, are:
prompt, a string
llm_string, a deterministic str representation of the model parameters.
(needed to prevent same-prompt-different-model collisions)
Create an AstraDB cache using a collection for storage.
Args (only keyword-arguments accepted):collection_name (str): name of the Astra DB collection to create/use.
token (Optional[str]): API token for Astra DB usage.
api_endpoint (Optional[str]): full URL to the API endpoint,
such as “https://<DB-ID>-us-east1.apps.astra.datastax.com”.
astra_db_client (Optional[Any]): alternative to token+api_endpoint,you can pass an already-created ‘astrapy.db.AstraDB’ instance.
namespace (Optional[str]): namespace (aka keyspace) where thecollection is created. Defaults to the database’s “default namespace”.
Methods
__init__(*[, collection_name, token, ...])
Create an AstraDB cache using a collection for storage.
clear(**kwargs)
Clear cache.
delete(prompt, llm_string)
Evict from cache if there's an entry.
delete_through_llm(prompt, llm[, stop])
A wrapper around delete with the LLM being passed.
lookup(prompt, llm_string)
Look up based on prompt and llm_string.