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

# (MODULE_NAME) 集成

> 使用 LangChain Python 与 (MODULE_NAME) 向量存储集成。

***

如何使用这个 Python 向量存储模板：

* [ ] 将 (MODULE\_NAME) 替换为模块名称，例如 Anthropic、OpenAI 等（`command + F` 对此很有帮助）
* [ ] 更新链接以指向正确的模块
* [ ] 如有必要，更新 PyPI/registry 包名称
* [ ] 如有必要，更新 API 密钥环境变量名称

模板从本行下方开始...

本指南提供了快速入门 (MODULE\_NAME) [向量存储](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/vectorstores.md#概述) 的概述。有关 (MODULE\_NAME)VectorStore 的所有功能、参数和配置的详细列表，请访问 [(MODULE\_NAME)VectorStore API 参考](LINK)。

## 设置

要访问 (MODULE\_NAME) 向量存储，您需要创建一个 (MODULE\_NAME) 账户，获取一个 API 密钥，并安装 `langchain-(MODULE_NAME)` 集成包。

### 凭证

```python Set API key icon="key" theme={null}
import getpass
import os

if "(MODULE_NAME)_API_KEY" not in os.environ:
    os.environ["(MODULE_NAME)_API_KEY"] = getpass.getpass("Enter your (MODULE_NAME) API key: ")
```

要启用模型调用的自动 跟踪 (Log each step of a model's execution to debug and improve it)，请设置您的 [LangSmith](https://docs.langchain.com/langsmith/observability) API 密钥：

```python Enable tracing icon="flask" theme={null}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### 安装

LangChain (MODULE\_NAME) 集成位于 `langchain-(MODULE_NAME)` 包中：

```python pip theme={null}
pip install -U langchain-(MODULE_NAME)
```

```python uv theme={null}
uv add langchain-(MODULE_NAME)
```

***

## 实例化

现在我们可以实例化我们的模型对象并生成响应：

```python Initialize vector store icon="database" theme={null}
from langchain_(MODULE_NAME).vectorstores import (MODULE_NAME)VectorStore

vector_store = (MODULE_NAME)VectorStore(embeddings=embeddings)
```

***

## 管理向量存储

### 添加项

```python Add documents icon="folder-plus" theme={null}
from langchain_core.documents import Document

document_1 = Document(page_content="foo", metadata={"source": "https://example.com"})
document_2 = Document(page_content="bar", metadata={"source": "https://example.com"})
document_3 = Document(page_content="baz", metadata={"source": "https://example.com"})
documents = [document_1, document_2, document_3]

vector_store.add_documents(documents=documents, ids=["1", "2", "3"])
```

### 更新项

```python Update document by ID icon="pencil" theme={null}
updated_document = Document(
    page_content="qux", metadata={"source": "https://another-example.com"}
)

vector_store.update_documents(document_id="1", document=updated_document)
```

### 删除项

```python Delete documents by IDs icon="trash" theme={null}
vector_store.delete(ids=["3"])
```

***

## 查询向量存储

一旦您的向量存储创建完成，并且相关的文档已添加，您很可能希望在链或智能体运行期间查询它。

### 直接查询

执行简单的相似度搜索可以按如下方式完成：

```python Similarity search icon="folders" theme={null}
results = vector_store.similarity_search(
    query="thud", k=1, filter={"source": "https://another-example.com"}
)
for doc in results:
    print(f"* {doc.page_content} [{doc.metadata}]")
```

如果您想执行相似度搜索并接收相应的分数，可以运行：

```python Similarity search with scores icon="star-half" theme={null}
results = vector_store.similarity_search_with_score(
    query="thud", k=1, filter={"source": "https://example.com"}
)
for doc, score in results:
    print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
```

### 转换为检索器

您还可以将向量存储转换为检索器，以便在您的链中更轻松地使用。

```python Create retriever icon="robot" theme={null}
retriever = vector_store.as_retriever(search_type="mmr", search_kwargs={"k": 1})
retriever.invoke("thud")
```

***

## 用于检索增强生成

> [card] [(MODULE\_NAME) 向量存储 RAG 指南](https://langchain-docs-zh.mintlify.site/langchain/oss/deepagents/rag.md)
>
> 如何使用此向量存储进行检索增强生成 (RAG) 的指南

***

## TODO：此向量存储的特定功能

如果不相关，请删除。

参考现有向量存储文档，例如 [Qdrant](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/vectorstores/qdrant.md)：

示例：

* &#x20;距离函数
* &#x20;相关性
* &#x20;过滤
* &#x20;外部存储选项
* &#x20;索引
* &#x20;合并

***

## API 参考

有关 (MODULE\_NAME)VectorStore 的所有功能和配置的详细文档，请访问 [API 参考](LINK)。

***

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


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