Agnes 2.0-flash是推理模型,推理token占大量预算。 800仍不够→JSON截断(parse error: unexpected end of JSON input)。 1200确保推理+正文都够用。
3.4 KiB
3.4 KiB
P1: 织忆蒸馏引擎 LightMem 式逐条事实提取改造
2026-08-11 | 小唯 | 目标:把织忆 distill 从「整段摘要式提取」升级为「逐条事实提取」(借鉴 LightMem) 优先级:P1(织忆 distill 质量的根本提升)
目标(Goal)
当前 callLLM5D 用单 prompt 做整段摘要(decisions/conclusions/actions 各≤3条),对长对话信息密度高的场景丢失细节。
改造为 LightMem 式逐条事实提取:提取所有可独立成句的事实 + 保留全部实体细节 + 轻量上下文补全。
修改文件(Files to modify)
| 文件 | 修改 |
|---|---|
/tmp/memoryweave/go/internal/distill/engine.go |
callLLM5D prompt 重写 + LLMResponse 结构新增 FactsDetail |
/tmp/memoryweave/go/internal/distill/engine.go |
extractFacts 保留(fallback),新增 facts 组装逻辑 |
实现细节(Implementation details)
1. 重写 callLLM5D 的 prompt(第 265-284 行)
新 prompt 要点(LightMem METADATA_GENERATE_PROMPT 精华移植):
- 逐条判断:"处理每条用户消息,判断是否含事实;除非纯问候/填充,否则都提取"
- 轻量上下文补全:
"My friend John is studying medicine"→"User's friend John is studying medicine." - 保留全部具体细节:全名/地点/事件/数字/公司名——"The Name of the Wind by Patrick Rothfuss" 不是 "a book"
- 推断隐含信息:多个相关条目 → 推断一般模式,独立成条
- 时间处理:mention time(说的时间)vs event time(发生时间)
- 输出 JSON:
{"facts": [...], "entities": [...], "decisions": [...], "conclusions": [...], "is": 0.8, "su": 0.7, "pa": 0.6, "vd": 0.9, "ru": 0.7}
2. LLMResponse 结构
Facts字段含义升级:从「1条整段摘要」→「多条独立事实」- 保持
Decisions/Conclusions/ActionsTaken/OpenQuestions兼容(下游使用)
3. extractFacts fallback 保留
LLM 失败时仍走关键词+命名实体启发式(原逻辑不动)。
测试命令(Test commands)
# 1. 编译
cd /tmp/memoryweave/go && go build -o zhiyid-new ./cmd/zhiyid
# 2. 单元测试(若有)
cd /tmp/memoryweave/go && go test ./internal/distill/ -v 2>&1 | tail -20
# 3. 部署
systemctl --user stop zhiyid
cp /tmp/memoryweave/go/zhiyid-new /home/muc/bin/zhiyid-new
systemctl --user start zhiyid
sleep 2
# 4. 功能测试 — 提交一条含多事实的对话
curl -s -X POST -H "X-API-Key: zhiyi-dev-key-2026" -H "Content-Type: application/json" \
-d '{"agent_id":"a06","content":"牧尘说小唯今天安装了ffmpeg用于语音转码,昨天研究了LightMem的架构,上周买了新显卡RTX 5080","metadata":{"source":"test"}}' \
http://localhost:7821/api/v1/commit
# 5. 验证蒸馏质量 — 日志出现 facts ≥ 3 条 + entities 含具体实体
journalctl --user -u zhiyid --no-pager -n 20 | grep distill
# 6. recall 命中验证
curl -s -X POST -H "X-API-Key: zhiyi-dev-key-2026" -H "Content-Type: application/json" \
-d '{"query":"ffmpeg 语音转码","top_k":3}' \
http://localhost:7821/api/v1/recall
验收标准
- go build 通过
- 部署后 7821 健康
- 提交多事实内容后,日志显示
LLM facts: N且 N ≥ 3(旧版只有 1) - recall 能命中具体实体(ffmpeg/RTX 5080/LightMem)
- 蒸馏无 fallback(日志无
LLMEndpoint empty/JSON parse error)