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 the

collection 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.

update(prompt,Ā llm_string,Ā return_val)

Update cache based on prompt and llm_string.

__init__(*, 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]Ā¶

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 the

collection is created. Defaults to the databaseā€™s ā€œdefault namespaceā€.

clear(**kwargs: Any) None[source]Ā¶

Clear cache. This is for all LLMs at once.

delete(prompt: str, llm_string: str) None[source]Ā¶

Evict from cache if thereā€™s an entry.

delete_through_llm(prompt: str, llm: LLM, stop: Optional[List[str]] = None) None[source]Ā¶

A wrapper around delete with the LLM being passed. In case the llm(prompt) calls have a stop param, you should pass it here

lookup(prompt: str, llm_string: str) Optional[Sequence[Generation]][source]Ā¶

Look up based on prompt and llm_string.

update(prompt: str, llm_string: str, return_val: Sequence[Generation]) None[source]Ā¶

Update cache based on prompt and llm_string.