Astra DB
This page lists the integrations available with Astra DB and Apache Cassandra®.
Setup
Install the following Python package:
pip install "astrapy>=0.5.3"
Astra DB
DataStax Astra DB is a serverless vector-capable database built on Cassandra and made conveniently available through an easy-to-use JSON API.
Vector Store
from langchain.vectorstores import AstraDB
vector_store = AstraDB(
embedding=my_embedding,
collection_name="my_store",
api_endpoint="...",
token="...",
)
Learn more in the example notebook.
LLM Cache
from langchain.globals import set_llm_cache
from langchain.cache import AstraDBCache
set_llm_cache(AstraDBCache(
api_endpoint="...",
token="...",
))
Learn more in the example notebook (scroll to the Astra DB section).
Semantic LLM Cache
from langchain.globals import set_llm_cache
from langchain.cache import AstraDBSemanticCache
set_llm_cache(AstraDBSemanticCache(
embedding=my_embedding,
api_endpoint="...",
token="...",
))
Learn more in the example notebook (scroll to the appropriate section).
Chat message history
from langchain.memory import AstraDBChatMessageHistory
message_history = AstraDBChatMessageHistory(
session_id="test-session"
api_endpoint="...",
token="...",
)
Learn more in the example notebook.
Apache Cassandra and Astra DB through CQL
Cassandra is a NoSQL, row-oriented, highly scalable and highly available database. Starting with version 5.0, the database ships with vector search capabilities. DataStax Astra DB through CQL is a managed serverless database built on Cassandra, offering the same interface and strengths.
These databases use the CQL protocol (Cassandra Query Language). Hence, a different set of connectors, outlined below, shall be used.
Vector Store
from langchain.vectorstores import Cassandra
vector_store = Cassandra(
embedding=my_embedding,
table_name="my_store",
)
Learn more in the example notebook (scroll down to the CQL-specific section).
Memory
from langchain.memory import CassandraChatMessageHistory
message_history = CassandraChatMessageHistory(session_id="my-session")
Learn more in the example notebook.
LLM Cache
from langchain.cache import CassandraCache
langchain.llm_cache = CassandraCache()
Learn more in the example notebook (scroll to the Cassandra section).
Semantic LLM Cache
from langchain.cache import CassandraSemanticCache
cassSemanticCache = CassandraSemanticCache(
embedding=my_embedding,
table_name="my_store",
)
Learn more in the example notebook (scroll to the appropriate section).