Skip to main content

Astra DB

DataStax Astra DB is a serverless vector-capable database built on Apache Cassandra® and made conveniently available through an easy-to-use JSON API.

Setup

Install the following Python package:

pip install "astrapy>=0.7.1"

Vector Store

from langchain_astradb import AstraDBVectorStore
vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint="...",
token="...",
)

Learn more in the example notebook.

Chat message history

from langchain_astradb import AstraDBChatMessageHistory
message_history = AstraDBChatMessageHistory(
session_id="test-session",
api_endpoint="...",
token="...",
)

LLM Cache

from langchain.globals import set_llm_cache
from langchain_community.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_community.cache import AstraDBSemanticCache
set_llm_cache(AstraDBSemanticCache(
embedding=my_embedding,
api_endpoint="...",
token="...",
))

Learn more in the example notebook (scroll to the appropriate section).

Learn more in the example notebook.

Document loader

from langchain_community.document_loaders import AstraDBLoader
loader = AstraDBLoader(
collection_name="my_collection",
api_endpoint="...",
token="..."
)

Learn more in the example notebook.

Self-querying retriever

from langchain_astradb import AstraDBVectorStore
from langchain.retrievers.self_query.base import SelfQueryRetriever

vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint="...",
token="...",
)

retriever = SelfQueryRetriever.from_llm(
my_llm,
vector_store,
document_content_description,
metadata_field_info
)

Learn more in the example notebook.

Store

from langchain_astradb import AstraDBStore
store = AstraDBStore(
collection_name="my_kv_store",
api_endpoint="...",
token="..."
)

Learn more in the example notebook.

Byte Store

from langchain_astradb import AstraDBByteStore
store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint="...",
token="..."
)

Learn more in the example notebook.