Files
memoryweave/docs/p5-wiki-curation-plan.md
T
xiaowei 2a350cf781 fix(distill): max_tokens 800→1200 — Agnes推理token预算不足
Agnes 2.0-flash是推理模型,推理token占大量预算。
800仍不够→JSON截断(parse error: unexpected end of JSON input)。
1200确保推理+正文都够用。
2026-08-20 01:13:06 +08:00

78 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# P5: Wiki 策展管线 — 自动知识库
## 问题
织忆能存储和检索记忆,但没有"知识库"的概念:将外部文档(.md 文章、技术笔记、项目文档)
自动提取为结构化知识条目,写入织忆系统供后续 recall 搜索。
## 方案(参考 Memory-OS Layer 5+6,适配织忆架构)
Memory-OS 用 Wiki Agent(LLM 提取概念/实体/对比)+ Continuous Ingest(嵌入 Qdrant)。
织忆的替代方案:Python 脚本扫描 Obsidian Vault → LLM 提取知识点 → 通过 /commit API 写入织忆。
## 实现
### 新增文件: `scripts/wiki_curator.py`
```python
#!/usr/bin/env python3
"""
Wiki Curator — 自动知识策展管线
扫描 Obsidian vault 中的 .md 文件,用 LLM 提取知识点,通过织忆 API 存入结构性记忆。
流程:
1. 扫描 ~/mc/小唯/ 和 ~/obsidian/ 中的 .md 文件(排除缓存/临时文件)
2. SHA-256 diff 检测(只处理新增/修改的文件)
3. LLM 提取:
- 概念(concept):什么是 X?
- 实体(entity):X 的属性/参数/配置
- 关系(relation):X 和 Y 的关系
4. 通过织忆 /commit API 写入 memories(category='wiki')
5. 更新状态文件(记录已处理的文件哈希)
"""
# 配置
WIKI_DIRS = [
"~/mc/小唯/", # 织忆设计文档/技术笔记
"~/mc/牧尘/", # 系统配置/命令记录
# 可根据需要扩展
]
ZHIYI_API = "http://localhost:7821"
ZHIYI_KEY = "zhiyi-dev-key-2026"
STATE_FILE = "~/.hermes/wiki_curator_state.json"
```
### 处理逻辑
对每个新/修改的文件:
1. 读取内容,过滤掉过短(<500字)或明显非知识性的文件
2. 调用 LLM(Hermes 的模型或 NewAPI)提取:
```json
{
"concepts": [{"name": "X", "summary": "...", "details": "..."}],
"entities": [{"name": "Y", "attributes": {...}}],
"relations": [{"source": "X", "relation": "uses", "target": "Y"}]
}
```
3. 对每个提取的概念/实体,通过织忆 /commit API 写入
4. 对每个关系,通过织忆 /api/v1/graph/edge API 写入
### 定时任务
创建 cronjob 每周运行两次(周一/周四凌晨3点):
```bash
hermes cron add "织忆 Wiki 策展" --schedule "0 3 * * 1,4" \
--prompt "执行 wiki_curator.py 扫描检查" \
--script ~/.hermes/scripts/wiki_curator.py
```
## 验证
```bash
# 手动运行
python3 ~/.hermes/scripts/wiki_curator.py --dry-run
# 验证织忆端已有 wiki 类记忆
curl -s -X POST -H "X-API-Key: zhiyi-dev-key-2026" \
-d '{"query":"织忆设计","top_k":5}' \
http://localhost:7821/api/v1/recall
```