Files
16gagent/memory/registers/memory-routing.md
T
2026-06-06 10:40:48 +08:00

84 lines
3.2 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.
# memory路由策略 — 五套记忆系统统一
> 2026-06-02 建立,2026-06-03 升级(加入 ContextGraph + CodeGraph
## 现状:五套系统
| 系统 | 存储 | 搜索 | 适用 |
|------|------|------|------|
| 文件系统 (memory/) | Markdown 文件 | 文本遍历 / grep | 结构化档案、决策、画像 |
| memory-core | SQLite + FTS5/向量 | `memory_search` | 对话级记忆、语义搜索 |
| TencentDB | SQLite | 插件自动 | 四种记忆分层 |
| 远程记忆服务器 | PostgreSQL + pgvector | API v2 | 跨会话持久化 |
| **ContextGraph** 🆕 | JSON 图文件 | `context-graph.js recall` | Entity-Relation-Observation 结构化记忆 |
| **CodeGraph** 🆕 | SQLite 知识图谱 | `codegraph:search/callers/impact` | 代码符号级结构化记忆 |
## 统一路由策略
```
用户问"记得之前...?" / "代码里怎么..."
┌─────────────────┐
│ 1. memory_search │ ← 默认入口(语义+全文,最快)
│ 命中? │
└────┬────────────┘
├─ 是 → 返回
└─ 否 ↓
┌─────────────────┐
│ 2. 代码相关? │
│ → CodeGraph │ ← 符号搜索 + 调用关系 + 影响分析
│ search/callers │ 适用: "谁调用X" "X在哪定义"
└────┬────────────┘
├─ 是 → 返回
└─ 否 ↓
┌─────────────────┐
│ 3. 结构化记忆? │
│ → ContextGraph │ ← Entity-Relation-Observation 图
│ recall/neighbors│ 适用: 项目决策链路、依赖关系
└────┬────────────┘
├─ 是 → 返回
└─ 否 ↓
┌─────────────────┐
│ 4. ctx_search │ ← context-mode FTS5(已索引的代码/文档)
│ 命中? │
└────┬────────────┘
├─ 是 → 返回
└─ 否 ↓
┌─────────────────┐
│ 5. 文件系统 grep │ ← memory/**/*.md 文本搜索
│ 命中? │
└────┬────────────┘
├─ 是 → 返回
└─ 否 ↓
告知"没有找到相关记录"
```
## 写入路由
```
对话中产生的新信息
┌──────────────────────────────┐
│ 所有写入第一落点: daily/ │
└──────────────────────────────┘
Write Gate 判断
┌────┼────┐
│ │ │
▼ ▼ ▼
偏好 纠正 决策
→registers/prefs →registers/open-loops →vault.md
```
## 注意事项
- **不重复写入** — 同一信息只存一个系统,通过路由分发
- **memory-core 由 OpenClaw 自动维护** — 不手动操作其 SQLite
- **TencentDB 放养** — 它自己跑,不主动维护
- **远程服务器** — `session-compact.sh save` 自动推
- **文件系统是底牌** — 当搜索都失败时手动 grep