openclaw-cortex-memory 0.1.0-Alpha.20 → 0.1.0-Alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -228
- package/SKILL.md +71 -332
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +194 -6
- package/dist/index.js.map +1 -1
- package/dist/openclaw.plugin.json +208 -12
- package/dist/src/dedup/three_stage_deduplicator.d.ts.map +1 -1
- package/dist/src/dedup/three_stage_deduplicator.js +1 -2
- package/dist/src/dedup/three_stage_deduplicator.js.map +1 -1
- package/dist/src/engine/ts_engine.d.ts +31 -0
- package/dist/src/engine/ts_engine.d.ts.map +1 -1
- package/dist/src/engine/ts_engine.js +262 -14
- package/dist/src/engine/ts_engine.js.map +1 -1
- package/dist/src/engine/types.d.ts +1 -0
- package/dist/src/engine/types.d.ts.map +1 -1
- package/dist/src/graph/ontology.d.ts +65 -15
- package/dist/src/graph/ontology.d.ts.map +1 -1
- package/dist/src/graph/ontology.js +316 -4
- package/dist/src/graph/ontology.js.map +1 -1
- package/dist/src/quality/llm_output_validator.d.ts +48 -0
- package/dist/src/quality/llm_output_validator.d.ts.map +1 -0
- package/dist/src/quality/llm_output_validator.js +404 -0
- package/dist/src/quality/llm_output_validator.js.map +1 -0
- package/dist/src/reflect/reflector.d.ts.map +1 -1
- package/dist/src/reflect/reflector.js +284 -8
- package/dist/src/reflect/reflector.js.map +1 -1
- package/dist/src/rules/rule_store.d.ts.map +1 -1
- package/dist/src/rules/rule_store.js +75 -16
- package/dist/src/rules/rule_store.js.map +1 -1
- package/dist/src/session/session_end.d.ts +20 -43
- package/dist/src/session/session_end.d.ts.map +1 -1
- package/dist/src/session/session_end.js +21 -233
- package/dist/src/session/session_end.js.map +1 -1
- package/dist/src/store/archive_store.d.ts +20 -7
- package/dist/src/store/archive_store.d.ts.map +1 -1
- package/dist/src/store/archive_store.js +96 -61
- package/dist/src/store/archive_store.js.map +1 -1
- package/dist/src/store/graph_memory_store.d.ts +44 -0
- package/dist/src/store/graph_memory_store.d.ts.map +1 -0
- package/dist/src/store/graph_memory_store.js +168 -0
- package/dist/src/store/graph_memory_store.js.map +1 -0
- package/dist/src/store/read_store.d.ts +27 -0
- package/dist/src/store/read_store.d.ts.map +1 -1
- package/dist/src/store/read_store.js +653 -94
- package/dist/src/store/read_store.js.map +1 -1
- package/dist/src/store/vector_store.d.ts +1 -0
- package/dist/src/store/vector_store.d.ts.map +1 -1
- package/dist/src/store/vector_store.js +1 -0
- package/dist/src/store/vector_store.js.map +1 -1
- package/dist/src/store/write_store.d.ts +7 -0
- package/dist/src/store/write_store.d.ts.map +1 -1
- package/dist/src/store/write_store.js +15 -3
- package/dist/src/store/write_store.js.map +1 -1
- package/dist/src/sync/session_sync.d.ts +48 -0
- package/dist/src/sync/session_sync.d.ts.map +1 -1
- package/dist/src/sync/session_sync.js +277 -78
- package/dist/src/sync/session_sync.js.map +1 -1
- package/openclaw.plugin.json +208 -12
- package/package.json +22 -18
package/README.md
CHANGED
|
@@ -1,229 +1,182 @@
|
|
|
1
|
-
# OpenClaw Cortex Memory
|
|
2
|
-
|
|
3
|
-
OpenClaw 长期记忆插件 - 专为 OpenClaw AI 助手设计的智能记忆系统
|
|
4
|
-
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://nodejs.org/)
|
|
7
|
-
[](https://github.com/openclaw)
|
|
8
|
-
|
|
9
|
-
面向 OpenClaw 的长期记忆插件,集成多路检索、事件归档、图谱关系、向量化与反衰减排序,支持历史增量导入、规则反思和可观测诊断,帮助 Agent 在跨会话中持续积累并稳定调用高价值记忆。
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
###
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
"
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|------|------|
|
|
183
|
-
| `<dbPath>/MEMORY.md` | 记忆说明 |
|
|
184
|
-
| `<dbPath>/CORTEX_RULES.md` | 规则文件 |
|
|
185
|
-
| `<dbPath>/sessions/active/sessions.jsonl` | 活跃会话 |
|
|
186
|
-
| `<dbPath>/sessions/archive/sessions.jsonl` | 归档事件 |
|
|
187
|
-
| `<dbPath>/vector/lancedb` | LanceDB 向量表(可用时) |
|
|
188
|
-
| `<dbPath>/vector/lancedb_events.jsonl` | 向量回退存储(LanceDB不可用时) |
|
|
189
|
-
| `<dbPath>/.sync_state.json` | 同步增量状态 |
|
|
190
|
-
| `<dbPath>/.session_end_state.json` | session_end 幂等状态 |
|
|
191
|
-
| `<dbPath>/.rule_store_state.json` | 规则去重状态 |
|
|
192
|
-
| `<dbPath>/.dedup_index.json` | 三阶段去重索引 |
|
|
193
|
-
| `<dbPath>/.read_hit_stats.json` | 检索命中频次统计(用于反衰减增益) |
|
|
194
|
-
| `<dbPath>/graph/mutation_log.jsonl` | 图谱写入审计日志 |
|
|
195
|
-
|
|
196
|
-
---
|
|
197
|
-
|
|
198
|
-
## 📋 核心特点
|
|
199
|
-
|
|
200
|
-
- **分层记忆**: 把"原始会话、结构化事件、抽象规则"拆分存储,便于分别检索与治理
|
|
201
|
-
- **图谱派生**: 实体关系来自事件层的 `entities` / `relations`,查询时动态生成图结构
|
|
202
|
-
- **会话结束写入**: message hook 默认仅缓存,会在 `session_end` 后批量抽取并落盘
|
|
203
|
-
- **严格导入门禁**: 历史导入内容必须经 LLM 提取判定后才写入事件层与图谱层
|
|
204
|
-
- **三阶段去重**: SimHash 预过滤 → MinHash 精比对 → 向量余弦相似度
|
|
205
|
-
- **自动演进**: 可结合 `autoSync`、`autoReflect` 持续把会话经验转化为长期可复用记忆
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## ⚠️ 注意事项
|
|
210
|
-
|
|
211
|
-
1. **API Key 安全**: 使用 `${EMBEDDING_API_KEY}`、`${LLM_API_KEY}`、`${RERANKER_API_KEY}` 等环境变量而非硬编码
|
|
212
|
-
2. **向量维度**: 必须与嵌入模型匹配,如 `text-embedding-3-large` 为 3072
|
|
213
|
-
3. **重排序**: 可选配置 `reranker` 以提升检索精度
|
|
214
|
-
4. **外部传输**: 检索与反思会调用你配置的 embedding/llm/reranker endpoint,请使用可信服务并最小化密钥权限
|
|
215
|
-
5. **会话数据**: 启用 `autoSync` 时会读取 OpenClaw 会话文件并写入本地记忆目录,生产环境建议先小范围验证
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## � 致谢
|
|
220
|
-
|
|
221
|
-
感谢 [memory-lancedb-pro](https://github.com/CortexReach/memory-lancedb-pro) 项目作者,本插件的核心想法借鉴了该项目。
|
|
222
|
-
|
|
223
|
-
---
|
|
224
|
-
|
|
225
|
-
## �📄 许可证
|
|
226
|
-
|
|
1
|
+
# OpenClaw Cortex Memory
|
|
2
|
+
|
|
3
|
+
OpenClaw 长期记忆插件 - 专为 OpenClaw AI 助手设计的智能记忆系统
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
[](https://github.com/openclaw)
|
|
8
|
+
|
|
9
|
+
面向 OpenClaw 的长期记忆插件,集成多路检索、事件归档、图谱关系、向量化与反衰减排序,支持历史增量导入、规则反思和可观测诊断,帮助 Agent 在跨会话中持续积累并稳定调用高价值记忆。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 核心能力
|
|
14
|
+
|
|
15
|
+
### 1) 语义检索
|
|
16
|
+
- 多路召回:`keyword / BM25 / vector / graph` 混合检索
|
|
17
|
+
- 排序融合:加权打分 + RRF + 可选 reranker
|
|
18
|
+
- 结果融合:可选 `readFusion`,支持权威融合返回
|
|
19
|
+
- 时序建模:`memoryDecay` + 命中反衰减(anti-decay)
|
|
20
|
+
|
|
21
|
+
### 2) 事件存储
|
|
22
|
+
- 分层写入:`active`(会话)与 `archive`(结构化事件)
|
|
23
|
+
- 摘要优先:归档记录保留 `summary` 与 `source_text`
|
|
24
|
+
- 向量分块:支持 summary/evidence 双通道向量记录
|
|
25
|
+
- 增量同步:按状态文件增量导入历史会话
|
|
26
|
+
|
|
27
|
+
### 3) 图谱关系
|
|
28
|
+
- 图谱独立层:`graph/memory.jsonl` 独立于 archive 文本层
|
|
29
|
+
- 关系追溯:每条关系可追溯 `source_event_id`
|
|
30
|
+
- 关系查询:`query_graph` 支持方向、关系类型、路径搜索
|
|
31
|
+
- 质量门禁:`graphQualityMode` 支持 `off/warn/strict`
|
|
32
|
+
|
|
33
|
+
### 4) 规则演进
|
|
34
|
+
- 反思沉淀:`reflect_memory` 将事件抽象为规则
|
|
35
|
+
- 去重治理:规则与事件均有去重控制,避免污染
|
|
36
|
+
- 规则复用:规则写入 `CORTEX_RULES.md` 供后续任务复用
|
|
37
|
+
|
|
38
|
+
### 5) 运维诊断
|
|
39
|
+
- `diagnostics`:模型连通、层级状态、字段对齐检查
|
|
40
|
+
- `backfill_embeddings`:支持 `incremental / vector_only / full`
|
|
41
|
+
- 完整状态文件:便于快速定位同步、回填、质量问题
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 已注册工具(与当前代码一致)
|
|
46
|
+
|
|
47
|
+
- `search_memory`
|
|
48
|
+
- `store_event`
|
|
49
|
+
- `query_graph`
|
|
50
|
+
- `get_hot_context`
|
|
51
|
+
- `get_auto_context`
|
|
52
|
+
- `reflect_memory`
|
|
53
|
+
- `sync_memory`
|
|
54
|
+
- `backfill_embeddings`
|
|
55
|
+
- `delete_memory`
|
|
56
|
+
- `diagnostics`
|
|
57
|
+
|
|
58
|
+
### 工具参数速览
|
|
59
|
+
|
|
60
|
+
| 工具 | 关键参数 |
|
|
61
|
+
|------|------|
|
|
62
|
+
| `search_memory` | `query`, `top_k` |
|
|
63
|
+
| `store_event` | `summary`, `entities`, `entity_types`, `outcome`, `relations` |
|
|
64
|
+
| `query_graph` | `entity`, `rel`, `dir`, `path_to`, `max_depth` |
|
|
65
|
+
| `get_hot_context` | `limit` |
|
|
66
|
+
| `get_auto_context` | `include_hot` |
|
|
67
|
+
| `backfill_embeddings` | `layer`, `batch_size`, `max_retries`, `retry_failed_only`, `rebuild_mode` |
|
|
68
|
+
| `delete_memory` | `memory_id` |
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 快速开始
|
|
73
|
+
|
|
74
|
+
### 安装
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cd ~/openclaw
|
|
78
|
+
openclaw plugins install clawhub:openclaw-cortex-memory
|
|
79
|
+
openclaw plugins enable openclaw-cortex-memory
|
|
80
|
+
openclaw gateway restart
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 卸载
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
cd ~/openclaw
|
|
87
|
+
openclaw plugins disable openclaw-cortex-memory
|
|
88
|
+
openclaw plugins uninstall openclaw-cortex-memory
|
|
89
|
+
openclaw gateway restart
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
如需卸载插件但保留记忆数据:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
cd ~/openclaw
|
|
96
|
+
openclaw plugins disable openclaw-cortex-memory
|
|
97
|
+
openclaw plugins uninstall openclaw-cortex-memory --keep-data
|
|
98
|
+
openclaw gateway restart
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 最小配置(推荐先跑起来)
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"plugins": {
|
|
106
|
+
"allow": ["openclaw-cortex-memory"],
|
|
107
|
+
"slots": { "memory": "openclaw-cortex-memory" },
|
|
108
|
+
"entries": {
|
|
109
|
+
"openclaw-cortex-memory": {
|
|
110
|
+
"enabled": true,
|
|
111
|
+
"config": {
|
|
112
|
+
"autoSync": true,
|
|
113
|
+
"autoReflect": false,
|
|
114
|
+
"graphQualityMode": "warn",
|
|
115
|
+
"embedding": {
|
|
116
|
+
"provider": "api",
|
|
117
|
+
"model": "text-embedding-3-large",
|
|
118
|
+
"apiKey": "${EMBEDDING_API_KEY}",
|
|
119
|
+
"baseURL": "https://your-embedding-endpoint/v1",
|
|
120
|
+
"dimensions": 3072
|
|
121
|
+
},
|
|
122
|
+
"llm": {
|
|
123
|
+
"provider": "api",
|
|
124
|
+
"model": "gpt-4",
|
|
125
|
+
"apiKey": "${LLM_API_KEY}",
|
|
126
|
+
"baseURL": "https://your-llm-endpoint/v1"
|
|
127
|
+
},
|
|
128
|
+
"reranker": {
|
|
129
|
+
"provider": "api",
|
|
130
|
+
"model": "BAAI/bge-reranker-v2-m3",
|
|
131
|
+
"apiKey": "${RERANKER_API_KEY}",
|
|
132
|
+
"baseURL": "https://your-reranker-endpoint/v1/rerank"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
<details>
|
|
142
|
+
<summary>高级配置(默认已内置,不懂可以不改)</summary>
|
|
143
|
+
|
|
144
|
+
- `readFusion`:融合候选数、通道权重、通道 TopK、最小 lexical/semantic 命中、长度归一
|
|
145
|
+
- `memoryDecay`:最小衰减地板、默认半衰期、事件类型半衰期、anti-decay 参数
|
|
146
|
+
- `vectorChunking`:分块大小、重叠、evidence 最大分块数
|
|
147
|
+
- `writePolicy`:archive/active 质量阈值与文本长度限制
|
|
148
|
+
- `readTuning`:打分权重、RRF 参数、recency 分桶、auto-context 轻量检索
|
|
149
|
+
|
|
150
|
+
</details>
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 数据目录
|
|
155
|
+
|
|
156
|
+
- `<dbPath>/MEMORY.md`
|
|
157
|
+
- `<dbPath>/CORTEX_RULES.md`
|
|
158
|
+
- `<dbPath>/sessions/active/sessions.jsonl`
|
|
159
|
+
- `<dbPath>/sessions/archive/sessions.jsonl`
|
|
160
|
+
- `<dbPath>/graph/memory.jsonl`
|
|
161
|
+
- `<dbPath>/graph/mutation_log.jsonl`
|
|
162
|
+
- `<dbPath>/vector/lancedb`
|
|
163
|
+
- `<dbPath>/vector/lancedb_events.jsonl`
|
|
164
|
+
- `<dbPath>/.sync_state.json`
|
|
165
|
+
- `<dbPath>/.session_end_state.json`
|
|
166
|
+
- `<dbPath>/.rule_store_state.json`
|
|
167
|
+
- `<dbPath>/.dedup_index.json`
|
|
168
|
+
- `<dbPath>/.read_hit_stats.json`
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 常用命令
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
npm run typecheck
|
|
176
|
+
npm run test:graph-quality
|
|
177
|
+
npm run test:graph-quality-zh
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
227
182
|
MIT License
|
|
228
|
-
|
|
229
|
-
发布签名见 [SIGNATURE.md](SIGNATURE.md)
|