Skip to main content

docs-search

零依赖的本地文档搜索引擎。纯 Python 标准库,SQLite 索引,毫秒级检索。

A zero-dependency local document search engine. Pure Python stdlib, SQLite index, millisecond-level retrieval.

特性 / Features

  • 零依赖 — 纯 Python 标准库(3.10+),无需 pip install
  • 快 — SQLite FTS 索引,检索 < 50ms
  • 自动索引 — 搜索前自动检测文件变更并增量重建
  • AI Agent 对接 — 内置 MCP stdio server(Cursor / ZCode / Qoder / DSH 等即插即用)+ pi 扩展;支持本地模式与远程模式(--url 连已运行的服务,可配 Bearer/Basic 认证)
  • 远端部署 — docs-search-web --host 0.0.0.0 --token <T> 独立启动为远端服务(非回环监听强制认证);后端与 agent 可分离部署
  • Web UI — 内置搜索界面 + 拖拽上传 .md 文档
  • 多库隔离 — 不同文档目录各自独立索引,可并存;每次操作可带 workspace 动态切自包含库(MCP/API/CLI 一致)
  • 上传安全 — 同名默认提示冲突,可强制覆盖或自动 -N 新文件;.md only、≤10MB、消毒
  • 不绑定路径 — 文档目录由参数/环境变量指定,不写死任何本地路径
  • 跨平台 — Windows / macOS / Linux

📖 文档站 / Documentation

https://ninjasln-labs.github.io/docs-search/

快速开始 / Quick Start

# 1. 索引一个文档目录(默认 ./docs,也可用 --dir 指定)
python scripts/docs-search.py index --dir /path/to/your/docs

# 2. 搜索
python scripts/docs-search.py search "关键词" --dir /path/to/your/docs

# 3. 启动 Web UI(含上传接口)
python scripts/docs-search-web.py /path/to/your/docs
# 访问 http://127.0.0.1:8765

路径解析规则

目标 优先级
文档目录 --dir 参数 > 环境变量 DOCS_SEARCH_DIR > ./docs
索引库 --db 参数(CLI)> 环境变量 DOCS_SEARCH_DB > ~/.docs-search/<目录哈希>/index.db

索引库按文档目录哈希隔离——多个文档目录可以各自拥有独立索引,互不干扰。

CLI

python scripts/docs-search.py index    [--dir DIR]   # 重建索引
python scripts/docs-search.py search "关键词" [--dir DIR] [-n 8]  # 多关键词 AND 搜索
python scripts/docs-search.py list     [--dir DIR]   # 列出所有文档
python scripts/docs-search.py show <path> [--dir DIR] # 显示文档内容
python scripts/docs-search.py status   [--dir DIR]   # 查看索引状态
python scripts/docs-search.py upload <file.md> [--dir DIR]  # 复制 .md 到文档库 uploads/ 并重建索引
python scripts/docs-search.py open <path> [--dir DIR]  # 用系统默认程序打开

Windows 下可用 scripts/docs-search.bat。

Web API

启动:python scripts/docs-search-web.py [DIR] [--port 8765] [--host 127.0.0.1] [--no-browser]

方法 端点 说明
GET /api/stats 统计信息 {count, updated, categories}
GET /api/search?q=关键词&cat= 搜索(多关键词 AND)
GET /api/list?cat= 列出文档
GET /api/show?path=x.md 文档内容
POST /api/upload?filename=x.md 上传文档(raw body = UTF-8 文本)
POST /api/delete?path=uploads/x.md 删除 uploads/ 下已上传文档

上传示例:

curl -X POST "http://127.0.0.1:8765/api/upload?filename=notes.md" \
     --data-binary @notes.md

上传的文件存入 <文档目录>/uploads/ 并自动进入索引;同名默认返回重名提示(不写不覆盖),可 if_exists=overwrite 覆盖或 if_exists=keep 生成 -1/-2 新文件;每次操作可带 workspace 切到独立自包含库(不填 = 默认库)。

AI Agent 接入(MCP)

内置零依赖 MCP stdio server,让 AI agent 直接检索/写入文档库:

# Cursor(~/.cursor/mcp.json)
{ "mcpServers": { "docs-search": { "command": "docs-search-mcp", "args": ["--dir", "/path/to/docs"] } } }

# Qoder CLI(-s user 全局;中国版额度在 qodercn,与国际版账号不通用)
qodercn mcp add -s user docs-search -- docs-search-mcp --dir /path/to/docs

暴露 5 个工具:docs_search / docs_read / docs_write / docs_delete / docs_info。 ZCode(Settings → MCP Servers)、DSH(@deepseek-ai/dsh-mcp-client 插件行)配置及 pi 扩展安装, 见 Agent 接入指南。

已有 docs-search 服务在运行时(本机或其他机器,接口与 /api/* 相同),MCP 可直接连它、不读本地目录:

# Cursor(远程模式——服务已启动/异机共享时用;远端启用认证时带 --token/--user/--password)
{ "mcpServers": { "docs-search": { "command": "docs-search-mcp", "args": ["--url", "http://192.168.1.10:8765", "--token", "<TOKEN>"] } } }
# 或环境变量: DOCS_SEARCH_URL=http://192.168.1.10:8765 docs-search-mcp
# 连接代理: 默认跟随环境代理;干扰时 --proxy direct 直连,或 --proxy http://代理:端口 指定(DOCS_SEARCH_PROXY)

# 后端独立启动为远端服务(非回环监听强制要求认证)
docs-search-web /path/to/docs --host 0.0.0.0 --token <TOKEN>

安全说明 / Security

  • 服务默认仅监听 127.0.0.1;监听非回环地址(如 --host 0.0.0.0)必须启用认证(--token Bearer 或 --user/--password Basic),否则拒绝启动
  • 上传仅接受 .md 文件、单文件 ≤ 10MB、文件名经过消毒(防路径穿越)
  • 删除接口仅允许操作 uploads/ 目录内的文件

开发 / Development

pip install -r requirements.lock -e .   # 可编辑安装 + 锁定的开发工具链
python scripts/verify.py        # 验证链单源:ruff + pytest(单元 + CLI E2E + Web API)
ruff check src/ tests/ scripts/  # lint
git config core.hooksPath .githooks  # 启用 pre-commit 验证链

工程结构见 DEVELOPMENT.md,贡献规范见 CONTRIBUTING.md,AI 协作纪律见 AGENTS.md。English docs: README.en.md

许可证 / License

MIT — 见 LICENSE

Metadata

Release files for docs-search 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docs-search 1.3.0
File Size Uploaded Provenance
docs_search-1.3.0.tar.gz 50.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for docs-search 1.3.0
File Interpreter ABI Platform
docs_search-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 88.0 kB

Release files / docs_search-1.3.0.tar.gz

Download URL docs_search-1.3.0.tar.gz
Size 50.4 kB
Tags Source
SHA-256 checksum
How to use checksums
075176a4e21291d65d5670dae37d13a398cd5a83681529e9b07877b0006e2c00
BLAKE2b-256 checksum
How to use checksums
48bda7e77567b187a0384704dcdde92c4e00ef9708749033268300fae5ba69a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / docs_search-1.3.0-py3-none-any.whl

Download URL docs_search-1.3.0-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e6db89b236062bbb95ab2671eeecb36b7dd9c444f416fde87625460bdcf8bc7
BLAKE2b-256 checksum
How to use checksums
e4fbe6b5f831c516a3f3628524078dd4328265e036ec70f83b708781062509da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Security for docs-search 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for docs_search-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page