doc中心
具有混合矢量+全文检索的多语料库文档搜索引擎,通过MCP(模型上下文协议)公开,供LLM代理使用。
它做什么
doc-hub从各种来源获取文档,将其解析为语义上有意义的块,用可插拔的嵌入器嵌入它们,用VectorChord在PostgreSQL中对它们进行索引,并通过MCP服务器或CLI提供混合搜索(矢量KNN+BM25全文,通过RRF融合)。
插件系统允许您添加新的获取器、解析器和嵌入器,而无需修改dochub本身。
安装
doc-hub是从GitHub安装的(未发布到PyPI)。
# Install globally from GitHub (recommended)
uv tool install --force git+https://github.com/kingfly55/doc-hub.git
# Or install globally from a local clone while developing
uv tool install --force /path/to/doc-hub
# Or run from a local clone without a global install
git clone https://github.com/kingfly55/doc-hub.git && cd doc-hub
uv sync
source .venv/bin/activate验证:
doc-hub --help
man doc-hub
# fallback if your shell has not picked up the installed manpath yet
doc-hub manman doc-hub 是已安装CLI的简明本地参考。 doc-hub man 是直接打印捆绑的手册页文本的内置回退。
支持的命令界面是统一的 doc-hub CLI。统一前的旧包装,如 doc-hub-search, doc-hub-pipeline, doc-hub-eval, doc-hub-sync-all,以及 doc-hub-mcp 不应该留在你的路径上。
需求
- Python>=3.11
- PostgreSQL与 VectorChord 扩展
- Gemini API密钥(免费层工作)-或自定义嵌入式插件
快速启动
1.使用VectorChord启动PostgreSQL
docker run -d --name vchord-postgres \
-e POSTGRES_PASSWORD=mypassword \
-p 5432:5432 \
tensorchord/vchord-postgres:latest2.设置环境变量
对于全球 doc-hub 安装时,最持久的设置是doc-hub的XDG数据目录下的一个机器范围的env文件:
mkdir -p ~/.local/share/doc-hub
cat > ~/.local/share/doc-hub/env " }
}
}
}上海证券交易所 (连接到正在运行的服务):
{
"mcpServers": {
"doc-hub": {
"type": "sse",
"url": "http://localhost:8340/sse"
}
}
}看 docs/user/mcp-server.md 有关传输详细信息和systemd服务设置。
作为systemd服务运行
cat > ~/.config/systemd/user/doc-hub-serve-mcp.service << 'EOF'
[Unit]
Description=doc-hub MCP Server (SSE on :8340)
After=network.target postgresql.service
[Service]
Type=simple
WorkingDirectory=%h
ExecStart=%h/.local/bin/doc-hub serve mcp --transport sse --port 8340
Restart=always
RestartSec=10
Environment=HOME=%h
EnvironmentFile=%h/.local/share/doc-hub/env
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now doc-hub-serve-mcp.service插件系统
doc-hub使用基于Python入口点的插件架构。三种插件类型:
| 插件类型 | 入口点组 | 协议 |
|---|---|---|
| 费彻 | doc_hub.fetchers | doc_hub.protocols.Fetcher |
| 解析器 | doc_hub.parsers | doc_hub.protocols.Parser |
| 嵌入器 | doc_hub.embedders | doc_hub.protocols.Embedder |
内置取料机: llms_txt, sitemap, git_repo, local_dir, direct_url. 内置解析器: markdown. 内置嵌入器: gemini.
看 docs/dev/plugin-authorization.md 获取编写插件的完整指南。
作为一个图书馆
import asyncio
from doc_hub.search import search_docs
from doc_hub.db import create_pool
async def main():
pool = await create_pool()
results = await search_docs("how do I define a tool?", pool=pool, corpora=["pydantic-ai"])
for r in results:
print(f"{r.heading} (sim={r.similarity:.3f})")
await pool.close()
asyncio.run(main())数据存储
doc-hub将本地数据(原始下载、块缓存、嵌入缓存)存储在XDG兼容目录中:
DOC_HUB_DATA_DIRenv-var(显式重写)$XDG_DATA_HOME/doc-hub如果XDG_DATA_HOME已设置~/.local/share/doc-hub(默认)
~/.local/share/doc-hub/
├── {corpus-slug}/
│ ├── raw/ # downloaded .md files + manifest.json
│ └── chunks/
│ ├── chunks.jsonl # parsed chunks
│ ├── embedded_chunks.jsonl # chunks with embedding vectors
│ └── embeddings_cache.jsonl # embedding cache (keyed by content hash)
└── plugins/ # local plugin files (alternative to entry points)
├── fetchers/
├── parsers/
└── embedders/环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
GEMINI_API_KEY | -- | 内置Gemini嵌入器需要 |
JINA_API_KEY | -- | 必需 sitemap fetcher和 llms_txt 和 --use-jina/--try-md |
DOC_HUB_DATABASE_URL | -- | 完整连接字符串(覆盖PG\*vars) |
PGHOST | localhost | PostgreSQL主机 |
PGPORT | 5432 | PostgreSQL端口 |
PGDATABASE | postgres | 数据库名称 |
PGUSER | postgres | 数据库用户 |
PGPASSWORD | -- | 数据库密码(必填) |
DOC_HUB_DATA_DIR | ~/.local/share/doc-hub | 覆盖数据目录 |
DOC_HUB_EVAL_DIR | {data_root}/eval/ | 覆盖eval目录 |
LOGLEVEL | -- | 设置为 DEBUG 用于详细输出 |
测试
# Unit tests (no DB or API key needed)
pytest tests/
# Integration tests (requires live DB + GEMINI_API_KEY)
pytest tests/ -m integration