openclaw-cortex-memory 0.1.0-Alpha.3 → 0.1.0-Alpha.30

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.
Files changed (82) hide show
  1. package/README.md +263 -204
  2. package/SKILL.md +77 -268
  3. package/dist/index.d.ts +92 -22
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1062 -1207
  6. package/dist/index.js.map +1 -1
  7. package/dist/openclaw.plugin.json +384 -15
  8. package/dist/src/dedup/three_stage_deduplicator.d.ts +25 -0
  9. package/dist/src/dedup/three_stage_deduplicator.d.ts.map +1 -0
  10. package/dist/src/dedup/three_stage_deduplicator.js +224 -0
  11. package/dist/src/dedup/three_stage_deduplicator.js.map +1 -0
  12. package/dist/src/engine/memory_engine.d.ts +2 -1
  13. package/dist/src/engine/memory_engine.d.ts.map +1 -1
  14. package/dist/src/engine/ts_engine.d.ts +126 -0
  15. package/dist/src/engine/ts_engine.d.ts.map +1 -1
  16. package/dist/src/engine/ts_engine.js +1145 -44
  17. package/dist/src/engine/ts_engine.js.map +1 -1
  18. package/dist/src/engine/types.d.ts +12 -0
  19. package/dist/src/engine/types.d.ts.map +1 -1
  20. package/dist/src/graph/ontology.d.ts +103 -0
  21. package/dist/src/graph/ontology.d.ts.map +1 -0
  22. package/dist/src/graph/ontology.js +564 -0
  23. package/dist/src/graph/ontology.js.map +1 -0
  24. package/dist/src/net/http_post.d.ts +17 -0
  25. package/dist/src/net/http_post.d.ts.map +1 -0
  26. package/dist/src/net/http_post.js +56 -0
  27. package/dist/src/net/http_post.js.map +1 -0
  28. package/dist/src/quality/llm_output_validator.d.ts +48 -0
  29. package/dist/src/quality/llm_output_validator.d.ts.map +1 -0
  30. package/dist/src/quality/llm_output_validator.js +404 -0
  31. package/dist/src/quality/llm_output_validator.js.map +1 -0
  32. package/dist/src/reflect/reflector.d.ts +7 -0
  33. package/dist/src/reflect/reflector.d.ts.map +1 -1
  34. package/dist/src/reflect/reflector.js +352 -8
  35. package/dist/src/reflect/reflector.js.map +1 -1
  36. package/dist/src/rules/rule_store.d.ts.map +1 -1
  37. package/dist/src/rules/rule_store.js +75 -16
  38. package/dist/src/rules/rule_store.js.map +1 -1
  39. package/dist/src/session/session_end.d.ts +33 -0
  40. package/dist/src/session/session_end.d.ts.map +1 -1
  41. package/dist/src/session/session_end.js +67 -64
  42. package/dist/src/session/session_end.js.map +1 -1
  43. package/dist/src/store/archive_store.d.ts +128 -0
  44. package/dist/src/store/archive_store.d.ts.map +1 -0
  45. package/dist/src/store/archive_store.js +475 -0
  46. package/dist/src/store/archive_store.js.map +1 -0
  47. package/dist/src/store/embedding_utils.d.ts +32 -0
  48. package/dist/src/store/embedding_utils.d.ts.map +1 -0
  49. package/dist/src/store/embedding_utils.js +173 -0
  50. package/dist/src/store/embedding_utils.js.map +1 -0
  51. package/dist/src/store/graph_memory_store.d.ts +44 -0
  52. package/dist/src/store/graph_memory_store.d.ts.map +1 -0
  53. package/dist/src/store/graph_memory_store.js +168 -0
  54. package/dist/src/store/graph_memory_store.js.map +1 -0
  55. package/dist/src/store/read_store.d.ts +86 -0
  56. package/dist/src/store/read_store.d.ts.map +1 -1
  57. package/dist/src/store/read_store.js +1661 -25
  58. package/dist/src/store/read_store.js.map +1 -1
  59. package/dist/src/store/vector_store.d.ts +44 -0
  60. package/dist/src/store/vector_store.d.ts.map +1 -0
  61. package/dist/src/store/vector_store.js +201 -0
  62. package/dist/src/store/vector_store.js.map +1 -0
  63. package/dist/src/store/write_store.d.ts +52 -0
  64. package/dist/src/store/write_store.d.ts.map +1 -1
  65. package/dist/src/store/write_store.js +239 -3
  66. package/dist/src/store/write_store.js.map +1 -1
  67. package/dist/src/sync/session_sync.d.ts +100 -2
  68. package/dist/src/sync/session_sync.d.ts.map +1 -1
  69. package/dist/src/sync/session_sync.js +725 -28
  70. package/dist/src/sync/session_sync.js.map +1 -1
  71. package/dist/src/utils/runtime_env.d.ts +4 -0
  72. package/dist/src/utils/runtime_env.d.ts.map +1 -0
  73. package/dist/src/utils/runtime_env.js +51 -0
  74. package/dist/src/utils/runtime_env.js.map +1 -0
  75. package/openclaw.plugin.json +384 -15
  76. package/package.json +53 -7
  77. package/schema/graph.schema.yaml +175 -0
  78. package/scripts/cli.js +19 -14
  79. package/scripts/repair-memory.js +321 -0
  80. package/scripts/uninstall.js +22 -5
  81. package/index.ts +0 -2142
  82. package/scripts/install.js +0 -27
package/README.md CHANGED
@@ -1,204 +1,263 @@
1
- # OpenClaw Cortex Memory
2
-
3
- OpenClaw 长期记忆插件,提供跨会话检索、事件存储、规则反思、增量同步与运行诊断能力。
4
- 可作为 OpenClaw 的 memory slot 直接接入,支持从历史会话持续沉淀可复用记忆。
5
-
6
- ## 功能特性
7
-
8
- | 特性 | 说明 |
9
- |------|------|
10
- | 语义检索 | `search_memory` 支持 query + top_k |
11
- | 事件存储 | `store_event` 将摘要写入归档 |
12
- | 上下文注入 | `get_hot_context` / `get_auto_context` |
13
- | 增量同步 | `sync_memory` 按状态文件增量导入 |
14
- | 规则演进 | `reflect_memory` 更新 `CORTEX_RULES.md` |
15
- | 运行诊断 | `diagnostics` 检查本地存储状态 |
16
-
17
- ## 安装
18
-
19
- ### 前置要求
20
-
21
- - Node.js 22+
22
- - OpenAI API Key(或其他兼容 API)
23
-
24
- ### 安装步骤
25
-
26
- 快速安装(推荐,npm 发布版):
27
-
28
- ```bash
29
- cd ~/openclaw
30
- pnpm openclaw plugins install openclaw-cortex-memory@alpha
31
- pnpm openclaw plugins enable openclaw-cortex-memory
32
- pnpm openclaw gateway restart
33
- ```
34
-
35
- 后续更新:
36
-
37
- ```bash
38
- cd ~/openclaw
39
- pnpm openclaw plugins install openclaw-cortex-memory@alpha
40
- pnpm openclaw gateway restart
41
- ```
42
-
43
- 安装前如果 `openclaw.json` 已经提前写了 `allow/slots/entries` 指向本插件,先临时移除,安装后再加回,避免安装前校验报 `plugin not found`。
44
-
45
- ### 本地打包安装(源码模式)
46
-
47
- ```bash
48
- git clone https://github.com/deki18/openclaw-cortex-memory.git ~/openclaw-cortex-memory-src
49
- cd ~/openclaw-cortex-memory-src
50
- npm install && npm run build && npm pack
51
- cd ~/openclaw
52
- pnpm openclaw plugins install ~/openclaw-cortex-memory-src/openclaw-cortex-memory-0.1.0-Alpha.1.tgz
53
- pnpm openclaw gateway restart
54
- ```
55
-
56
- ### 本地开发模式(无安装记录)
57
-
58
- ```bash
59
- cd ~/.openclaw/extensions
60
- git clone https://github.com/deki18/openclaw-cortex-memory.git
61
- cd openclaw-cortex-memory
62
- npm install
63
- ```
64
-
65
- `npm install` 会自动执行 TypeScript 构建并生成 `dist/`,但这种方式默认不写 OpenClaw 安装记录。
66
-
67
- ## 配置
68
-
69
- 在 `openclaw.json` 中添加:
70
-
71
- ```json
72
- {
73
- "plugins": {
74
- "slots": { "memory": "openclaw-cortex-memory" },
75
- "entries": {
76
- "openclaw-cortex-memory": {
77
- "enabled": true,
78
- "config": {
79
- "engineMode": "ts",
80
- "dbPath": "<optional-memory-dir>",
81
- "autoSync": true,
82
- "autoReflect": true,
83
- "embedding": {
84
- "provider": "api",
85
- "model": "text-embedding-3-large",
86
- "apiKey": "${EMBEDDING_API_KEY}",
87
- "baseURL": "https://your-embedding-endpoint/v1",
88
- "dimensions": 3072
89
- },
90
- "llm": {
91
- "provider": "api",
92
- "model": "gpt-4",
93
- "apiKey": "${LLM_API_KEY}",
94
- "baseURL": "https://your-llm-endpoint/v1"
95
- },
96
- "reranker": {
97
- "provider": "api",
98
- "model": "BAAI/bge-reranker-v2-m3",
99
- "apiKey": "${RERANKER_API_KEY}",
100
- "baseURL": "https://your-reranker-endpoint/v1/rerank"
101
- }
102
- }
103
- }
104
- }
105
- }
106
- }
107
- ```
108
-
109
- ### 配置项说明
110
-
111
- | 配置项 | 必填 | 说明 |
112
- |--------|------|------|
113
- | `embedding.provider` | 是 | 建议使用 `api`(统一第三方接口模式) |
114
- | `embedding.model` | 是 | 嵌入模型名称 |
115
- | `embedding.dimensions` | 否 | 向量维度,需与模型匹配 |
116
- | `embedding.apiKey` | 是 | Embedding API Key(建议 `${EMBEDDING_API_KEY}`) |
117
- | `embedding.baseURL` | 是 | Embedding API 端点 |
118
- | `llm.provider` | 是 | 建议使用 `api` |
119
- | `llm.model` | 是 | LLM 模型名称 |
120
- | `llm.apiKey` | 是 | LLM API Key(建议 `${LLM_API_KEY}`) |
121
- | `llm.baseURL` | 是 | LLM API 端点 |
122
- | `reranker.provider` | 否 | 建议使用 `api` |
123
- | `reranker.model` | 是 | Reranker 模型名称 |
124
- | `reranker.apiKey` | 是 | Reranker API Key(建议 `${RERANKER_API_KEY}`) |
125
- | `reranker.baseURL` | 是 | Reranker API 端点 |
126
- | `engineMode` | 否 | 固定 `ts` |
127
- | `dbPath` | 否 | 数据目录,默认 `<plugin-dir>/data/memory` |
128
- | `autoSync` | 否 | 会话结束时自动同步历史记录,默认 `true` |
129
- | `autoReflect` | 否 | 自动触发记忆反思,默认 `false` |
130
-
131
- ### 启动
132
-
133
- ```bash
134
- pnpm openclaw config validate
135
- pnpm openclaw gateway restart
136
- ```
137
-
138
- ### 主 Agent 注入说明
139
-
140
- 首次接入后,建议把下面这段发给主 Agent,确保其按记忆工作流执行:
141
-
142
- ```text
143
- 你已接入 Cortex Memory。请遵循以下规则:
144
- 1) 当用户询问历史对话、偏好、项目上下文时,先调用 search_memory 再回答。
145
- 2) 需要当前会话热上下文时调用 get_hot_context。
146
- 3) 需要自动召回相关记忆时调用 get_auto_context。
147
- 4) 在一件重要事情结束并形成明确结果后,再调用 store_event 记录(不要在过程进行中频繁记录)。
148
- 5) 需要实体关联关系时调用 query_graph。
149
- 6) 当任务经历“失败→调整→最终成功”时,优先用 store_event 记录失败原因与成功方案,再调用 reflect_memory 沉淀可复用规则。
150
- 7) 需要导入历史会话时调用 sync_memory。
151
- 8) 出现配置校验失败、记忆读写异常、检索结果异常或数据目录问题时,优先调用 diagnostics。
152
- 9) 同一任务内不要反复调用 store_event 或 reflect_memory;仅在关键节点或任务收尾时触发一次。
153
- 10) 不要臆造历史事实;无法确认时必须先检索。
154
- ```
155
-
156
- ## 可用工具
157
-
158
- | 工具 | 说明 |
159
- |------|------|
160
- | `search_memory` | 语义搜索记忆库,支持 top_k 参数 |
161
- | `store_event` | 存储事件,可包含实体和关系 |
162
- | `query_graph` | 查询实体关系图谱 |
163
- | `get_hot_context` | 获取热上下文(CORTEX_RULES.md + 近期会话) |
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
-
204
- MIT License
1
+ # OpenClaw Cortex Memory
2
+
3
+ OpenClaw 长期记忆插件 - 专为 OpenClaw AI 助手设计的智能记忆系统
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
+ [![Node.js: 22+](https://img.shields.io/badge/Node.js-22+-green.svg)](https://nodejs.org/)
7
+ [![OpenClaw: Plugin](https://img.shields.io/badge/OpenClaw-Plugin-orange.svg)](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
+ ## Agent 使用手册(系统提示词)
73
+
74
+ > 可直接粘贴到 Agent 的系统提示词中使用
75
+
76
+ **Cortex Memory 记忆插件使用规则(核心规则,不允许删除)**
77
+
78
+ 你已接入 Cortex Memory。必须遵循以下规则:
79
+
80
+ 1. 禁止臆造历史事实;凡涉及历史对话、用户偏好、项目既有决策,先检索再回答。
81
+ 2. 单个任务内避免重复写入:`store_event` / `reflect_memory` 仅在关键节点或收尾触发一次。
82
+ 3. 用户询问历史信息、偏好、项目上下文时:先调用 `search_memory`,再回答。
83
+ 4. 需要当前会话热上下文时:调用 `get_hot_context`。
84
+ 5. 需要自动召回相关记忆时:调用 `get_auto_context`。
85
+ 6. 需要实体关系、依赖链路或路径关系时:调用 `query_graph`。
86
+ 7. 仅在“重要事项已结束且结论明确”后调用 `store_event` 记录结果(过程进行中不频繁记录)。
87
+ 8. 当任务经历“失败 -> 调整 -> 成功”时:先用 `store_event` 记录失败原因与成功方案,再调用 `reflect_memory` 沉淀可复用规则。
88
+ 9. 需要导入历史会话时:调用 `sync_memory`。
89
+ 10. 当 `diagnostics` 显示 active/archive 有未向量化记录,或迁移后需重建向量层时:调用 `backfill_embeddings`(按需选择 `incremental` / `vector_only` / `full`)。
90
+ 11. 出现配置校验失败、记忆读写异常、检索结果异常或数据目录问题时:优先调用 `diagnostics`。
91
+ 12. 仅在用户明确要求删除记忆,且已确认 `memory_id` 时,才调用 `delete_memory`;禁止在未确认情况下自动删除。
92
+ 13. 任一工具调用失败时,先重试一次;仍失败则明确告知用户,并基于当前可得上下文继续完成任务。
93
+ 14. 调用任意 Cortex Memory 工具前,先确认当前运行环境可见该工具;若工具不可见,必须立即报告“当前 lane 不可用”,不得虚构执行结果。
94
+ 15. `sync_memory` 属于关键路径任务:执行前后应避免并发重复触发;若已有同任务进行中,复用当前结果或等待完成。
95
+ 16. 当用户明确请求 Cortex Memory 任务(如 `sync_memory` / `search_memory` / `store_event`)时,禁止切换到无关流程(如心跳巡检、日报、闲聊任务);若被系统任务打断,先完成用户请求再处理后台任务。
96
+
97
+ ---
98
+
99
+ ## 快速开始
100
+
101
+ ### 安装
102
+
103
+ ```bash
104
+ cd ~/openclaw
105
+ openclaw plugins install clawhub:openclaw-cortex-memory
106
+ openclaw plugins enable openclaw-cortex-memory
107
+ ```
108
+
109
+ 如果 `clawhub:` 安装出现 `fetch failed`,可改用 npm 包本地安装(推荐兜底):
110
+
111
+ ```bash
112
+ npm pack openclaw-cortex-memory@0.1.0-Alpha.30
113
+ openclaw plugins install ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
114
+ openclaw plugins enable openclaw-cortex-memory
115
+ rm ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
116
+ ```
117
+
118
+ 完成安装后,请先按下方“最小配置”示例配置 `openclaw.json`,确认配置无误后再启动 gateway。
119
+
120
+ ### 更新
121
+
122
+ ```bash
123
+ rm -r ~/.openclaw/extensions/openclaw-cortex-memory
124
+ npm pack openclaw-cortex-memory@0.1.0-Alpha.30
125
+ openclaw plugins install ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
126
+ openclaw plugins enable openclaw-cortex-memory
127
+ rm ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
128
+ openclaw plugins list
129
+ openclaw gateway restart
130
+ ```
131
+
132
+ ### 卸载
133
+
134
+ ```bash
135
+ cd ~/openclaw
136
+ openclaw plugins disable openclaw-cortex-memory
137
+ openclaw plugins uninstall openclaw-cortex-memory
138
+ ```
139
+
140
+ 如需卸载插件但保留记忆数据:
141
+
142
+ ```bash
143
+ cd ~/openclaw
144
+ openclaw plugins disable openclaw-cortex-memory
145
+ openclaw plugins uninstall openclaw-cortex-memory --keep-data
146
+ ```
147
+
148
+ ### 最小配置(推荐先跑起来)
149
+
150
+ ```json
151
+ {
152
+ "plugins": {
153
+ "allow": ["openclaw-cortex-memory"],
154
+ "slots": { "memory": "none" },
155
+ "entries": {
156
+ "openclaw-cortex-memory": {
157
+ "enabled": true,
158
+ "config": {
159
+ "autoSync": true,
160
+ "autoReflect": false,
161
+ "graphQualityMode": "warn",
162
+ "embedding": {
163
+ "provider": "api",
164
+ "model": "text-embedding-3-large",
165
+ "apiKey": "${EMBEDDING_API_KEY}",
166
+ "baseURL": "https://your-embedding-endpoint/v1",
167
+ "dimensions": 3072
168
+ },
169
+ "llm": {
170
+ "provider": "api",
171
+ "model": "gpt-4",
172
+ "apiKey": "${LLM_API_KEY}",
173
+ "baseURL": "https://your-llm-endpoint/v1"
174
+ },
175
+ "reranker": {
176
+ "provider": "api",
177
+ "model": "BAAI/bge-reranker-v2-m3",
178
+ "apiKey": "${RERANKER_API_KEY}",
179
+ "baseURL": "https://your-reranker-endpoint/v1/rerank"
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ ## 外部端点与凭证声明(审查说明)
189
+
190
+ 本插件是本地长期记忆系统,但以下能力依赖用户自配置的外部模型端点:
191
+
192
+ - `embedding`:向量化(`/embeddings`)
193
+ - `llm`:写入门控、规则反思、读融合(`/chat/completions`)
194
+ - `reranker`:候选重排序(`/rerank`)
195
+
196
+ 对应凭证要求:
197
+
198
+ - 环境变量(可选):`EMBEDDING_API_KEY`、`LLM_API_KEY`、`RERANKER_API_KEY`
199
+ - 插件配置(常用):`embedding.apiKey`、`llm.apiKey`、`reranker.apiKey`
200
+ - 端点配置:`embedding.baseURL`、`llm.baseURL`、`reranker.baseURL`
201
+
202
+ ### 网络发送的数据边界
203
+
204
+ - 会发送:用于模型推理的文本片段(如 query、候选摘要、转写片段、待向量化文本)
205
+ - 不会主动发送:本地配置文件原文、系统环境变量全集、插件状态文件全集
206
+ - 凭证使用方式:仅作为 `Authorization: Bearer` 请求头调用你配置的端点
207
+
208
+ ### 风险与建议
209
+
210
+ - 你应只配置可信模型网关,密钥权限最小化(建议专用 key)
211
+ - 生产环境建议启用网关审计与请求日志脱敏
212
+ - 如不希望联网推理,不要配置外部端点/密钥(相关能力将降级或跳过)
213
+
214
+ <details>
215
+ <summary>高级配置(默认已内置,不懂可以不改)</summary>
216
+
217
+ - `readFusion`:融合候选数、通道权重、通道 TopK、最小 lexical/semantic 命中、长度归一
218
+ - `memoryDecay`:最小衰减地板、默认半衰期、事件类型半衰期、anti-decay 参数
219
+ - `vectorChunking`:分块大小、重叠、evidence 最大分块数
220
+ - `writePolicy`:archive/active 质量阈值与文本长度限制
221
+ - `readTuning`:打分权重、RRF 参数、recency 分桶、auto-context 轻量检索
222
+
223
+ </details>
224
+
225
+ ---
226
+
227
+ ## 数据目录
228
+
229
+ 默认情况下(未配置 `dbPath`),数据目录为:
230
+
231
+ - Linux: `~/.openclaw/extensions/openclaw-cortex-memory/data/memory`
232
+ - macOS: `~/.openclaw/extensions/openclaw-cortex-memory/data/memory`
233
+ - Windows: `%USERPROFILE%\\.openclaw\\extensions\\openclaw-cortex-memory\\data\\memory`
234
+
235
+ 如果在插件配置里设置了 `dbPath`,则以下文件都会写到你指定的 `dbPath` 下:
236
+
237
+ - `<memoryRoot>/MEMORY.md`
238
+ - `<memoryRoot>/CORTEX_RULES.md`
239
+ - `<memoryRoot>/sessions/active/sessions.jsonl`
240
+ - `<memoryRoot>/sessions/archive/sessions.jsonl`
241
+ - `<memoryRoot>/graph/memory.jsonl`
242
+ - `<memoryRoot>/graph/mutation_log.jsonl`
243
+ - `<memoryRoot>/vector/lancedb`
244
+ - `<memoryRoot>/vector/lancedb_events.jsonl`
245
+ - `<memoryRoot>/.sync_state.json`
246
+ - `<memoryRoot>/.session_end_state.json`
247
+ - `<memoryRoot>/.rule_store_state.json`
248
+ - `<memoryRoot>/.dedup_index.json`
249
+ - `<memoryRoot>/.read_hit_stats.json`
250
+
251
+ ---
252
+
253
+ ## 常用命令
254
+
255
+ ```bash
256
+ npm run typecheck
257
+ npm run test:graph-quality
258
+ npm run test:graph-quality-zh
259
+ ```
260
+
261
+ ---
262
+
263
+ MIT License