openclaw-cortex-memory 0.1.0-Alpha.2 → 0.1.0-Alpha.21
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 +163 -203
- package/SKILL.md +71 -268
- package/dist/index.d.ts +88 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +859 -1189
- package/dist/index.js.map +1 -1
- package/dist/openclaw.plugin.json +362 -14
- package/dist/src/dedup/three_stage_deduplicator.d.ts +25 -0
- package/dist/src/dedup/three_stage_deduplicator.d.ts.map +1 -0
- package/dist/src/dedup/three_stage_deduplicator.js +224 -0
- package/dist/src/dedup/three_stage_deduplicator.js.map +1 -0
- package/dist/src/engine/memory_engine.d.ts +2 -1
- package/dist/src/engine/memory_engine.d.ts.map +1 -1
- package/dist/src/engine/ts_engine.d.ts +126 -0
- package/dist/src/engine/ts_engine.d.ts.map +1 -1
- package/dist/src/engine/ts_engine.js +1172 -44
- package/dist/src/engine/ts_engine.js.map +1 -1
- package/dist/src/engine/types.d.ts +12 -0
- package/dist/src/engine/types.d.ts.map +1 -1
- package/dist/src/graph/ontology.d.ts +103 -0
- package/dist/src/graph/ontology.d.ts.map +1 -0
- package/dist/src/graph/ontology.js +564 -0
- package/dist/src/graph/ontology.js.map +1 -0
- 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 +7 -0
- package/dist/src/reflect/reflector.d.ts.map +1 -1
- package/dist/src/reflect/reflector.js +358 -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 +33 -0
- package/dist/src/session/session_end.d.ts.map +1 -1
- package/dist/src/session/session_end.js +67 -64
- package/dist/src/session/session_end.js.map +1 -1
- package/dist/src/store/archive_store.d.ts +128 -0
- package/dist/src/store/archive_store.d.ts.map +1 -0
- package/dist/src/store/archive_store.js +481 -0
- package/dist/src/store/archive_store.js.map +1 -0
- 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 +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 +86 -0
- package/dist/src/store/read_store.d.ts.map +1 -1
- package/dist/src/store/read_store.js +1681 -25
- package/dist/src/store/read_store.js.map +1 -1
- package/dist/src/store/vector_store.d.ts +44 -0
- package/dist/src/store/vector_store.d.ts.map +1 -0
- package/dist/src/store/vector_store.js +201 -0
- package/dist/src/store/vector_store.js.map +1 -0
- package/dist/src/store/write_store.d.ts +52 -0
- package/dist/src/store/write_store.d.ts.map +1 -1
- package/dist/src/store/write_store.js +245 -3
- package/dist/src/store/write_store.js.map +1 -1
- package/dist/src/sync/session_sync.d.ts +100 -2
- package/dist/src/sync/session_sync.d.ts.map +1 -1
- package/dist/src/sync/session_sync.js +673 -22
- 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/openclaw.plugin.json +362 -14
- package/package.json +23 -6
- package/scripts/cli.js +19 -14
- package/scripts/uninstall.js +22 -5
- package/index.ts +0 -2092
- package/scripts/install.js +0 -27
package/README.md
CHANGED
|
@@ -1,204 +1,164 @@
|
|
|
1
|
-
# OpenClaw Cortex Memory
|
|
2
|
-
|
|
3
|
-
OpenClaw
|
|
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-
|
|
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
|
-
| `get_auto_context` | 自动检索相关记忆 + 热上下文 |
|
|
165
|
-
| `reflect_memory` | 触发记忆反思,将事件转化为规则 |
|
|
166
|
-
| `sync_memory` | 同步 OpenClaw 历史会话(增量) |
|
|
167
|
-
| `delete_memory` | 删除指定记忆 |
|
|
168
|
-
| `diagnostics` | 系统诊断 |
|
|
169
|
-
|
|
170
|
-
## CLI 命令
|
|
171
|
-
|
|
172
|
-
CLI 命令需在插件目录运行:
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
npx cortex-memory status # 查看插件状态
|
|
176
|
-
npx cortex-memory enable # 启用插件
|
|
177
|
-
npx cortex-memory disable # 禁用插件(回退到内置记忆)
|
|
178
|
-
npx cortex-memory uninstall # 卸载插件
|
|
179
|
-
npx cortex-memory uninstall --keep-data # 卸载但保留数据
|
|
180
|
-
npx cortex-memory help # 查看命令帮助
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## 数据存储
|
|
184
|
-
|
|
185
|
-
| 路径 | 说明 |
|
|
186
|
-
|------|------|
|
|
187
|
-
| `<dbPath>/MEMORY.md` | 记忆说明 |
|
|
188
|
-
| `<dbPath>/CORTEX_RULES.md` | 规则文件 |
|
|
189
|
-
| `<dbPath>/sessions/active/sessions.jsonl` | 活跃会话 |
|
|
190
|
-
| `<dbPath>/sessions/archive/sessions.jsonl` | 归档事件 |
|
|
191
|
-
| `<dbPath>/.sync_state.json` | 同步增量状态 |
|
|
192
|
-
| `<dbPath>/.session_end_state.json` | session_end 幂等状态 |
|
|
193
|
-
| `<dbPath>/.rule_store_state.json` | 规则去重状态 |
|
|
194
|
-
|
|
195
|
-
## 注意事项
|
|
196
|
-
|
|
197
|
-
1. **API Key 安全**:使用环境变量 `${OPENAI_API_KEY}` 而非硬编码
|
|
198
|
-
2. **向量维度**:必须与嵌入模型匹配,如 `text-embedding-3-large` 为 3072
|
|
199
|
-
3. **重排序**:可选配置 `reranker` 以提升检索精度
|
|
200
|
-
4. **单栈运行**:当前版本为纯 TS,无 Python 运行时依赖
|
|
201
|
-
|
|
202
|
-
## 许可证
|
|
203
|
-
|
|
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
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"plugins": {
|
|
88
|
+
"allow": ["openclaw-cortex-memory"],
|
|
89
|
+
"slots": { "memory": "openclaw-cortex-memory" },
|
|
90
|
+
"entries": {
|
|
91
|
+
"openclaw-cortex-memory": {
|
|
92
|
+
"enabled": true,
|
|
93
|
+
"config": {
|
|
94
|
+
"autoSync": true,
|
|
95
|
+
"autoReflect": false,
|
|
96
|
+
"graphQualityMode": "warn",
|
|
97
|
+
"embedding": {
|
|
98
|
+
"provider": "api",
|
|
99
|
+
"model": "text-embedding-3-large",
|
|
100
|
+
"apiKey": "${EMBEDDING_API_KEY}",
|
|
101
|
+
"baseURL": "https://your-embedding-endpoint/v1",
|
|
102
|
+
"dimensions": 3072
|
|
103
|
+
},
|
|
104
|
+
"llm": {
|
|
105
|
+
"provider": "api",
|
|
106
|
+
"model": "gpt-4",
|
|
107
|
+
"apiKey": "${LLM_API_KEY}",
|
|
108
|
+
"baseURL": "https://your-llm-endpoint/v1"
|
|
109
|
+
},
|
|
110
|
+
"reranker": {
|
|
111
|
+
"provider": "api",
|
|
112
|
+
"model": "BAAI/bge-reranker-v2-m3",
|
|
113
|
+
"apiKey": "${RERANKER_API_KEY}",
|
|
114
|
+
"baseURL": "https://your-reranker-endpoint/v1/rerank"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
<details>
|
|
124
|
+
<summary>高级配置(默认已内置,不懂可以不改)</summary>
|
|
125
|
+
|
|
126
|
+
- `readFusion`:融合候选数、通道权重、通道 TopK、最小 lexical/semantic 命中、长度归一
|
|
127
|
+
- `memoryDecay`:最小衰减地板、默认半衰期、事件类型半衰期、anti-decay 参数
|
|
128
|
+
- `vectorChunking`:分块大小、重叠、evidence 最大分块数
|
|
129
|
+
- `writePolicy`:archive/active 质量阈值与文本长度限制
|
|
130
|
+
- `readTuning`:打分权重、RRF 参数、recency 分桶、auto-context 轻量检索
|
|
131
|
+
|
|
132
|
+
</details>
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 数据目录
|
|
137
|
+
|
|
138
|
+
- `<dbPath>/MEMORY.md`
|
|
139
|
+
- `<dbPath>/CORTEX_RULES.md`
|
|
140
|
+
- `<dbPath>/sessions/active/sessions.jsonl`
|
|
141
|
+
- `<dbPath>/sessions/archive/sessions.jsonl`
|
|
142
|
+
- `<dbPath>/graph/memory.jsonl`
|
|
143
|
+
- `<dbPath>/graph/mutation_log.jsonl`
|
|
144
|
+
- `<dbPath>/vector/lancedb`
|
|
145
|
+
- `<dbPath>/vector/lancedb_events.jsonl`
|
|
146
|
+
- `<dbPath>/.sync_state.json`
|
|
147
|
+
- `<dbPath>/.session_end_state.json`
|
|
148
|
+
- `<dbPath>/.rule_store_state.json`
|
|
149
|
+
- `<dbPath>/.dedup_index.json`
|
|
150
|
+
- `<dbPath>/.read_hit_stats.json`
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 常用命令
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
npm run typecheck
|
|
158
|
+
npm run test:graph-quality
|
|
159
|
+
npm run test:graph-quality-zh
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
204
164
|
MIT License
|