Skip to main content

AstraDBByteStore

This will help you get started with Astra DB key-value stores. For detailed documentation of all AstraDBByteStore features and configurations head to the API reference.

Overviewโ€‹

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

Integration detailsโ€‹

ClassPackageLocalJS supportPackage downloadsPackage latest
AstraDBByteStorelangchain_astradbโŒโŒPyPI - DownloadsPyPI - Version

Setupโ€‹

To create an AstraDBByteStore byte store, you'll need to create a DataStax account.

Credentialsโ€‹

After signing up, set the following credentials:

from getpass import getpass

ASTRA_DB_API_ENDPOINT = getpass("ASTRA_DB_API_ENDPOINT = ")
ASTRA_DB_APPLICATION_TOKEN = getpass("ASTRA_DB_APPLICATION_TOKEN = ")

Installationโ€‹

The LangChain AstraDB integration lives in the langchain_astradb package:

%pip install -qU langchain_astradb

Instantiationโ€‹

Now we can instantiate our byte store:

from langchain_astradb import AstraDBByteStore

kv_store = AstraDBByteStore(
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
collection_name="my_store",
)

Usageโ€‹

You can set data under keys like this using the mset method:

kv_store.mset(
[
["key1", b"value1"],
["key2", b"value2"],
]
)

kv_store.mget(
[
"key1",
"key2",
]
)
[b'value1', b'value2']

And you can delete data using the mdelete method:

kv_store.mdelete(
[
"key1",
"key2",
]
)

kv_store.mget(
[
"key1",
"key2",
]
)
[None, None]

You can use an AstraDBByteStore anywhere you'd use other ByteStores, including as a cache for embeddings.

API referenceโ€‹

For detailed documentation of all AstraDBByteStore features and configurations, head to the API reference: https://python.langchain.com/api_reference/astradb/storage/langchain_astradb.storage.AstraDBByteStore.html


Was this page helpful?


You can also leave detailed feedback on GitHub.