openclaw-cortex-memory 0.1.0-Alpha.8 → 0.1.0
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/LICENSE +21 -0
- package/README.md +347 -299
- package/SIGNATURE.md +7 -0
- package/SKILL.md +96 -350
- package/dist/index.d.ts +93 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1234 -1318
- package/dist/index.js.map +1 -1
- package/dist/openclaw.plugin.json +377 -18
- package/dist/src/dedup/three_stage_deduplicator.d.ts.map +1 -1
- package/dist/src/dedup/three_stage_deduplicator.js +13 -3
- package/dist/src/dedup/three_stage_deduplicator.js.map +1 -1
- package/dist/src/engine/memory_engine.d.ts +6 -1
- package/dist/src/engine/memory_engine.d.ts.map +1 -1
- package/dist/src/engine/ts_engine.d.ts +208 -0
- package/dist/src/engine/ts_engine.d.ts.map +1 -1
- package/dist/src/engine/ts_engine.js +1353 -84
- package/dist/src/engine/ts_engine.js.map +1 -1
- package/dist/src/engine/types.d.ts +27 -0
- package/dist/src/engine/types.d.ts.map +1 -1
- package/dist/src/graph/ontology.d.ts +87 -15
- package/dist/src/graph/ontology.d.ts.map +1 -1
- package/dist/src/graph/ontology.js +999 -12
- package/dist/src/graph/ontology.js.map +1 -1
- package/dist/src/net/http_post.d.ts +17 -0
- package/dist/src/net/http_post.d.ts.map +1 -0
- package/dist/src/net/http_post.js +56 -0
- package/dist/src/net/http_post.js.map +1 -0
- package/dist/src/quality/llm_output_validator.d.ts +65 -0
- package/dist/src/quality/llm_output_validator.d.ts.map +1 -0
- package/dist/src/quality/llm_output_validator.js +635 -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 +296 -26
- 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 -42
- package/dist/src/session/session_end.d.ts.map +1 -1
- package/dist/src/session/session_end.js +31 -214
- package/dist/src/session/session_end.js.map +1 -1
- package/dist/src/store/archive_store.d.ts +52 -7
- package/dist/src/store/archive_store.d.ts.map +1 -1
- package/dist/src/store/archive_store.js +526 -96
- package/dist/src/store/archive_store.js.map +1 -1
- package/dist/src/store/embedding_utils.d.ts +32 -0
- package/dist/src/store/embedding_utils.d.ts.map +1 -0
- package/dist/src/store/embedding_utils.js +173 -0
- package/dist/src/store/embedding_utils.js.map +1 -0
- package/dist/src/store/graph_memory_store.d.ts +115 -0
- package/dist/src/store/graph_memory_store.d.ts.map +1 -0
- package/dist/src/store/graph_memory_store.js +1061 -0
- package/dist/src/store/graph_memory_store.js.map +1 -0
- package/dist/src/store/read_store.d.ts +95 -0
- package/dist/src/store/read_store.d.ts.map +1 -1
- package/dist/src/store/read_store.js +2108 -268
- package/dist/src/store/read_store.js.map +1 -1
- package/dist/src/store/vector_store.d.ts +15 -0
- package/dist/src/store/vector_store.d.ts.map +1 -1
- package/dist/src/store/vector_store.js +75 -1
- package/dist/src/store/vector_store.js.map +1 -1
- package/dist/src/store/write_store.d.ts +46 -0
- package/dist/src/store/write_store.d.ts.map +1 -1
- package/dist/src/store/write_store.js +399 -50
- package/dist/src/store/write_store.js.map +1 -1
- package/dist/src/sync/session_sync.d.ts +115 -2
- package/dist/src/sync/session_sync.d.ts.map +1 -1
- package/dist/src/sync/session_sync.js +2497 -44
- package/dist/src/sync/session_sync.js.map +1 -1
- package/dist/src/utils/runtime_env.d.ts +4 -0
- package/dist/src/utils/runtime_env.d.ts.map +1 -0
- package/dist/src/utils/runtime_env.js +51 -0
- package/dist/src/utils/runtime_env.js.map +1 -0
- package/dist/src/wiki/wiki_linter.d.ts +26 -0
- package/dist/src/wiki/wiki_linter.d.ts.map +1 -0
- package/dist/src/wiki/wiki_linter.js +339 -0
- package/dist/src/wiki/wiki_linter.js.map +1 -0
- package/dist/src/wiki/wiki_logger.d.ts +10 -0
- package/dist/src/wiki/wiki_logger.d.ts.map +1 -0
- package/dist/src/wiki/wiki_logger.js +78 -0
- package/dist/src/wiki/wiki_logger.js.map +1 -0
- package/dist/src/wiki/wiki_maintainer.d.ts +39 -0
- package/dist/src/wiki/wiki_maintainer.d.ts.map +1 -0
- package/dist/src/wiki/wiki_maintainer.js +38 -0
- package/dist/src/wiki/wiki_maintainer.js.map +1 -0
- package/dist/src/wiki/wiki_projector.d.ts +35 -0
- package/dist/src/wiki/wiki_projector.d.ts.map +1 -0
- package/dist/src/wiki/wiki_projector.js +1151 -0
- package/dist/src/wiki/wiki_projector.js.map +1 -0
- package/dist/src/wiki/wiki_queue.d.ts +29 -0
- package/dist/src/wiki/wiki_queue.d.ts.map +1 -0
- package/dist/src/wiki/wiki_queue.js +137 -0
- package/dist/src/wiki/wiki_queue.js.map +1 -0
- package/openclaw.plugin.json +377 -18
- package/package.json +52 -5
- package/schema/graph.schema.yaml +330 -0
- package/scripts/cli.js +80 -26
- package/scripts/repair-memory.js +321 -0
- package/scripts/uninstall.js +7 -1
- package/skills/cortex-memory/SKILL.md +83 -0
- package/skills/cortex-memory/references/agent-manual.md +127 -0
- package/skills/cortex-memory/references/configuration.md +109 -0
- package/skills/cortex-memory/references/publish-checklist.md +45 -0
- package/skills/cortex-memory/references/system-prompt-template.md +27 -0
- package/skills/cortex-memory/references/tools.md +191 -0
package/README.md
CHANGED
|
@@ -1,299 +1,347 @@
|
|
|
1
|
-
# OpenClaw Cortex Memory
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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 的长期记忆插件,集成多路检索、事件归档、图谱关系、向量化与反衰减排序,支持历史增量导入、规则反思和可观测诊断,可以将会话中零碎的记忆去噪整理、分层存储,支持对话中自动搜索回忆,吸收了LLM wiki的概念,帮助 Agent 在跨会话中持续积累并稳定调用高价值记忆。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 核心能力
|
|
14
|
+
|
|
15
|
+
### 1) 语义检索
|
|
16
|
+
- 多路召回:`keyword / BM25 / vector / graph` 混合检索
|
|
17
|
+
- 排序融合:加权打分 + RRF + 可选 reranker
|
|
18
|
+
- 结果融合:可选 `readFusion`,支持权威融合返回
|
|
19
|
+
- 调试输出:`search_memory` 返回 `timing_ms` 与 `debug`,可定位检索链路耗时、召回策略与 fusion 模式
|
|
20
|
+
- 检索控制:`fusion_mode` 可按次关闭/强制 fusion,`track_hits: false` 可用于诊断或评测,避免污染 anti-decay 命中统计
|
|
21
|
+
- 通道明细:`search_memory` 保留兼容字段 `semantic_results` / `keyword_results`,同时返回 `channel_results` 区分 `archive/graph/rules/vector/keyword` 等全局通道
|
|
22
|
+
- 图谱边界:`search_memory` 不把 Wiki markdown 当作候选记忆;图谱命中可返回 `wiki_ref` / `wiki_refs` / `evidence_ids` 作为展示和追溯链接,事实来源仍以 `graph/memory.jsonl` 为准
|
|
23
|
+
- 时序建模:`memoryDecay` + 命中反衰减(anti-decay)
|
|
24
|
+
|
|
25
|
+
### 2) 事件存储
|
|
26
|
+
- 分层写入:`active`(会话)与 `archive`(结构化事件)
|
|
27
|
+
- 摘要优先:归档记录保留 `summary` 与 `source_text`
|
|
28
|
+
- 向量分块:支持 summary/evidence 双通道向量记录
|
|
29
|
+
- 增量同步:按状态文件增量导入历史会话
|
|
30
|
+
|
|
31
|
+
### 3) 图谱关系
|
|
32
|
+
- 图谱独立层:`graph/memory.jsonl` 独立于 archive 文本层
|
|
33
|
+
- 关系追溯:每条关系可追溯 `source_event_id`
|
|
34
|
+
- 关系查询:`query_graph` 支持方向、关系类型、路径搜索
|
|
35
|
+
- 冲突治理:单值事实冲突进入队列,支持人工 `accept/reject` 闭环
|
|
36
|
+
- 可视化导出:`export_graph_view` 输出状态化图谱快照(含来源证据)
|
|
37
|
+
- 质量门禁:全局 `graphQualityMode` 支持 `off/warn/strict`;历史导入可用 `syncPolicy.graphQualityMode` 单独收紧
|
|
38
|
+
|
|
39
|
+
### 4) 规则演进
|
|
40
|
+
- 反思沉淀:`reflect_memory` 将事件抽象为规则
|
|
41
|
+
- 去重治理:规则与事件均有去重控制,避免污染
|
|
42
|
+
- 规则复用:规则写入 `CORTEX_RULES.md` 供后续任务复用
|
|
43
|
+
|
|
44
|
+
### 5) 运维诊断
|
|
45
|
+
- `cortex_diagnostics`:模型连通、层级状态、字段对齐检查
|
|
46
|
+
- `backfill_embeddings`:支持 `incremental / vector_only / full`
|
|
47
|
+
- `lint_memory_wiki`:Wiki/图谱一致性、证据完整性与知识页质量巡检
|
|
48
|
+
- 完整状态文件:便于快速定位同步、回填、质量问题
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 已注册工具(与当前代码一致)
|
|
53
|
+
|
|
54
|
+
- `search_memory`
|
|
55
|
+
- `store_event`
|
|
56
|
+
- `query_graph`
|
|
57
|
+
- `export_graph_view`
|
|
58
|
+
- `lint_memory_wiki`
|
|
59
|
+
- `list_graph_conflicts`
|
|
60
|
+
- `resolve_graph_conflict`
|
|
61
|
+
- `get_hot_context`
|
|
62
|
+
- `get_auto_context`
|
|
63
|
+
- `reflect_memory`
|
|
64
|
+
- `sync_memory`
|
|
65
|
+
- `backfill_embeddings`
|
|
66
|
+
- `delete_memory`
|
|
67
|
+
- `cortex_diagnostics`(推荐)
|
|
68
|
+
|
|
69
|
+
### 工具参数速览
|
|
70
|
+
|
|
71
|
+
| 工具 | 关键参数 |
|
|
72
|
+
|------|------|
|
|
73
|
+
| `search_memory` | `query`, `top_k`, `fusion_mode`, `track_hits` |
|
|
74
|
+
| `store_event` | `summary`, `entities`, `entity_types`, `outcome`, `relations` |
|
|
75
|
+
| `query_graph` | `entity`, `rel`, `dir`, `path_to`, `max_depth` |
|
|
76
|
+
| `export_graph_view` | `write_snapshot` |
|
|
77
|
+
| `lint_memory_wiki` | 无 |
|
|
78
|
+
| `list_graph_conflicts` | `status`, `limit` |
|
|
79
|
+
| `resolve_graph_conflict` | `conflict_id`, `action`, `note` |
|
|
80
|
+
| `get_hot_context` | `limit` |
|
|
81
|
+
| `get_auto_context` | `include_hot` |
|
|
82
|
+
| `reflect_memory` | 无 |
|
|
83
|
+
| `sync_memory` | 无 |
|
|
84
|
+
| `backfill_embeddings` | `layer`, `batch_size`, `max_retries`, `retry_failed_only`, `rebuild_mode` |
|
|
85
|
+
| `cortex_diagnostics` | 无 |
|
|
86
|
+
| `delete_memory` | `memory_id` |
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Agent 使用手册(系统提示词)
|
|
91
|
+
|
|
92
|
+
> 可直接粘贴到 Agent 的系统提示词中使用
|
|
93
|
+
|
|
94
|
+
**Cortex Memory 记忆插件使用规则(核心规则,不允许删除)**
|
|
95
|
+
|
|
96
|
+
你已接入 Cortex Memory。必须遵循以下规则:
|
|
97
|
+
|
|
98
|
+
1. 禁止臆造历史事实;凡涉及历史对话、用户偏好、项目既有决策,先检索再回答。
|
|
99
|
+
2. 单个任务内避免频繁写入:`store_event` / `reflect_memory` 应按里程碑触发(通常每个完整任务 0-2 次)。
|
|
100
|
+
3. 用户询问历史信息、偏好、项目上下文时:先调用 `search_memory`,再回答,触发词如“上次、之前、你记得、上个月、去年、上个星期、昨天、前天、我记得、你查一下”等。
|
|
101
|
+
4. 需要当前会话热上下文时:调用 `get_hot_context`。
|
|
102
|
+
5. 需要自动召回相关记忆时:调用 `get_auto_context`。
|
|
103
|
+
6. 需要实体关系、依赖链路或路径关系时:调用 `query_graph`。
|
|
104
|
+
7. 仅在“重要事项已结束且结论明确”后调用 `store_event` 记录结果;结论未定时先不写入。
|
|
105
|
+
8. 当任务经历“失败 -> 调整 -> 成功”时:先用 `store_event` 记录失败原因与成功方案,再调用 `reflect_memory` 沉淀可复用规则。
|
|
106
|
+
9. 需要导入历史会话时:调用 `sync_memory`。
|
|
107
|
+
10. 当 `cortex_diagnostics` 显示 active/archive 有未向量化记录,或迁移后需重建向量层时:调用 `backfill_embeddings`(按需选择 `incremental` / `vector_only` / `full`)。
|
|
108
|
+
11. 出现配置校验失败、记忆读写异常、检索结果异常或数据目录问题时:优先调用 `cortex_diagnostics`。
|
|
109
|
+
12. 仅在用户明确要求删除记忆,且已确认 `memory_id` 时,才调用 `delete_memory`;禁止在未确认情况下自动删除。
|
|
110
|
+
13. 工具调用失败时:读操作可重试一次;写操作(如 `store_event` / `reflect_memory` / `delete_memory` / `resolve_graph_conflict`)重试前先确认是否已成功落库,避免重复写入。
|
|
111
|
+
14. 调用任意 Cortex Memory 工具前,先确认当前运行环境可见该工具;若工具不可见,必须立即报告“当前 lane 不可用”,不得虚构执行结果。
|
|
112
|
+
15. `sync_memory` 与 `backfill_embeddings` 属于关键路径任务:执行前后应避免并发重复触发;若已有同任务进行中,复用当前结果或等待完成。
|
|
113
|
+
16. 当用户明确请求 Cortex Memory 任务(如 `sync_memory` / `search_memory` / `store_event`)时,禁止切换到无关流程(如心跳巡检、日报、闲聊任务);若被系统任务打断,先完成用户请求再处理后台任务。
|
|
114
|
+
17. 当 `query_graph` 返回 `conflict_hint` 时,不得静默覆盖冲突事实;应先调用 `list_graph_conflicts`,并与用户确认后再 `resolve_graph_conflict`。
|
|
115
|
+
18. 需要解释图谱状态分布或排查投影异常时,优先调用 `export_graph_view` 与 `lint_memory_wiki`。
|
|
116
|
+
19. 记忆检索结果与模型推断必须分开表述:可明确标注“来自记忆检索/图谱”与“基于当前信息的推断”。
|
|
117
|
+
20. 涉及隐私或用户明确要求“不要记忆”的内容,禁止调用 `store_event` / `reflect_memory` 写入长期记忆。
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 快速开始
|
|
122
|
+
|
|
123
|
+
### 安装
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
cd ~/openclaw
|
|
127
|
+
openclaw plugins install clawhub:openclaw-cortex-memory
|
|
128
|
+
openclaw plugins enable openclaw-cortex-memory
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
如果 `clawhub:` 安装出现 `fetch failed`,可改用 npm 包本地安装(推荐兜底):
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm pack openclaw-cortex-memory@0.1.0
|
|
135
|
+
openclaw plugins install ./openclaw-cortex-memory-0.1.0.tgz
|
|
136
|
+
openclaw plugins enable openclaw-cortex-memory
|
|
137
|
+
rm ./openclaw-cortex-memory-0.1.0.tgz
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
完成安装后,请先按下方"最小配置"示例配置 `openclaw.json`,确认配置无误后再启动 gateway。
|
|
141
|
+
|
|
142
|
+
### 更新
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
rm -r ~/.openclaw/extensions/openclaw-cortex-memory
|
|
146
|
+
npm pack openclaw-cortex-memory@0.1.0
|
|
147
|
+
openclaw plugins install ./openclaw-cortex-memory-0.1.0.tgz
|
|
148
|
+
openclaw plugins enable openclaw-cortex-memory
|
|
149
|
+
rm ./openclaw-cortex-memory-0.1.0.tgz
|
|
150
|
+
openclaw plugins list --enabled
|
|
151
|
+
openclaw gateway restart
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 卸载
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
cd ~/openclaw
|
|
158
|
+
openclaw plugins disable openclaw-cortex-memory
|
|
159
|
+
openclaw plugins uninstall openclaw-cortex-memory
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
如需卸载插件但保留记忆数据:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
cd ~/openclaw
|
|
166
|
+
openclaw plugins disable openclaw-cortex-memory
|
|
167
|
+
openclaw plugins uninstall openclaw-cortex-memory --keep-data
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 最小配置(推荐先跑起来)
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"plugins": {
|
|
175
|
+
"allow": ["openclaw-cortex-memory"],
|
|
176
|
+
"slots": { "memory": "none" },
|
|
177
|
+
"entries": {
|
|
178
|
+
"memory-core": {
|
|
179
|
+
"enabled": false
|
|
180
|
+
},
|
|
181
|
+
"memory-lancedb": {
|
|
182
|
+
"enabled": false
|
|
183
|
+
},
|
|
184
|
+
"openclaw-cortex-memory": {
|
|
185
|
+
"enabled": true,
|
|
186
|
+
"config": {
|
|
187
|
+
"autoSync": true,
|
|
188
|
+
"autoReflect": false,
|
|
189
|
+
"graphQualityMode": "warn",
|
|
190
|
+
"readFusion": {
|
|
191
|
+
"enabled": true,
|
|
192
|
+
"authoritative": true
|
|
193
|
+
},
|
|
194
|
+
"memoryDecay": {
|
|
195
|
+
"enabled": true,
|
|
196
|
+
"antiDecay": {
|
|
197
|
+
"enabled": true
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"embedding": {
|
|
201
|
+
"provider": "api",
|
|
202
|
+
"model": "text-embedding-3-small",
|
|
203
|
+
"apiKey": "${EMBEDDING_API_KEY}",
|
|
204
|
+
"baseURL": "https://your-embedding-endpoint/v1",
|
|
205
|
+
"dimensions": 1536
|
|
206
|
+
},
|
|
207
|
+
"llm": {
|
|
208
|
+
"provider": "api",
|
|
209
|
+
"model": "gpt-4",
|
|
210
|
+
"apiKey": "${LLM_API_KEY}",
|
|
211
|
+
"baseURL": "https://your-llm-endpoint/v1"
|
|
212
|
+
},
|
|
213
|
+
"reranker": {
|
|
214
|
+
"provider": "api",
|
|
215
|
+
"model": "BAAI/bge-reranker-v2-m3",
|
|
216
|
+
"apiKey": "${RERANKER_API_KEY}",
|
|
217
|
+
"baseURL": "https://your-reranker-endpoint/v1/rerank"
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
独占模式注意事项:
|
|
227
|
+
|
|
228
|
+
- `plugins.slots.memory` 不要设置为 `openclaw-cortex-memory`
|
|
229
|
+
- 建议将 `memory-core` 与 `memory-lancedb` 显式禁用(如上示例),避免多记忆后端并存冲突
|
|
230
|
+
|
|
231
|
+
## 外部端点与凭证声明(审查说明)
|
|
232
|
+
|
|
233
|
+
本插件是本地长期记忆系统,但以下能力依赖用户自配置的外部模型端点:
|
|
234
|
+
|
|
235
|
+
- `embedding`:向量化(`/embeddings`)
|
|
236
|
+
- `llm`:写入门控、规则反思、读融合(`/chat/completions`)
|
|
237
|
+
- `reranker`:候选重排序(`/rerank`)
|
|
238
|
+
|
|
239
|
+
对应凭证要求:
|
|
240
|
+
|
|
241
|
+
- 环境变量(可选):`EMBEDDING_API_KEY`、`LLM_API_KEY`、`RERANKER_API_KEY`
|
|
242
|
+
- 插件配置(常用):`embedding.apiKey`、`llm.apiKey`、`reranker.apiKey`
|
|
243
|
+
- 端点配置:`embedding.baseURL`、`llm.baseURL`、`reranker.baseURL`
|
|
244
|
+
|
|
245
|
+
### 网络发送的数据边界
|
|
246
|
+
|
|
247
|
+
- 会发送:用于模型推理的文本片段(如 query、候选摘要、转写片段、待向量化文本)
|
|
248
|
+
- 不会主动发送:本地配置文件原文、系统环境变量全集、插件状态文件全集
|
|
249
|
+
- 凭证使用方式:仅作为 `Authorization: Bearer` 请求头调用你配置的端点
|
|
250
|
+
|
|
251
|
+
### 风险与建议
|
|
252
|
+
|
|
253
|
+
- 你应只配置可信模型网关,密钥权限最小化(建议专用 key)
|
|
254
|
+
- 生产环境建议启用网关审计与请求日志脱敏
|
|
255
|
+
- 如不希望联网推理,不要配置外部端点/密钥(相关能力将降级或跳过)
|
|
256
|
+
|
|
257
|
+
<details>
|
|
258
|
+
<summary>高级配置(默认已内置,不懂可以不改)</summary>
|
|
259
|
+
|
|
260
|
+
- `readFusion`:融合候选数、通道权重、通道 TopK、最小 lexical/semantic 命中、长度归一
|
|
261
|
+
- `memoryDecay`:最小衰减地板、默认半衰期、事件类型半衰期、anti-decay 参数
|
|
262
|
+
- `vectorChunking`:分块大小、重叠、evidence 最大分块数
|
|
263
|
+
- `writePolicy`:archive/active 质量阈值与文本长度限制
|
|
264
|
+
- `syncPolicy`:历史导入来源与导入期图谱质量门禁
|
|
265
|
+
- `readTuning`:打分权重、RRF 参数、recency 分桶、auto-context 轻量检索
|
|
266
|
+
|
|
267
|
+
`search_memory` 支持按次覆盖读取行为:
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"query": "上次我们怎么处理记忆搜索延迟?",
|
|
272
|
+
"top_k": 5,
|
|
273
|
+
"fusion_mode": "candidates",
|
|
274
|
+
"track_hits": false
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
- `fusion_mode: "auto"`:默认值,遵循 `readFusion.authoritative`
|
|
279
|
+
- `fusion_mode: "authoritative"`:返回融合后的权威结果
|
|
280
|
+
- `fusion_mode: "candidates"`:返回融合结果 + 候选明细,适合调试
|
|
281
|
+
- `fusion_mode: "off"`:关闭 LLM fusion,适合低延迟或诊断
|
|
282
|
+
- `track_hits: false`:不更新 anti-decay 命中统计,适合评测/排查
|
|
283
|
+
|
|
284
|
+
`search_memory` 的 JSONL fallback 向量层会缓存文档、向量 norm 与 source-memory 分组;当 query embedding 可用时,会先按 cosine 预选 topN,再进入 BM25/RRF 混合排序,避免大库下把所有 fallback vector chunk 放进后续排序。中文 n-gram 用于召回扩展,但 BM25 文档 token 保留重复项以维持 term frequency 区分度。
|
|
285
|
+
|
|
286
|
+
`get_auto_context` 使用最近会话消息构造自动查询,并默认走无外部模型调用的 auto 检索路径;显式 `search_memory` 仍使用完整检索链路。消息 hook 仍有短保护窗口,但同一 session 的 on-message 自动检索会做 in-flight 去重,避免超时后后台搜索堆积。
|
|
287
|
+
|
|
288
|
+
</details>
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 数据目录
|
|
293
|
+
|
|
294
|
+
默认情况下(未配置 `dbPath`),数据目录为 OpenClaw workspace 下:
|
|
295
|
+
|
|
296
|
+
- Linux/macOS: `~/.openclaw/workspace/memory/openclaw-cortex-memory`
|
|
297
|
+
- Windows: `%USERPROFILE%\\.openclaw\\workspace\\memory\\openclaw-cortex-memory`
|
|
298
|
+
|
|
299
|
+
如果当前进程无法识别 OpenClaw 基础目录(例如离线脚本直接运行且无相关环境变量),会回退到项目目录:
|
|
300
|
+
|
|
301
|
+
- `<projectRoot>/data/memory`
|
|
302
|
+
|
|
303
|
+
如果在插件配置里设置了 `dbPath`,则以下文件都会写到你指定的 `dbPath` 下:
|
|
304
|
+
|
|
305
|
+
- `<memoryRoot>/CORTEX_RULES.md`
|
|
306
|
+
- `<memoryRoot>/sessions/active/sessions.jsonl`
|
|
307
|
+
- `<memoryRoot>/sessions/archive/sessions.jsonl`
|
|
308
|
+
- `<memoryRoot>/graph/memory.jsonl`
|
|
309
|
+
- `<memoryRoot>/graph/memory.md`
|
|
310
|
+
- `<memoryRoot>/graph/mutation_log.jsonl`
|
|
311
|
+
- `<memoryRoot>/graph/mutation_log.md`
|
|
312
|
+
- `<memoryRoot>/graph/conflict_queue.jsonl`
|
|
313
|
+
- `<memoryRoot>/graph/superseded_relations.jsonl`
|
|
314
|
+
- `<memoryRoot>/wiki/index.md`
|
|
315
|
+
- `<memoryRoot>/wiki/log.md`
|
|
316
|
+
- `<memoryRoot>/wiki/entities/*.md`
|
|
317
|
+
- `<memoryRoot>/wiki/topics/*.md`
|
|
318
|
+
- `<memoryRoot>/wiki/timelines/*.md`
|
|
319
|
+
- `<memoryRoot>/wiki/graph/view.json`
|
|
320
|
+
- `<memoryRoot>/wiki/graph/timeline.jsonl`
|
|
321
|
+
- `<memoryRoot>/wiki/graph/network.mmd`
|
|
322
|
+
- `<memoryRoot>/wiki/graph/network.md`
|
|
323
|
+
- `<memoryRoot>/wiki/.projection_index.json`
|
|
324
|
+
- `<memoryRoot>/wiki/.rebuild_queue.jsonl`
|
|
325
|
+
- `<memoryRoot>/vector/lancedb`
|
|
326
|
+
- `<memoryRoot>/vector/lancedb_events.jsonl`
|
|
327
|
+
- `<memoryRoot>/.sync_state.json`
|
|
328
|
+
- `<memoryRoot>/.session_end_state.json`
|
|
329
|
+
- `<memoryRoot>/.rule_store_state.json`
|
|
330
|
+
- `<memoryRoot>/.dedup_index.json`
|
|
331
|
+
- `<memoryRoot>/.read_hit_stats.json`
|
|
332
|
+
|
|
333
|
+
Wiki 是图谱关系的物化投影,不是独立记忆库。Wiki 投影会为实体页生成 `Current Conclusion`、`Recent Changes`、`High Confidence Facts`、`Evidence Excerpts` 等知识页结构;为主题页生成状态分组;为时间线页生成 `Event Flow`,并在 archive 事件存在时带上 `cause/process/result`。`lint_memory_wiki` 会检查这些结构是否缺失、是否仍停留在旧式泛化 Summary、以及图谱证据是否不足。
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 常用命令
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
npm run typecheck
|
|
341
|
+
npm run test:graph-quality
|
|
342
|
+
npm run test:graph-quality-zh
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
MIT License
|