|
|
|
|
|
> [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). |
|
|
|
|
|
|
|
Install the following Python package: |
|
```bash |
|
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: |
|
|
|
```python |
|
ASTRA_DB_APPLICATION_TOKEN="TOKEN" |
|
ASTRA_DB_API_ENDPOINT="API_ENDPOINT" |
|
``` |
|
|
|
|
|
|
|
```python |
|
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, |
|
) |
|
``` |
|
|
|
Learn more in the [example notebook](/docs/integrations/vectorstores/astradb). |
|
|
|
See the [example provided by DataStax](https://docs.datastax.com/en/astra/astra-db-vector/integrations/langchain.html). |
|
|
|
|
|
|
|
```python |
|
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](/docs/integrations/memory/astradb_chat_message_history |
|
|
|
|
|
|
|
```python |
|
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, |
|
)) |
|
``` |
|
|
|
Learn more in the [example notebook](/docs/integrations/llm_caching |
|
|
|
|
|
|
|
|
|
```python |
|
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](/docs/integrations/llm_caching |
|
|
|
Learn more in the [example notebook](/docs/integrations/memory/astradb_chat_message_history). |
|
|
|
|
|
|
|
```python |
|
from langchain_astradb import AstraDBLoader |
|
|
|
loader = AstraDBLoader( |
|
collection_name="my_collection", |
|
api_endpoint=ASTRA_DB_API_ENDPOINT, |
|
token=ASTRA_DB_APPLICATION_TOKEN, |
|
) |
|
``` |
|
|
|
Learn more in the [example notebook](/docs/integrations/document_loaders/astradb). |
|
|
|
|
|
|
|
```python |
|
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](/docs/integrations/retrievers/self_query/astradb). |
|
|
|
|
|
|
|
```python |
|
from langchain_astradb import AstraDBStore |
|
|
|
store = AstraDBStore( |
|
collection_name="my_kv_store", |
|
api_endpoint=ASTRA_DB_API_ENDPOINT, |
|
token=ASTRA_DB_APPLICATION_TOKEN, |
|
) |
|
``` |
|
|
|
Learn more in the [example notebook](/docs/integrations/stores/astradb |
|
|
|
|
|
|
|
```python |
|
from langchain_astradb import AstraDBByteStore |
|
|
|
store = AstraDBByteStore( |
|
collection_name="my_kv_store", |
|
api_endpoint=ASTRA_DB_API_ENDPOINT, |
|
token=ASTRA_DB_APPLICATION_TOKEN, |
|
) |
|
``` |
|
|
|
Learn more in the [example notebook](/docs/integrations/stores/astradb |
|
|