知识入库与问答 — Hermes Skill
把任意内容存入 Open Notebook 知识库, 让用户日后能就这些内容提问 (RAG)。
| 输入类型 |
处理路径 |
产物 |
| URL (网页) |
ON 直接抓取 → embedding |
可检索可问答的 source |
| PDF |
MinerU 解析为 markdown + 原 PDF 备份 |
表格/公式保留的高质量 source |
| DOCX/TXT/MD/EPUB |
ON 上传 + 内置解析 |
可检索 source |
| 纯文本 |
直接存为文本 source |
可检索 source |
黄金规则:调用确定性脚本,不要自己拼 curl
Open Notebook 的 API 路径前缀不同版本不一致 (/api/sources vs /sources)、字段名有差异、PDF 要不要走 MinerU 有判断逻辑。这些都封装在 ops/ingest/ingest.sh 里。 直接调用:
terminal(command="bash $TITANVAULT_REPO/ops/ingest/ingest.sh <子命令> [参数]", workdir="$TITANVAULT_REPO")
工作流
场景 A: 存一个 URL ——「把这个链接存进知识库」
Step 1: 🔴 CHECKPOINT · 跟用户确认 (如果 URL 看起来可疑/超长)
「我把这个链接存入 Open Notebook, ON 会抓取网页内容并建立索引。
标题用 [网页标题/自定义], 继续?」
- 内部链接/明显正常 → 可跳过确认直接存
- 不确定来源 → 先 fetch 看一眼内容再决定
Step 2: 入库
bash ops/ingest/ingest.sh url <URL> --title "<标题>"
→ 输出 source_id
Step 3: 确认 + 告知
「✅ 已入库 (source_id=xxx)。ON 后台正在抓取+建索引, 约 1-3 分钟后可问答。
现在可以问关于这篇内容的问题。」
场景 B: 存一个 PDF ——「这篇 PDF 加到知识库」
Step 1: 确认文件 + 大小
ls -lh <PDF路径>
file <PDF路径>
Step 2: 检查 MinerU 状态 (PDF 质量的关键)
bash ops/ingest/ingest.sh probe
→ 看 MinerU 那行是否 ✅
Step 3: 🔴 CHECKPOINT · 告知处理方式
「这个 PDF 我用【MinerU 解析】(保留表格/公式/图表), 解析后存为可问答的文本源,
同时备份原 PDF。大 PDF 解析可能要几分钟。继续?」
- MinerU 不可用 → 降级提示: 「MinerU 暂不可用, 会直接上传, 表格/公式可能解析不全」
- 用户确认 → 继续
Step 4: 入库
bash ops/ingest/ingest.sh pdf <路径> --title "<标题>"
→ 内部: MinerU 解析 → 存 markdown 文本源 + 原PDF备份
Step 5: 确认
「✅ 已入库。MinerU 解析了 N 行 markdown, 原文件也备份了。
可以直接问关于这篇 PDF 的问题。」
场景 C: 存文本 ——「把这段话存进知识库」
echo "<文本>" | bash ops/ingest/ingest.sh text - --title "<标题>"
# 或
bash ops/ingest/ingest.sh text "<长文本>" --title "<标题>"
场景 D: 就已入库内容提问 ——「这篇报告的核心结论?」
🔴 GATE (ask 前判断): 如果是刚入库的 source (用户 5 分钟内存的),
先告知「刚入库的内容还在建索引, 可能要等 1-3 分钟才能问答」。
已入库超过 5 分钟 → 直接 ask。
bash ops/ingest/ingest.sh ask "<问题>"
→ RAG 检索 + LLM 生成答案
🔴 GATE (ask 返回空/无关后): 不要直接重述原问题。
先 bash ops/ingest/ingest.sh sources 看那个 source 的 status:
- processing → 告诉用户还在处理, 等会儿再问
- failed → 触发重试 POST /sources/<id>/retry
- ready 但空 → 换问法或缩小范围, 不要机械重试
回答质量问题:如果答案明显无关或为空,先检查 source 是否处理完成:
bash ops/ingest/ingest.sh sources
→ 看那个 source 的状态字段 (processing/ready/failed)
场景 E: 诊断 ——「知识库怎么不工作了」
bash ops/ingest/ingest.sh probe
→ 检查 ON 健康、端点前缀、MinerU、认证, 一眼定位问题
失败模式速查表(if-then)
| 触发条件 |
一线修复 |
仍失败兜底 |
| ON :5055 不通 (probe 全红) |
docker compose --profile apps ps open-notebook; 没起则 up -d open-notebook |
启动慢 (surrealdb 迁移), 等 3 分钟再 probe |
| url 存入后 ask 返回空 |
ON 还在抓取+embedding (1-3 min); sources 看 status; 等 60s 重试 |
source 状态=failed → 重试 POST /sources/<id>/retry |
| PDF MinerU 解析超时/失败 |
curl $MINERU_URL/health; MinerU 没起则 docker compose --profile ai-capability up -d mineru-api |
降级: 直接 file 子命令 (不走 MinerU), 告知用户表格/公式可能丢 |
| PDF 太大 (>100MB) MinerU OOM |
先拆分: pdftk big.pdf cat 1-50 output part1.pdf (按页) |
提醒用户用小一点的 PDF, 或只存关键章节 |
| ask 答案明显跑题 |
ON 的 embedding 模型没配好; 检查 setup-open-notebook.sh 是否跑过; GET /api/models 看 embedding 是否就绪 |
升级到 titanvault-ops 处理模型配置 |
| ask 中文问题报 OUTPUT_PARSING_FAILURE |
ON 的 LLM 用中文问时 JSON 输出格式错误 (英文正常)。已知限制, 非脚本 bug |
换英文提问, 或在完整模式 (/api/chat/execute) 下用中文 |
| ask 返回 "Ask operation failed" |
模型 ID 没传对; ingest.sh 会自动从 /api/models/defaults 获取, 检查该端点是否返回有效 model_id |
手动指定: 看 /api/models 拿一个 language 类型的 model id |
| text 子命令字段名不对 (string vs content) |
ingest.sh 已自动重试两个字段名 |
ON 版本太旧/太新, 看 /openapi.json 确认字段 |
| 认证 401/403 |
ON 启用了密码; 确认 .env 里 OPEN_NOTEBOOK_PASSWORD; probe 会显示密码模式 |
重跑 setup-open-notebook.sh |
| PDF 是扫描件 (纯图片) |
MinerU 会做 OCR, 但慢; 正常等 |
OCR 质量差→提醒用户提供文字版 PDF |
权限边界
| 动作 |
允许? |
方式 |
| 读用户提供的文件 |
✅ |
ls, file, cat |
| 存入本机 ON / MinerU 解析 |
✅ |
ingest.sh url/file/text/pdf |
| RAG 问答 |
✅ |
ingest.sh ask |
| 列出 notebook / source |
✅ |
ingest.sh notebooks/sources |
| 抓取用户指定的 URL (本机 ON 抓) |
✅ |
ingest.sh url (ON 服务端抓取, 非脚本抓) |
| 删除 source / notebook |
❌ 升级 |
告诉用户, 不自动删 |
| 改 ON 配置 / 模型 |
❌ 升级 |
提议 diff, 不直接改 |
| 抓取用户未指定的 URL |
❌ 拒绝 |
只存用户明确给的 URL, 不自动扩展爬取 |
| 上传文件到外部服务 |
❌ 拒绝 |
所有内容只进本机 ON, 永不上传外部 |
反模式黑名单(绝不做的事)
| # |
反模式 |
为什么 / 替代 |
| 1 |
自己拼 curl 调 ON API |
路径前缀、字段名、认证都有版本差异。用 ingest.sh |
| 2 |
PDF 不走 MinerU 直接传 ON |
丢表格/公式/图表。PDF 必须先 probe 检查 MinerU |
| 3 |
存入后不告诉用户「还要等处理」 |
embedding 是异步的, 用户马上问会得到空答案, 以为坏了 |
| 4 |
ask 返回空就判定「没存进去」 |
80% 是还在处理, 不是失败。先 sources 看状态 |
| 5 |
抓取用户没给的 URL |
迷失方向 + 隐私风险。严格只处理用户指定的输入 |
| 6 |
一次存几十个 URL 不分批 |
ON 处理是串行的, 批量会堆积。提醒用户分批, 每批等前一批 ready |
| 7 |
把扫描件 PDF 当文字 PDF |
扫描件要 OCR (MinerU 支持), 直接传可能出空白。先 pdftotext 试探有无文字层 |
| 8 |
ask 答非所问就直接重述原问题 |
换个问法或缩小范围, 或检查 source 是否处理完。机械重试无效 |
技术细节(排障时查)
- Open Notebook (:5055, UI :8088): 无认证 (本机默认) 或密码 (
OPEN_NOTEBOOK_PASSWORD)。SurrealDB 后端。Embedding 走 LiteLLM→Qwen3-Embedding。Source 异步处理: 上传立即返回 id, 后台抓取/embedding。
- 路径前缀: 探测
/openapi.json 自动确定 /api/sources 或 /sources。结果缓存 1 小时 (/tmp/ingest_on_prefix.cache)。
- MinerU (:18080 mineru-api): 无认证。
POST /file_parse (multipart file) → markdown。GPU 解析, 大 PDF 慢。
- /ask 是 SSE 流式:
curl -N, 取 type=final_answer 的 content 拼接。
- ON 不能路径反代 (Caddyfile 注明): 必须用原始端口 :5055, 不能走
/open-notebook/ 子路径。
环境变量(从 $TITANVAULT_REPO/.env 读)
OPEN_NOTEBOOK_URL=http://localhost:5055
OPEN_NOTEBOOK_PASSWORD= # 空=无密码
MINERU_API_URL=http://localhost:18080
View full license text (Apache-2.0)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.