文索 AxcWenSuo
Offline, Chinese-first RAG engine with no server: any folder becomes a searchable knowledge base for humans and AI agents.
中文优先、不起服务、目录即知识库的本地 RAG 引擎。人和程序共用同一个内核:命令行、Python API。
状态:
0.2.0(Alpha)。核心检索、同步、引用、缺口清单、评测、CLI/API 已实现并有自动化测试;
特性
- 目录即知识库:放入、修改、删除文件后,下一次查询前自动增量同步;删掉索引目录后自动重建,结果一致。
- 中文关键词检索:单字 + 相邻两字 + 标识符拆分的 BM25,中文与
user_id这类英文标识符都能检索。 - 结果可追溯:每条结果带文件路径、章节路径、行号 / 页码 / 幻灯片号 / 工作表行号。
- 分数可信:可选重排分数经过温度/偏置校准,阈值有明确含义;未开启重排时分数只用于排序,不接受阈值。
- 知道“查不到”:结果里列出知识库中不存在的标识符,并把空结果、缺标识符的查询记入缺口清单。
- 低资源、离线:运行时只有 numpy / onnxruntime / tokenizers / PyYAML / filelock,不依赖 torch,不联网。
- 两种入口一个内核:命令行文本/JSON、Python API 的检索结果完全一致。
安装
需要 Python 3.11 ~ 3.13,推荐 uv。
从源码安装:
在自己的项目里作为依赖安装:
uv add axc-wensuo # 核心:Markdown / TXT / CSV
uv add "axc-wensuo[docs]" # 另加 PDF / Office / HTML 解析
uv run ws models download # 下载默认向量模型(约 95 MB)
从源码开发:
git clone https://github.com/axclogo/AxcWenSuo.git
cd AxcWenSuo
uv sync
uv run ws --version
需要解析 PDF / Word / Excel / PPT / HTML 时安装 docs 扩展(会带入 torch,体积较大):
uv sync --extra docs
docs扩展使用 Docling。首次解析 PDF 时 Docling 会下载版面/表格模型(需要网络),之后离线可用; 也可以按 Docling 文档预置DOCLING_ARTIFACTS_PATH。未安装 Docling 时相关测试自动跳过;CI 另有一个安装 docs 扩展的任务。
快速开始
# 1. 指定知识库根目录(也可在 ~/.config/wensuo/config.yaml 里登记 --kb 名字)
cd ~/Documents/notes
# 2. 看诊断:文档数、段数、专题、跳过/解析失败的文件
ws doctor
# 3. 检索
ws search "用户表的 user_id 字段"
ws search "部署 环境变量" --top-k 10 --scope 运维 --format json
# 4. 读原文 / 看单段
ws read "数据字典/用户.md" --section "用户表 > 字段说明"
ws show 3f2a9c0d1e4b5a67
# 5. 缺口清单:用户和 agent 都查不到的内容
ws gaps
ws 不带 --root / --kb 时使用全局配置的 default,没有则使用当前目录。
向量检索默认开启。若还没有准备模型,先在
wensuo.yaml写入dense: {enabled: false}, 否则带自动同步的命令会报“向量模型未就绪”。模型准备见下文准备模型。
Python API
from axc_wensuo import Filters, KnowledgeBase, SearchOptions
with KnowledgeBase('/path/to/docs') as kb:
report = kb.sync() # SyncReport
result = kb.search('用户表的 user_id 字段', top_k=5, scope=['数据字典'])
advanced = kb.search(
'用户表',
options=SearchOptions(filters=Filters(tags=['数据库'], file_types=['md']), max_chars=400),
)
doc = kb.read('数据字典/用户.md', section='用户表 > 字段说明')
chunk = kb.show('3f2a9c0d1e4b5a67')
docs = kb.list_docs(scope=['数据字典'])
print(result.to_dict()) # 与 CLI --format json 完全相同
配置
知识库配置是可选的 <root>/wensuo.yaml(全部字段可省略):
name: notes # 显示名,默认根目录名
index_dir: null # 索引目录,默认 <root>/.wensuo/
models_dir: null # 默认 ~/.cache/wensuo/models/
threads: null # 默认 max(1, CPU 核数 // 2)
include: [] # glob,相对根目录;**/ 可匹配零层或多层目录
exclude: []
max_file_mb: 50
scopes: {数据字典: 表结构与字段说明}
scope_rules: [{glob: "**/*报销*", scope: 财务}]
chunk: {max_chars: 1200, min_chars: 80}
lexical: {tokenizer: cjk_bigram, title_weight: 2, k1: 1.2, b: 0.5}
dense: {enabled: true, model: bge-small-zh-v1.5}
fusion: {w_lexical: 1.0, w_dense: 0.25, candidates: 50, max_per_doc: 3}
rerank: {model_dir: null, top_k: 30, min_score: null}
全局配置 ~/.config/wensuo/config.yaml(Windows 为 %APPDATA%\wensuo\config.yaml):
default: notes
kbs:
notes: ~/Documents/notes
manuals: /data/manuals
同义词写在 <root>/synonyms.yaml,例如 - [登录, 登陆, sign in];改完不需要重建索引。
完整字段、约束与行为以 docs/REQUIREMENTS.md 为准。
专题(scope)
每篇文档恰好属于一个专题,按顺序取第一个命中的规则:
- Markdown 文件头 YAML 的
scope; wensuo.yaml的scope_rules(按顺序第一个匹配的 glob);- 文件所在的第一级子目录名;
- 根目录文件为
_root。
准备模型
向量检索默认开启,需要 bge-small-zh-v1.5 的 ONNX 导出(约 95 MB,512 维,CLS + L2 归一化)。
执行 ws models download 从本仓库 GitHub Release models-v1
下载到 ~/.cache/wensuo/models/(或 models_dir),下载后校验 SHA-256,不一致报错。
查询时发现缺模型只报错提示执行该命令,不会自动联网。网络受限时有两种替代方式:
- 自己导出(torch 等只临时安装,不进入项目依赖),结果与 Release 逐字节相同:
uv run --no-project --python 3.13 --with torch --with transformers --with onnx --with onnxruntime \ --with huggingface_hub python tools/export_embedder.py --output dist/models/bge-small-zh-v1.5
然后在wensuo.yaml中设置models_dir指向dist/models(目录结构为<models_dir>/bge-small-zh-v1.5/{model.onnx,tokenizer.json})。 - 暂时关闭向量,只用关键词检索:
dense: {enabled: false}
重排是可选项,默认关闭。开启时把 rerank.model_dir 指向一个包含 model.onnx、tokenizer.json、
model_meta.json 的目录(规格见需求文档第 7.4 节)。
命令行
ws [--root PATH | --kb NAME] <命令> [选项]
ws search QUERY [--top-k 5] [--scope S]... [--path-prefix P] [--tag T]...
[--file-type EXT]... [--modified-after YYYY-MM-DD] [--min-score F]
[--max-chars 800] [--format text|json] [--no-sync] [--threads N]
ws read DOC_ID [--section "标题 > 子标题"] [--offset 0] [--max-chars 20000]
[--format text|json] [--no-sync]
ws show CHUNK_ID [--format text|json]
ws docs [--scope S]... [--path-prefix P] [--format text|json] [--no-sync]
ws scopes [--format text|json]
ws sync [--threads N] [--format text|json]
ws doctor [--format text|json]
ws gaps [--limit 50] [--format text|json] [--clear]
ws eval QUERIES.jsonl [--modes lexical,dense,fused,rerank] [--k 5] [--format text|json]
ws models download [--force]
ws --version
退出码:0 成功;1 search 无结果 / read、show 找不到对象;2 参数或配置错误;
3 运行错误(缺模型、缺扩展、索引损坏、锁超时等)。--format json 时错误也会以
{"schema_version": 1, "error": {"code": 2, "message": "…"}} 写到标准输出。
评测
评测集是 JSONL,每行一个对象:
{"id": "q1", "query": "……", "relevant": [{"doc_id": "a/b.md", "title_path": ["标题"]}], "k": 5}
{"id": "q2", "query": "……", "no_answer": true}
ws eval eval/queries.jsonl --modes lexical,fused --k 5
输出 hit_at_k、top1、mrr_at_k、answerable_return_rate、false_return_rate。
开发
uv sync --dev
uv run ruff check .
uv run pytest
- 代码风格:Tab 缩进、单引号、行宽 120、方法/类之间 1 个空行(
ruff check见 pyproject.toml)。 - 公开测试语料在 tests/fixtures/corpus,由 tools/make_fixtures.py 生成。
- 非功能基准:tools/bench.py。
- 模型导出:tools/export_embedder.py。
- 实现说明(索引结构、同步流程、检索流水线)见 docs/ARCHITECTURE.md。
- 贡献流程见 CONTRIBUTING.md,开发红线见 docs/CODE_POLICY.md。
已知限制
- Alpha 阶段:解析器对 Docling 的支持依赖可选
docs扩展;首次使用需要下载 Docling 模型,CI 默认不安装 Docling。 - 不做扫描件 OCR、旧版
.doc/.xls/.ppt、多用户、常驻服务、文件监听。 - 默认向量模型需要手动准备(见上文),在模型就绪前请关闭
dense或只使用docs以外的关键词检索。 - 规模上限约 10 万段;相似度为暴力点积,不使用近似向量索引。
- 索引结构随版本变化;遇到“索引版本不兼容”时删除索引目录(默认
<root>/.wensuo/)后重新同步即可。
许可证
Apache-2.0。依赖许可:Docling(MIT)、bge-small-zh-v1.5(MIT)、onnxruntime(MIT)、 tokenizers(Apache-2.0)、filelock(Unlicense)、PyYAML(MIT)。
Metadata
Release files for axc-wensuo 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| axc_wensuo-0.2.0.tar.gz | 418.4 kB | Without provenance | Details for axc_wensuo-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| axc_wensuo-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for axc_wensuo-0.2.0-py3-none-any.whl |
Total release size: 496.0 kB
Release files / axc_wensuo-0.2.0.tar.gz
| Download URL | axc_wensuo-0.2.0.tar.gz |
|---|---|
| Size | 418.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d1b1ae156c61943c1489bc83058c53b3d1bd2876d9b089e6e4d77e9ee3ca1c9
|
|
BLAKE2b-256 checksum How to use checksums |
b48cdb4a4e219441c372e54d5cdcaf68b8de90010eabfda1a5c1d69308200350
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / axc_wensuo-0.2.0-py3-none-any.whl
| Download URL | axc_wensuo-0.2.0-py3-none-any.whl |
|---|---|
| Size | 77.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd6e0a1279d646b524940e0a7fa25a5af128c769cb0a6f843b81b998056c9372
|
|
BLAKE2b-256 checksum How to use checksums |
e2efb768fde63cd616d91f5f8ea3e0f6616e0faf1966fbec7ffe41e3d72cc7ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for axc-wensuo 0.2.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.