8.6 KiB
8.6 KiB
织忆五步实施计划
创建时间:2026-05-30 状态:E1/E2/E3 已完成,E4-E5 规划中 禁止:偷懒、随意更改变动设计语言
总览
| 阶段 | 内容 | 优先级 | 预计工期 | 状态 |
|---|---|---|---|---|
| E1 | 图谱导航激活 | 🔴 高 | 1-2 天 | ✅ 完成 |
| E2 | 多 agent 命名空间激活 | 🔴 高 | 1 天 | ✅ 完成 |
| E3 | 增量 embedding | 🟡 中 | 1 天 | ✅ 完成 |
| E4 | 图谱推理 | 🟡 中 | 2-3 天 | ⏳ |
| E5 | 产品 UI | 🔵 低 | 长期 | ⏳ |
E1:图谱导航激活
目标
改造 /recall 链路,向量搜索后接图谱 BFS 扩展,让搜索结果融合结构化知识。
现状
- 图谱数据:1269 节点 / 31248 边(
graph/stats确认) navigate.goBFS 导航代码已写好,但/recall没调用/recall当前纯语义搜索,不走图谱
实施步骤
E1.1 确认 navigate.go 接口
- 找到
navigate.go的函数签名和参数 - 确认 BFS 扩展是 1 跳还是 2 跳
- 确认输出格式(节点列表还是边列表)
E1.2 改造 recall 链路
修改 internal/api/routes/recall.go:
语义搜索 → 向量 top-K →
图谱 BFS 扩展(navigate 1跳邻居)→
合并去重 → bge-reranker 重排 →
返回最终结果
E1.3 测试验证
# 验证图谱有数据
curl http://localhost:7821/api/v1/graph/stats
# 验证 recall 走图谱(找有图谱关联的记忆)
curl "http://localhost:7821/api/v1/recall?query=织忆图谱导航&top_k=5"
# 对比:图谱激活前 vs 激活后的召回结果差异
# 激活后应该出现更多 1 跳邻居相关结果
验收标准
graph/statsnode_count > 1000(已有,确认不变)- recall 结果中包含图谱扩展内容(通过日志或响应标记确认)
- 延迟 < 500ms(可接受范围)
E2:多 agent 命名空间激活
目标
Hermes 和 OpenClaw 使用独立 namespace,数据物理隔离,互不串味。
现状(2026-05-31 验证)
- ✅ Hermes:
agent_id="hermes-a06"→namespace="hermes-main"(GoderiveNamespace自动推导) - ✅ OpenClaw:
agent_id="openclaw",namespace="openclaw-main"(zhiyi client 显式传递) - ✅ Rust sidecar:
search()/scan_all()均有only_if("namespace = '{}'", ns)namespace 过滤 - ✅ 验证:同一 query 在 hermes-main 和 default-main 返回不同 ID 的记忆,隔离生效
- ℹ️ 历史数据(
agent_id=default)在default-main,与 hermes-main/openclaw-main 物理隔离
实施步骤
E2.1 确认当前 namespace 配置(已验证)
- Hermes 插件:
agent_id="hermes-a06"硬编码于ZhiYiClient.commit/recall(~/.hermes/plugins/zhiyi/__init__.py) - OpenClaw 插件:
agent_id="openclaw",namespace="openclaw-main"硬编码于ZhiYiClient(/persistent/.../memory-zhiyi/src/client.ts)
E2.2 验收(2026-05-31 通过)
# Hermes recall → hermes-main
curl -X POST http://localhost:7821/api/v1/recall \
-H "X-API-Key: zhiyi-dev-key-2026" \
-d '{"query":"牧尘 小唯","top_k":3,"namespace":"hermes-main"}'
# → 返回 hermes-main 专属记忆
# OpenClaw recall → openclaw-main
curl -X POST http://localhost:7821/api/v1/recall \
-H "X-API-Key: zhiyi-dev-key-2026" \
-d '{"query":"牧尘 小唯","top_k":3,"namespace":"openclaw-main"}'
# → 返回 openclaw-main 专属记忆
验收标准
namespace=hermes-main查询不到namespace=openclaw-main的记忆namespace=openclaw-main查询不到namespace=hermes-main的记忆- Rust sidecar 在 commit/recall 时正确使用 namespace 过滤
E3:增量 embedding
目标
commit 时同步调用 vLLM embedding,不等 Rust sidecar batch,延迟从分钟级降到毫秒级。
现状(2026-05-31 验证)
- ✅ 已实现:Go
core.go:79在Commit()中调用a.Embedder.EncodeSingle(req.Content) - ✅ BGE HTTP:连接
localhost:8000/v1/embeddings,17ms/条,L2 归一化 - ✅ IPC 传输:Go 将 vector + 文本一起发往 Rust
lancedb_insert,Rust 直接存储(不重编码) - ✅ 验证:commit 后立即 recall 测试记忆排第一(score=0.843),无需等待 batch
- ℹ️ embedder.go 有
MOLIFANG_API_KEYfallback(当前未启用,环境无此 key)
实施步骤
E3.1 确认当前 embedding 流程(已验证)
- Go
core.go:79→a.Embedder.EncodeSingle(req.Content)→ BGE HTTP 8000 → 1024-dim vector - Go
core.go:123→Vector: vector写入models.MemoryRecord - Go
core.go:129→a.LanceDB.InsertMemory(mem)→ IPClancedb_insert发送到 Rust - Rust
lancedb_ops.rs:160-163→ 从 JSON 读取 vector,直接写入 LanceDB FixedSizeListArray
E3.2 验证结果(2026-05-31)
# commit 后立即 recall
curl -X POST http://localhost:7821/api/v1/commit \
-H "X-API-Key: zhiyi-dev-key-2026" \
-d '{"content":"E3增量embedding测试:验证commit时同步生成vector","namespace":"default-main"}'
# → memory_id: mem_1780211630617301197
curl -X POST http://localhost:7821/api/v1/recall \
-H "X-API-Key: zhiyi-dev-key-2026" \
-d '{"query":"E3增量embedding测试","top_k":3,"namespace":"default-main"}'
# → mem_1780211630617301197 排第一,score=0.843 ✅
验收标准
- commit 响应包含 memory_id(写入成功)
- commit 后立即 recall 能搜到(无需等待 Rust sidecar batch)
- recall 得分 > 0.8(证明向量有效,非零向量)
E4:图谱推理
目标
图谱真正参与推理:矛盾检测、跨 agent 共享、遗忘决策参考图谱结构。
现状
- 图谱存了 1269 节点/31248 边,但只搜不用
- 没有基于图谱结构的推理逻辑
实施步骤
E4.1 矛盾检测
当 commit 新记忆时,检查图谱中是否有同一实体相斥属性:
commit 新记忆 → 解析实体 + 属性 →
查图谱中该实体所有属性 →
如果存在矛盾属性(e.g. "是" vs "不是")→ 标记为矛盾 →
不阻止写入,但记录到矛盾表中
E4.2 跨 agent 知识共享
当 Hermes 找不到答案时,主动查 OpenClaw namespace 的相关记忆:
hermes recall 无结果 → 查 openclaw namespace 相同实体的记忆 →
如有,标记为"跨 agent 共享",合并结果
E4.3 遗忘决策参考图谱
当前遗忘策略只看时间 + 质量分数,加上图谱:
节点度(连接数)高的节点优先保留
跨 namespace 共享的节点不允许遗忘
E4.4 测试验证
# E4.1 矛盾检测
curl -X POST http://localhost:7821/api/v1/commit \
-H "Content-Type: application/json" \
-d '{"content":"小唯是牧尘的女朋友","namespace":"hermes"}'
curl -X POST http://localhost:7821/api/v1/commit \
-H "Content-Type: application/json" \
-d '{"content":"小唯不是牧尘的女朋友","namespace":"hermes"}'
# 验证矛盾标记
curl "http://localhost:7821/api/v1/graph/conflicts?entity=小唯"
# E4.2 跨 agent 共享
curl "http://localhost:7821/api/v1/recall?query=小唯&namespace=hermes&cross_agent=true"
# 应能看到 openclaw 相关的记忆(如果有)
# E4.3 图谱度优先保留
# 验证图谱度高的节点在遗忘测试后仍然存在
验收标准
- 矛盾检测能识别出相斥属性对
- 跨 agent recall 能返回其他 namespace 相关记忆
- 高连接度节点在遗忘后仍存在
E5:产品 UI(长期)
目标
给织忆做一个简单的可视化界面,用于查看记忆、图谱、搜索结果。
现状
- 只能 API 调,没有界面
- 个人用足够,但不方便查看图谱结构
实施步骤
待定,优先级最低。前 4 个阶段完成后再规划。
可能的方案
- 简单 Web UI(React + Go API)
- Obsidian 插件直接可视化
- CLI 增强(tree/graph 可视化)
阶段推进规则
- 必须按顺序完成:E1 → E2 → E3 → E4 → E5
- 每个阶段必须测试验证后才能进入下一阶段
- 禁止跳过测试验证步骤
- 禁止偷懒:实施步骤必须逐条执行
- 禁止随意更改变动设计语言:阶段目标和验收标准锁定
- 如有阻塞,记录到 BLOCKED 章节,继续下一个阶段
BLOCKED(阻塞记录)
| 时间 | 阶段 | 阻塞原因 | 尝试方案 |
|---|---|---|---|
| - | - | 无阻塞 | - |
进度追踪
| 阶段 | 开始时间 | 完成时间 | 状态 |
|---|---|---|---|
| E1 图谱导航激活 | - | - | ⏳ |
| E2 多 agent 命名空间 | - | - | ⏳ |
| E3 增量 embedding | - | - | ⏳ |
| E4 图谱推理 | - | - | ⏳ |
| E5 产品 UI | - | - | ⏳ |
最后更新:2026-05-30