跳到主要内容
本指南将帮助您开始使用内存中的键值存储。有关所有 InMemoryByteStore 功能和配置的详细文档,请参阅API 参考

概览

InMemoryByteStoreByteStore 的非持久化实现,它将所有内容存储在 Python 字典中。它适用于演示和不需要在 Python 进程生命周期之外进行持久化的场景。

集成详情

类别本地JS 支持下载量版本
InMemoryByteStorelangchain-corePyPI - DownloadsPyPI - Version

安装

LangChain InMemoryByteStore 集成位于 langchain-core 包中。
pip install -qU langchain-core

实例化

现在您可以实例化您的字节存储了。
from langchain_core.stores import InMemoryByteStore

kv_store = InMemoryByteStore()

用法

您可以使用 mset 方法在键下设置数据,如下所示。
kv_store.mset(
    [
        ["key1", b"value1"],
        ["key2", b"value2"],
    ]
)

kv_store.mget(
    [
        "key1",
        "key2",
    ]
)
[b'value1', b'value2']
您可以使用 mdelete 方法删除数据。
kv_store.mdelete(
    [
        "key1",
        "key2",
    ]
)

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

API 参考

有关所有 InMemoryByteStore 功能和配置的详细文档,请参阅 API 参考:python.langchain.com/api_reference/core/stores/langchain_core.stores.InMemoryByteStore.html
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.