## Astra DB

> [DataStax Astra DB](https://docs.datastax.com/en/astra/home/astra.html) 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](https://docs.datastax.com/en/astra/astra-db-vector/tutorials/chatbot.html).

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

Install the following Python package:

```
pip install "langchain-astradb>=0.1.0"
```

Get the [connection secrets](https://docs.datastax.com/en/astra/astra-db-vector/get-started/quickstart.html). Set up the following environment variables:

```
ASTRA_DB_APPLICATION_TOKEN="TOKEN"ASTRA_DB_API_ENDPOINT="API_ENDPOINT"
```

## Vector Store[​](#vector-store "Direct link to Vector Store")

```
from langchain_astradb import AstraDBVectorStorevector_store = AstraDBVectorStore(    embedding=my_embedding,    collection_name="my_store",    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,)
```

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/vectorstores/astradb/).

See the [example provided by DataStax](https://docs.datastax.com/en/astra/astra-db-vector/integrations/langchain.html).

## Chat message history[​](#chat-message-history "Direct link to Chat message history")

```
from langchain_astradb import AstraDBChatMessageHistorymessage_history = AstraDBChatMessageHistory(    session_id="test-session",    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,)
```

See the [usage example](https://python.langchain.com/docs/integrations/memory/astradb_chat_message_history/#example).

## LLM Cache[​](#llm-cache "Direct link to LLM Cache")

```
from langchain.globals import set_llm_cachefrom langchain_astradb import AstraDBCacheset_llm_cache(AstraDBCache(    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,))
```

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/llms/llm_caching/#astra-db-caches) (scroll to the Astra DB section).

## Semantic LLM Cache[​](#semantic-llm-cache "Direct link to Semantic LLM Cache")

```
from langchain.globals import set_llm_cachefrom langchain_astradb import AstraDBSemanticCacheset_llm_cache(AstraDBSemanticCache(    embedding=my_embedding,    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,))
```

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/llms/llm_caching/#astra-db-caches) (scroll to the appropriate section).

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/memory/astradb_chat_message_history/).

## Document loader[​](#document-loader "Direct link to Document loader")

```
from langchain_astradb import AstraDBLoaderloader = AstraDBLoader(    collection_name="my_collection",    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,)
```

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/document_loaders/astradb/).

## Self-querying retriever[​](#self-querying-retriever "Direct link to Self-querying retriever")

```
from langchain_astradb import AstraDBVectorStorefrom langchain.retrievers.self_query.base import SelfQueryRetrievervector_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](https://python.langchain.com/docs/integrations/retrievers/self_query/astradb/).

## Store[​](#store "Direct link to Store")

```
from langchain_astradb import AstraDBStorestore = AstraDBStore(    collection_name="my_kv_store",    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,)
```

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/stores/astradb/#astradbstore).

## Byte Store[​](#byte-store "Direct link to Byte Store")

```
from langchain_astradb import AstraDBByteStorestore = AstraDBByteStore(    collection_name="my_kv_store",    api_endpoint=ASTRA_DB_API_ENDPOINT,    token=ASTRA_DB_APPLICATION_TOKEN,)
```

Learn more in the [example notebook](https://python.langchain.com/docs/integrations/stores/astradb/#astradbbytestore).