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

# Aerospike 集成

> 使用 LangChain Python 将 Aerospike 与 LangGraph 检查点保存和存储持久化集成。

> [Aerospike](https://aerospike.com/) 是一款高性能、分布式的 NoSQL 数据库，专为大规模实时应用设计。它提供亚毫秒级延迟、强一致性以及跨集群的自动数据分发，非常适合需要快速、可靠状态持久化的 AI 工作负载。

Aerospike 具有无共享架构、线性水平扩展、混合内存架构（DRAM 索引配合 SSD/NVMe 数据存储）、每个命名空间可调的强一致性或宽松一致性、内置 TTL（自动记录过期）、主动-主动跨数据中心复制，以及对键值、文档、图和向量数据的多模型支持。

Aerospike LangGraph 集成提供了一个用于持久化图执行状态的检查点保存器，以及一个用于长期代理数据（如用户配置文件、提取的实体和缓存的工具输出）的存储。

## 开始使用

该实现可在 [aerospike-community/aerospike-langgraph](https://github.com/aerospike-community/aerospike-langgraph) 仓库中找到。它包括一个基于 Docker 的 Aerospike 设置、`AerospikeSaver` 和 `AerospikeStore` 的参考实现，以及用于测试检查点恢复、TTL 行为和命名空间范围存储访问的基本测试。

要尝试它，请启动一个 Aerospike 容器，在 LangGraph 应用中配置保存器和存储，然后运行包含的示例以观察执行恢复和代理状态持久化。

## 安装

安装两个包：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -U langgraph-store-aerospike langgraph-checkpoint-aerospike
```

## 在本地运行 Aerospike

使用 Aerospike Docker 镜像启动 Aerospike：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docker run -d --name aerospike \
  -p 3000-3002:3000-3002 \
  container.aerospike.com/aerospike/aerospike-server
```

## 配置

存储和检查点保存器使用相同的 Aerospike 连接设置：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export AEROSPIKE_HOST=127.0.0.1
export AEROSPIKE_PORT=3000
```

## LangGraph 检查点保存器

Aerospike 检查点保存器持久化 LangGraph 执行状态，并支持从任何检查点恢复。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import aerospike
from langgraph.checkpoint.aerospike import AerospikeSaver

client = aerospike.client(
    {"hosts": [("127.0.0.1", 3000)]}
).connect()

saver = AerospikeSaver(
    client=client,
    namespace="langgraph",
)

compiled = graph.compile(checkpointer=saver)

compiled.invoke(
    {"input": "hello"},
    config={
        "configurable": {
            "thread_id": "demo-thread"
        }
    }
)
```

## LangGraph 存储

Aerospike 存储用于长期代理数据，例如用户配置文件、提取的实体和缓存的工具输出。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import aerospike
from langgraph.store.aerospike import AerospikeStore
from langgraph.store.base import PutOp, GetOp, SearchOp

client = aerospike.client(
    {"hosts": [("127.0.0.1", 3000)]}
).connect()

store = AerospikeStore(
    client=client,
    namespace="langgraph",
    set="store",
)

# 写入数据
store.put(
    namespace=("users", "profiles"),
    key="user_123",
    value={"name": "Alice", "age": 30},
)

# 读取数据
item = store.get(
    namespace=("users", "profiles"),
    key="user_123",
)
print(item.value)

# 批量操作
results = store.batch([
    PutOp(namespace=("documents",), key="doc1", value={"status": "draft"}),
    GetOp(namespace=("documents",), key="doc1"),
])

# 在命名空间内搜索
search_results = store.search(
    namespace_prefix=("documents",),
    filter={"status": {"$eq": "draft"}},
    limit=10,
)

# 删除数据
store.delete(namespace=("users", "profiles"), key="user_123")
```

## 资源

* [PyPI 上的 langgraph-checkpoint-aerospike](https://pypi.org/project/langgraph-checkpoint-aerospike/)
* [PyPI 上的 langgraph-store-aerospike](https://pypi.org/project/langgraph-store-aerospike/)
* [GitHub 上的 aerospike-community/aerospike-langgraph](https://github.com/aerospike-community/aerospike-langgraph)
* [Aerospike 文档](https://aerospike.com/docs/)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/providers/aerospike.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
