> ## 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.

# 存储集成

> 使用 LangChain JavaScript 集成存储。

## 概述

LangChain 提供了一个键值存储接口，用于通过键存储和检索数据。LangChain 中的键值存储接口主要用于缓存 [嵌入](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/embeddings.md)。

## 接口

所有 [`BaseStores`](https://reference.langchain.com/javascript/langchain-core/stores/BaseStore) 都是 **通用** 的，并支持以下接口，其中 `K` 表示键类型，`V` 表示值类型：

* `mget(keys: K[]): Promise<(V | undefined)[]>`: 获取多个键的值，如果键不存在则返回 `undefined`
* `mset(keyValuePairs: [K, V][]): Promise<void>`: 设置多个键的值
* `mdelete(keys: K[]): Promise<void>`: 删除多个键
* `yieldKeys(prefix?: string): AsyncGenerator<K | string>`: 异步生成存储中的所有键，可选择按前缀过滤

接口的通用性允许你使用不同的键和值类型。例如，`BaseStore<string, BaseMessage>` 会用字符串键存储消息，而 `BaseStore<string, number[]>` 会存储数字数组。

> [!NOTE]
>
> 基础存储设计为一次处理 **多个** 键值对以提高效率。这可以节省网络往返次数，并可能允许在底层存储中进行更高效的批量操作。

## 本地开发的自带存储

> [card] [InMemoryStore](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/stores/in_memory.md)

> [card] [LocalFileStore](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/stores/file_system.md)

## 自定义存储

你也可以通过扩展 @\[`BaseStore`] 类来实现自己的自定义存储。有关更多详细信息，请参阅 [存储接口文档](https://reference.langchain.com/javascript/langchain-core/stores/BaseStore)。

## 所有键值存储

| 集成 | 下载 |
| :- | :- |
| [`AlBuddyMemoryStore`](https://github.com/flytomoon/al-buddy-memory/blob/main/docs/integrations/langchain.md) | [  ![Downloads per month](https://img.shields.io/npm/dm/al-buddy-memory?style=flat-square\&label=%20&)](https://www.npmjs.com/package/al-buddy-memory) |
| [`InMemoryStore`](https://langchain-docs-zh.mintlify.site/langchain/oss/javascript/integrations/stores/in_memory) | N/A |
| [`LocalFileStore`](https://langchain-docs-zh.mintlify.site/langchain/oss/javascript/integrations/stores/file_system) | N/A |

***

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


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