Moorcheh
>Moorcheh Moorcheh 是一个极速的语义搜索引擎和向量存储库。与使用简单的距离度量(如 L2 或余弦相似度)不同,Moorcheh 使用最大信息二值化(MIB)和信息论评分(ITS)来检索精确的文档块。
本页介绍如何在 LangChain 中使用 Moorcheh 进行向量存储、语义搜索和生成式 AI 响应。
安装与设置
安装 Python 集成包:
pip install langchain-moorcheh
从 Moorcheh Console 获取 Moorcheh API 密钥,并将其设置为环境变量:
向量存储
Moorcheh 提供了一个向量存储封装器,允许您高效地存储、搜索和检索文档嵌入。
查看 详细使用示例.
from langchain_moorcheh import MoorchehVectorStore
# Initialize the vector store
store = MoorchehVectorStore(
api_key="your-api-key",
namespace="your_namespace",
namespace_type="text" # or "vector"
)
# Add documents
from langchain_core.documents import Document
documents = [
Document(page_content="Your document content here", metadata={"source": "example"})
]
store.add_documents(documents=documents)
生成式 AI
Moorcheh 支持使用各种 LLM 模型(包括 Claude 3)进行生成式 AI 响应,让您能够根据存储的文档获取 AI 生成的答案。
# Get an AI-generated answer based on your documents
query = "What are the main topics covered in the documents?"
answer = store.generative_answer(
query,
ai_model="anthropic.claude-sonnet-4-6"
)
print(answer)
核心功能
- 文档管理:使用唯一 ID 添加和删除文档
- 语义搜索:使用自然语言查询查找相关文档
- 生成式 AI:使用各种 LLM 模型获取 AI 生成的答案
- 命名空间组织:将数据组织到独立的命名空间中
- 元数据支持:使用自定义元数据存储和检索文档
有关更详细的示例和高级用法,请参阅 Moorcheh vectorstore 集成.