> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AstraDBByteStore 集成

> 使用 LangChain Python 集成 AstraDBByteStore 存储。

这将帮助您开始使用 Astra DB [键值存储](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/stores.md)。有关所有 `AstraDBByteStore` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/python/langchain-astradb/storage/AstraDBByteStore)。

## 概述

> [DataStax Astra DB](https://docs.datastax.com/en/astra-db-serverless/index.html) 是一个无服务器的、AI 就绪的数据库，基于 `Apache Cassandra®` 构建，并通过易于使用的 JSON API 方便地提供。

### 集成细节

| 类 | 包 | 本地 | JS 支持 | 下载 | 版本 |
| :- | :- | :-: | :-: | :-: | :-: |
| [`AstraDBByteStore`](https://reference.langchain.com/python/langchain-astradb/storage/AstraDBByteStore) | [`langchain-astradb`](https://reference.langchain.com/python/langchain-astradb) | ❌ | ❌ | ![PyPI - 下载](https://img.shields.io/pypi/dm/langchain_astradb?style=flat-square\&label=%20) | ![PyPI - 版本](https://img.shields.io/pypi/v/langchain_astradb?style=flat-square\&label=%20) |

## 设置

要创建一个 `AstraDBByteStore` 字节存储，您需要 [创建一个 DataStax 账户](https://www.datastax.com/products/datastax-astra)。

### 凭证

注册后，设置以下凭证：

```python theme={null}
from getpass import getpass

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

### 安装

LangChain AstraDB 集成存在于 `langchain-astradb` 包中：

```python theme={null}
pip install -qU langchain-astradb
```

## 实例化

现在我们可以实例化我们的字节存储：

```python theme={null}
from langchain_astradb import AstraDBByteStore

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

## 使用

您可以使用 `mset` 方法像这样在键下设置数据：

```python theme={null}
kv_store.mset(
    [
        ["key1", b"value1"],
        ["key2", b"value2"],
    ]
)

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

```text theme={null}
[b'value1', b'value2']
```

您可以使用 `mdelete` 方法像这样删除数据：

```python theme={null}
kv_store.mdelete(
    [
        "key1",
        "key2",
    ]
)

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

```text theme={null}
[None, None]
```

您可以在任何您使用其他 ByteStores 的地方使用 `AstraDBByteStore`。

***

## API 参考

有关所有 `AstraDBByteStore` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/python/langchain-astradb/storage/AstraDBByteStore)

***

> 官方原文：[src/oss/python/integrations/stores/astradb.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/stores/astradb.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.