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.

See a tutorial provided by DataStax.

Installation and Setupโ€‹

Install the following Python package:

pip install "langchain-astradb>=0.1.0"

Get the connection secrets. Set up the following environment variables:

ASTRA_DB_APPLICATION_TOKEN="TOKEN"
ASTRA_DB_API_ENDPOINT="API_ENDPOINT"

Vector Storeโ€‹

from langchain_astradb import AstraDBVectorStore

vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API Reference:AstraDBVectorStore

Learn more in the example notebook.

See the example provided by DataStax.

Chat message historyโ€‹

from langchain_astradb import AstraDBChatMessageHistory

message_history = AstraDBChatMessageHistory(
session_id="test-session",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)

See the usage example.

LLM Cacheโ€‹

from langchain.globals import set_llm_cache
from langchain_astradb import AstraDBCache

set_llm_cache(AstraDBCache(
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
))
API Reference:set_llm_cache | AstraDBCache

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

Semantic LLM Cacheโ€‹

from langchain.globals import set_llm_cache
from langchain_astradb import AstraDBSemanticCache

set_llm_cache(AstraDBSemanticCache(
embedding=my_embedding,
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
))

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

Learn more in the example notebook.

Document loaderโ€‹

from langchain_astradb import AstraDBLoader

loader = AstraDBLoader(
collection_name="my_collection",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API Reference:AstraDBLoader

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=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_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=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API Reference:AstraDBStore

Learn more in the example notebook.

Byte Storeโ€‹

from langchain_astradb import AstraDBByteStore

store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API Reference:AstraDBByteStore

Learn more in the example notebook.


Was this page helpful?


You can leave detailed feedback on GitHub.