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

# 存储集成

> 使用 LangChain JavaScript 与存储系统集成。

## 概述

LangChain 提供了一个键值存储接口，用于按键存储和检索数据。LangChain 中的键值存储接口主要用于缓存[嵌入向量](/oss/javascript/integrations/embeddings)。

## 接口

所有 [`BaseStore`](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>
  基础存储设计为一次处理**多个**键值对以提高效率。这可以减少网络往返次数，并可能在底层存储中实现更高效的批量操作。
</Note>

## 用于本地开发的内置存储

<Columns cols={2}>
  <Card title="InMemoryStore" icon="link" href="/oss/javascript/integrations/stores/in_memory" arrow="true" cta="查看指南" />

  <Card title="LocalFileStore" icon="link" href="/oss/javascript/integrations/stores/file_system" arrow="true" cta="查看指南" />
</Columns>

## 自定义存储

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

## 所有集成

<Columns cols={3}>
  <Card title="Cassandra KV" icon="link" href="/oss/javascript/integrations/stores/cassandra_storage" arrow="true" cta="查看指南" />

  <Card title="IORedis" icon="link" href="/oss/javascript/integrations/stores/ioredis_storage" arrow="true" cta="查看指南" />

  <Card title="Upstash Redis" icon="link" href="/oss/javascript/integrations/stores/upstash_redis_storage" arrow="true" cta="查看指南" />

  <Card title="Vercel KV" icon="link" href="/oss/javascript/integrations/stores/vercel_kv_storage" arrow="true" cta="查看指南" />
</Columns>

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\javascript\integrations\stores\index.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
