CassandraCache(
self,
session: Optional[CassandraSession] = None,
keyspace: Optional[| Name | Type | Description |
|---|---|---|
session | Optional[CassandraSession] | Default: Nonean open Cassandra session. Leave unspecified to use the global cassio init (see below) |
keyspace | Optional[str] | Default: Nonethe keyspace to use for storing the cache. Leave unspecified to use the global cassio init (see below) |
table_name | str | Default: CASSANDRA_CACHE_DEFAULT_TABLE_NAME |
ttl_seconds | Optional[int] | Default: CASSANDRA_CACHE_DEFAULT_TTL_SECONDS |
setup_mode | CassandraSetupMode | Default: CassandraSetupMode.SYNC |
Cache that uses Cassandra / Astra DB as a backend.
Example:
.. code-block:: python
import cassio
from langchain_community.cache import CassandraCache
from langchain_core.globals import set_llm_cache
cassio.init(auto=True) # Requires env. variables, see CassIO docs
set_llm_cache(CassandraCache())
It uses a single Cassandra table. The lookup keys (which get to form the primary key) are: - prompt, a string - llm_string, a deterministic str representation of the model parameters. (needed to prevent same-prompt-different-model collisions)
Note:
The session and keyspace parameters, when left out (or passed as None), fall back to the globally-available cassio settings if any are available. In other words, if a previously-run 'cassio.init(...)' has been executed previously anywhere in the code, Cassandra-based objects need not specify the connection parameters at all.
name of the Cassandra table to use as cache
time-to-live for cache entries (default: None, i.e. forever)
a value in langchain_community.utilities.cassandra.SetupMode. Choose between SYNC, ASYNC and OFF - the latter if the Cassandra table is guaranteed to exist already, for a faster initialization.