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

# Moorcheh 集成

> 使用最大信息二值化 (MIB) 和信息理论分数 (ITS) 的闪电般快速的语义搜索引擎和向量存储

# Moorcheh

[Moorcheh](https://www.moorcheh.ai/) 是一款闪电般快速的语义搜索引擎和向量存储。与使用简单的距离度量（如 L2 或余弦相似度）不同，Moorcheh 使用最大信息二值化 (MIB) 和信息理论分数 (ITS) 来检索准确的文档块。

以下教程将指导您使用 Moorcheh 和 LangChain 上传和存储文本文档及向量嵌入，并为您的所有查询检索相关块。

## 设置

首先，安装必要的包：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install langchain-moorcheh
```

## 初始化

开始使用 Moorcheh

1. 在 [Moorcheh 控制台](https://console.moorcheh.ai/) 注册或登录。
2. 转到“API 密钥”选项卡并生成 API 密钥。
3. 将密钥保存为名为 `MOORCHEH_API_KEY` 的环境变量（您将在下面使用它）。
4. 要为存储数据创建命名空间：
   * 在控制台中，打开“命名空间”选项卡并点击“创建命名空间”；或者
   * 使用下一节中的向量存储代码进行编程初始化。
5. 使用您的 API 密钥创建命名空间、上传文档并检索答案。

有关 Moorcheh SDK 函数的更多信息，请参阅 [GitHub 仓库](https://github.com/moorcheh-ai/moorcheh-python-sdk)。

## 导入包

导入以下包：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_moorcheh import MoorchehVectorStore
from moorcheh_sdk import MoorchehClient

import logging
import os
from uuid import uuid4
import asyncio
from typing import Any, List, Optional, Literal, Tuple, Type, TypeVar, Sequence
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.vectorstores import VectorStore
from google.colab import userdata
```

## 代码设置

在环境变量中设置您的 Moorcheh API 密钥：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
MOORCHEH_API_KEY = os.environ['MOORCHEH_API_KEY']
```

设置您的命名空间名称、类型，并创建向量存储：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
namespace = "your_namespace_name"
namespace_type = "text" # or vector
store = MoorchehVectorStore(
            api_key=MOORCHEH_API_KEY,
            namespace=namespace,
            namespace_type=namespace_type
        )
```

## 添加文档

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
document_1 = Document(
    page_content="Brewed a fresh cup of Ethiopian coffee and paired it with a warm croissant.",
    metadata={"source": "blog"},
)

document_2 = Document(
    page_content="Tomorrow's weather will be sunny with light winds, reaching a high of 78°F.",
    metadata={"source": "news"},
)

document_3 = Document(
    page_content="Experimenting with LangChain for an AI-powered note-taking assistant!",
    metadata={"source": "tweet"},
)

document_4 = Document(
    page_content="Local bakery donates 500 loaves of bread to the community food bank.",
    metadata={"source": "news"},
)

document_5 = Document(
    page_content="That concert last night was absolutely unforgettable—what a performance!",
    metadata={"source": "tweet"},
)

document_6 = Document(
    page_content="Check out our latest article: 5 ways to boost productivity while working from home.",
    metadata={"source": "website"},
)

document_7 = Document(
    page_content="The ultimate guide to mastering homemade pizza dough.",
    metadata={"source": "website"},
)

document_8 = Document(
    page_content="LangGraph just made multi-agent workflows way easier—seriously impressive!",
    metadata={"source": "tweet"},
)

document_9 = Document(
    page_content="Oil prices rose 3% today after unexpected supply cuts from major exporters.",
    metadata={"source": "news"},
)

document_10 = Document(
    page_content="I really hope this post doesn't vanish into the digital void…",
    metadata={"source": "tweet"},
)

documents = [
    document_1,
    document_2,
    document_3,
    document_4,
    document_5,
    document_6,
    document_7,
    document_8,
    document_9,
    document_10,
]

uuids = [str(uuid4()) for _ in range(len(documents))]

store.add_documents(documents=documents, ids=uuids)
```

## 删除文档

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
store.delete(ids=["chunk_id_here"])
```

## 查询引擎

一旦您的命名空间已创建并将文档上传到其中，您就可以直接通过向量存储对文档提出查询。设置查询以及您希望用于回答查询的 LLM。有关支持 LLM 的更多信息，请访问我们的 [GitHub 页面](https://github.com/moorcheh-ai/moorcheh-python-sdk)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
query = "Give me a brief summary of the provided documents"
answer = store.generative_answer(query, ai_model = "anthropic.claude-sonnet-4-6-v1:0")
print(answer)
```

## 更多资源

有关 Moorcheh 的更多信息，请随时访问以下资源：

* [GitHub 页面](https://github.com/moorcheh-ai/moorcheh-python-sdk)
* [示例 GitHub 页面](https://github.com/moorcheh-ai/moorcheh-examples)
* [网站](https://www.moorcheh.ai/)
* [文档](https://console.moorcheh.ai/docs)
* [YouTube](https://www.youtube.com/@moorchehai)
* [X](https://x.com/moorcheh_ai)

***

<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\python\integrations\vectorstores\moorcheh.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>
