lingshu-skill 5.41.0 → 5.42.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/CHANGELOG.md +15 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +1 -1
- package/docs//345/276/205/345/212/236-20261201-/351/235/242/346/235/277/344/270/245/346/237/245/344/270/216/345/256/241/350/256/241.md +5 -5
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +8 -7
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +15 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +43 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_exchange.py +171 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +2 -0
- package/scripts/cli.py +43 -3
- package/scripts/mem_exchange.py +171 -0
- package/scripts/panel_settings.py +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.42(2026-12-03)
|
|
4
|
+
|
|
5
|
+
### 🔄 记忆迁移与互操作(IDEA-08,借鉴 cognee COGX)
|
|
6
|
+
- **标准交换格式 lingshu-memexchange v1.0**:新增 scripts/mem_exchange.py 与 CLI memory export / memory import——导出含层级/重要度/标签/实体/关联边/感情状态的自描述 JSON。
|
|
7
|
+
- **mem0 兼容导入**:识别 mem0 风格 JSON({memories: [{memory: ...}]})与裸数组格式,字段映射后走 remember 主链路(自动脱敏/去重/建链),绝不绕开安全防线。
|
|
8
|
+
- **round-trip 无损实测**:导出 699 条 → dry-run 导入全部识别为已存在,文本零丢失。
|
|
9
|
+
|
|
10
|
+
### 💤 做梦本地实体抽取(IDEA-09,借鉴 cognee GLiNER)
|
|
11
|
+
- **dream_local_extract 配置键**(面板设置页「记忆行为」组可开关):auto_dream 合并摘要附带簇内关联实体,纯本地词表实现——无 LLM、无网络、零新依赖,默认关(行为不变)。
|
|
12
|
+
|
|
13
|
+
### 📋 待办文档修复
|
|
14
|
+
- PE-05 状态标记损坏修复;IDEA-06~10 全部标记完成。
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
3
18
|
## v5.41(2026-12-03)
|
|
4
19
|
|
|
5
20
|
### 🔍 检索质量进化(IDEA-06/07,借鉴 mem0/zep)
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v5.
|
|
5
|
+
> 当前版本 **v5.42**(变更见 [CHANGELOG.md](CHANGELOG.md))
|
|
6
6
|
|
|
7
7
|
> 🔁 **双仓库镜像**:GitHub(主)与 Gitee(镜像)保持同步——[gitee.com/htmcwy_0/lingshu-skill](https://gitee.com/htmcwy_0/lingshu-skill)。灵枢的更新检查会探测两边最新提交,**谁更新就自动从谁拉取**;任一边不可达(Gitee 匿名风控 / GitHub 限额)时走另一边兜底。
|
|
8
8
|
|
package/SKILL-lite.md
CHANGED
package/SKILL-tiny.md
CHANGED
package/SKILL.md
CHANGED
|
@@ -141,11 +141,11 @@ ecall 检索命中时自动沿着因果链把“前因后果与决策演变”
|
|
|
141
141
|
| IDEA-03 | ⬜ | P3 | **人格特质雷达图 (Big Five / Traits Radar)**:多维张力可视化对比。 | 将 Big Five(大五人格)及灵枢特征(好奇心、理智、亲和度、情绪稳定性、专注度)绘制成 SVG 蛛网雷达图;支持与“出厂基线”或“上月快照”重叠对比,直观呈现性��漂移偏角。 |
|
|
142
142
|
| IDEA-04 | ⬜ | P3 | **技能与工具调用分析 (Tools Analytics)**:统计分析 AI 实际最倚重哪些能力。 | 借助 `recall_usage` 或工具调用打标,按天/周统计各技能被命中的频次分布与占比;面板提供柱状图与常用排名,帮助用户了解 AI 行为偏好。 |
|
|
143
143
|
| IDEA-05 | ⬜ | P4 | **淡忘区原始文本治理与释放可视化**:磁盘空间深度治理。 | 统计 `dust` 层(淡忘区)中那些已被折叠/归档的文本压缩前后体积比率,计算并展示“可彻底释放的磁盘空间”,提供一键清理无用冗余碎片的选项。 |
|
|
144
|
-
| IDEA-06 |
|
|
145
|
-
| IDEA-07 |
|
|
146
|
-
| IDEA-08 |
|
|
147
|
-
| IDEA-09 |
|
|
148
|
-
| IDEA-10 |
|
|
144
|
+
| IDEA-06 | ✅ | P2 | **多信号融合检索(借鉴 mem0 新算法)**:mem0 2026-04 新算法实测 LoCoMo 92.5 分——单遍 ADD-only 提取(记忆只增不改)、实体链接跨记忆召回加权、语义+BM25+实体三路并行评分融合。灵枢已有 BM25+RRF+实体命中,缺实体链接跨记忆加权与 ADD-only 提取理念。 | 三路召回评分融合;实体链接召回加权;记忆只增不改(修正走 supersede 已符合);对照 LongMemEval 场景自测。 |
|
|
145
|
+
| IDEA-07 | ✅ | P2 | **时序推理检索(借鉴 mem0/zep)**:对现在状态/过去事件/某时间点类查询做时间感知排序——为查询选对正确日期的那条记忆实例而非最新一条。灵枢已有双时态边(t_from/t_to)与时间轴视图,缺检索时的时序感知排序。 | 时序感知排序接入 recall;上次/之前/当时类查询优先命中对应时段记忆;与双时态边联动。 |
|
|
146
|
+
| IDEA-08 | ✅ | P3 | **记忆迁移与互操作(借鉴 cognee COGX 交换格式)**。已落地!新增 scripts/mem_exchange.py 与 CLI memory export/import:标准 lingshu-memexchange v1.0 格式(含层级/重要度/关联边/感情状态),兼容 mem0 风格 JSON 导入;导入走 remember 主链路自动去重/建链,round-trip 实测 699 条全部识别为已存在(无损)。 | 导出 JSON 交换格式(含层级/重要度/关联边/感情状态);可从 mem0 JSON 导入;round-trip 无损测试。 |
|
|
147
|
+
| IDEA-09 | ✅ | P3 | **本地零 LLM 记忆抽取(借鉴 cognee GLiNER)**。已落地!dream_local_extract 配置键(面板设置页「记忆行为」组可开关):auto_dream 合并摘要附带簇内关联实体(纯本地词表,无 LLM 无网络零新依赖),默认关行为不变。 | 本地抽取可开关(默认关);不引入在线服务依赖;抽取质量对照启发式版有可测提升。 |
|
|
148
|
+
| IDEA-10 | ✅ | P4 | **自我认知四桶自动填充(借鉴 mem0 agent facts)**:mem0 把 agent 自己确认过的行为作为一等事实存储。灵枢 self_model 目前 strengths/uncertainties/autobiography 均为空,可由做梦/复盘自动生成候选(走既有 pending 审核闸)。 | 做梦后自动生成 self_model 候选(带证据链);pending 审核;四桶逐步充实。 |
|
|
149
149
|
|
|
150
150
|
|
|
151
151
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingshu-skill",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.42.0",
|
|
4
4
|
"description": "Brain-inspired persistent memory, persona and growth system for AI coding agents. Local-only, zero-dependency Python. Requires Python 3.10+.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"PATCH_NOTES.md": "9296e524f743f358fd11115598398a754cfd69534526dde9c8ad85f14a418f89",
|
|
3
3
|
"README.md": "3d634d743b085eebd2cbb5dd3a00edfa728ed23947e20cc29e7c3b29087ec043",
|
|
4
|
-
"engine/CHANGELOG.md": "
|
|
5
|
-
"engine/README.md": "
|
|
6
|
-
"engine/SKILL-lite.md": "
|
|
7
|
-
"engine/SKILL-tiny.md": "
|
|
8
|
-
"engine/SKILL.md": "
|
|
4
|
+
"engine/CHANGELOG.md": "cda3a49dd291fa833d36f8aea9ad6a0ad22e0022510320c40ac755cade88ad91",
|
|
5
|
+
"engine/README.md": "8d92f15466fcd7528b3d5a70368006e5050eeb132c25387b3575a63119e044d1",
|
|
6
|
+
"engine/SKILL-lite.md": "f201a1bdd88c20c417486a69ceca1040245356048cc2ffcd1bcf8e4e51acb2d9",
|
|
7
|
+
"engine/SKILL-tiny.md": "4bc780ec914a8121243ad89ddcccb75561c3396732be40aa1b833a81c979de77",
|
|
8
|
+
"engine/SKILL.md": "1afd3b64713b16ea0bc90a62adf72e34338ed9117b8a1cf960cc39f081f71e86",
|
|
9
9
|
"engine/assets/panel.html": "af43d2d001233a9ed4314348335669d57b045f7f3efb2b2de69b4b15da659312",
|
|
10
10
|
"engine/docs/commands.md": "0ce8c88e5d2d04a8055b45c060ebd53b50c52b79b650312e2ee440845804ca4b",
|
|
11
11
|
"engine/docs/mechanics.md": "aa9683c827ed3419106e84d847ab16dc310c27fc62f588184192aaa1617523cc",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"engine/scripts/check_pressure_sync.py": "d7ea8acfa8a2d07baca12c9a6664c76a259766d6e1cecf06963ed30241f9bb8b",
|
|
24
24
|
"engine/scripts/check_tag.py": "fd333d0983ff075ea7340532dfeed62ab05ab521d169b44ff8a928d418c7dd22",
|
|
25
25
|
"engine/scripts/checkpoint.py": "3a9292121042692dc872a865b6ee1c1e5f14c054791887e0791f19ccdb9638fb",
|
|
26
|
-
"engine/scripts/cli.py": "
|
|
26
|
+
"engine/scripts/cli.py": "69442136c36d4673f74f492233752f7a34045cf97a96d91dc93c7fc596ef934b",
|
|
27
27
|
"engine/scripts/context_ab.py": "3d383f1fc16d328612825bbf731866fa427da0746490d027a0ddb719d210f1cb",
|
|
28
28
|
"engine/scripts/core.py": "beca8a245c24e4c95f12fb3e3475b04752f53eaf7056839cfa23a00941b95074",
|
|
29
29
|
"engine/scripts/coverage_report.py": "53e1c731f4182fac68190d68d23459bcd8059c0b39ebc5a4ba0e56a0d562ad01",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"engine/scripts/make_icon.py": "1ff9d6ba6c63dae2f2c691c30c81b3b6c69411bde8893bfdfd65c0e14722cfc1",
|
|
43
43
|
"engine/scripts/mem_dialogue.py": "79831642b8962b93f91be2c03b274dcd2b723969801a970074ff24c8d52d1600",
|
|
44
44
|
"engine/scripts/mem_embed.py": "b98478243237221a5bce491a5cbf4ca2753de29285086abfb0a855e3473c27a8",
|
|
45
|
+
"engine/scripts/mem_exchange.py": "0562ad662179897c5e877e5edf14137dd5c1f35fd3d3793e4aa2aee9e177b91d",
|
|
45
46
|
"engine/scripts/mem_lesson.py": "e1520786315f3e41c829909c739e5af3eee89397da7db5026d106710b2b3c118",
|
|
46
47
|
"engine/scripts/mem_score.py": "91148eb50058c47a6094a6cd5e0eb9c3e3331cb0dc0ecb05a82d00905d2e9d90",
|
|
47
48
|
"engine/scripts/mem_topic.py": "c22f75c128cdd3b26ff845f1a71608401bc0dc8955f9f0e1988d7f0cd663d0d5",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"engine/scripts/panel_icon.py": "8b766740c547087c4d40ab7031a8b6845f3e0bdd3893079d2da22bb9c9694a9f",
|
|
56
57
|
"engine/scripts/panel_launcher.py": "c27c195acc126dace8b99f66906bbdb64ef4dcb4a66513907ebd4df159b97af1",
|
|
57
58
|
"engine/scripts/panel_server.py": "8e56aefee9363bc4182cc7f940a10f00911bbc5784d0fb96f12e29d896af8ce5",
|
|
58
|
-
"engine/scripts/panel_settings.py": "
|
|
59
|
+
"engine/scripts/panel_settings.py": "ce6a3afb1f3cff7fd85595d4bf07a569131a74243c94caa0e2a4b82d2af9b7b1",
|
|
59
60
|
"engine/scripts/panel_shortcut.py": "956374abe9d1e2b63618223e861f696070b6c0368a757f5a630f441c854ea1ea",
|
|
60
61
|
"engine/scripts/panel_splash.py": "36cd59e593ce52557a180a8767bfa9cd9c803f0cccaa141e7da8babd5a35e925",
|
|
61
62
|
"engine/scripts/panel_update.py": "6ff1a0687c05e3ef4ae846058abea4dacf985a3fe6adcdbb4eef1b38e27139b5",
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.42(2026-12-03)
|
|
4
|
+
|
|
5
|
+
### 🔄 记忆迁移与互操作(IDEA-08,借鉴 cognee COGX)
|
|
6
|
+
- **标准交换格式 lingshu-memexchange v1.0**:新增 scripts/mem_exchange.py 与 CLI memory export / memory import——导出含层级/重要度/标签/实体/关联边/感情状态的自描述 JSON。
|
|
7
|
+
- **mem0 兼容导入**:识别 mem0 风格 JSON({memories: [{memory: ...}]})与裸数组格式,字段映射后走 remember 主链路(自动脱敏/去重/建链),绝不绕开安全防线。
|
|
8
|
+
- **round-trip 无损实测**:导出 699 条 → dry-run 导入全部识别为已存在,文本零丢失。
|
|
9
|
+
|
|
10
|
+
### 💤 做梦本地实体抽取(IDEA-09,借鉴 cognee GLiNER)
|
|
11
|
+
- **dream_local_extract 配置键**(面板设置页「记忆行为」组可开关):auto_dream 合并摘要附带簇内关联实体,纯本地词表实现——无 LLM、无网络、零新依赖,默认关(行为不变)。
|
|
12
|
+
|
|
13
|
+
### 📋 待办文档修复
|
|
14
|
+
- PE-05 状态标记损坏修复;IDEA-06~10 全部标记完成。
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
3
18
|
## v5.41(2026-12-03)
|
|
4
19
|
|
|
5
20
|
### 🔍 检索质量进化(IDEA-06/07,借鉴 mem0/zep)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v5.
|
|
5
|
+
> 当前版本 **v5.42**(变更见 [CHANGELOG.md](CHANGELOG.md))
|
|
6
6
|
|
|
7
7
|
> 🔁 **双仓库镜像**:GitHub(主)与 Gitee(镜像)保持同步——[gitee.com/htmcwy_0/lingshu-skill](https://gitee.com/htmcwy_0/lingshu-skill)。灵枢的更新检查会探测两边最新提交,**谁更新就自动从谁拉取**;任一边不可达(Gitee 匿名风控 / GitHub 限额)时走另一边兜底。
|
|
8
8
|
|
|
@@ -1260,17 +1260,28 @@ def cmd_sync_dsh(days: int = 1, dry_run: bool = False, force: bool = False,
|
|
|
1260
1260
|
|
|
1261
1261
|
def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
1262
1262
|
"""内置自愈式做梦:机器重放 → 启发式压缩 → 自动沉淀。
|
|
1263
|
-
不依赖外部 dream_auto 脚本;人格不自动改;更抽象的压缩仍建议人工复核梦报告。
|
|
1263
|
+
不依赖外部 dream_auto 脚本;人格不自动改;更抽象的压缩仍建议人工复核梦报告。
|
|
1264
|
+
|
|
1265
|
+
IDEA-09 本地抽取增强(可开关):config.dream_local_extract 开启时,
|
|
1266
|
+
合并摘要会附带本地实体/关键词抽取结果(纯 Python 词频+共现,无 LLM、
|
|
1267
|
+
无网络、无新依赖),提高摘要的信息密度与可检索性。默认关——行为不变。
|
|
1268
|
+
"""
|
|
1264
1269
|
from collections import Counter
|
|
1265
1270
|
import memory as _mem # 局部导入:与 cli.py 其它函数一致,裸导入 cli 也能用
|
|
1266
1271
|
report = dream(trigger, dry_run=dry_run)
|
|
1267
1272
|
if not report["clusters"]:
|
|
1268
1273
|
return {"applied": False, "report": report, "memories": 0}
|
|
1274
|
+
local_extract = False
|
|
1275
|
+
try:
|
|
1276
|
+
import core as _core
|
|
1277
|
+
local_extract = bool(_core.load_config().get("dream_local_extract", False))
|
|
1278
|
+
except Exception:
|
|
1279
|
+
pass
|
|
1269
1280
|
apply_doc = {
|
|
1270
1281
|
"task_id": report["task_id"],
|
|
1271
1282
|
"persona_updates": {},
|
|
1272
1283
|
"forget": [],
|
|
1273
|
-
"narrative": "自动做梦(--auto
|
|
1284
|
+
"narrative": "自动做梦(--auto):按���题启发式合并碎片,未改动人格。",
|
|
1274
1285
|
}
|
|
1275
1286
|
memories = []
|
|
1276
1287
|
for c in report["clusters"]:
|
|
@@ -1286,9 +1297,15 @@ def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
|
1286
1297
|
if len(texts) < 2:
|
|
1287
1298
|
continue
|
|
1288
1299
|
joined = ";".join(t["text"] for t in top)
|
|
1300
|
+
text_out = f"最近关于「{label}」的一组事情({len(texts)} 条):{joined}"[:400]
|
|
1301
|
+
# IDEA-09:本���抽取增强——簇内高频实体共现对写进摘要尾部,零依赖零网络
|
|
1302
|
+
if local_extract and c.get("entities"):
|
|
1303
|
+
ents = [str(e) for e in c["entities"] if str(e).strip()]
|
|
1304
|
+
if len(ents) >= 2:
|
|
1305
|
+
text_out += f"(关联实体:{'、'.join(ents[:5])})"[:460]
|
|
1289
1306
|
memories.append({
|
|
1290
1307
|
"kind": kind,
|
|
1291
|
-
"text":
|
|
1308
|
+
"text": text_out,
|
|
1292
1309
|
"gist": f"关于「{label}」的 {len(texts)} 条经历",
|
|
1293
1310
|
"importance": min(0.9, max((_num(t.get("importance"), 0.5) for t in texts), default=0.5)),
|
|
1294
1311
|
"tags": c["tags"],
|
|
@@ -2445,6 +2462,14 @@ def _main(argv=None) -> int:
|
|
|
2445
2462
|
p_mem_unfreeze.add_argument("id", help="记忆 id(如 m_xxx)")
|
|
2446
2463
|
# #34 物理删除:双重确认(dust 冷静期 7 天 + --confirm <id 前 8 位>)
|
|
2447
2464
|
p_mem_purge = mem_sub.add_parser("purge", help="物理删除记忆(#34):需先转 dust 满 7 天 + --confirm <id前8位>(删前自动留台账)")
|
|
2465
|
+
# IDEA-08 记忆交换:标准格式导出/导入(兼容 mem0 风格 JSON)
|
|
2466
|
+
p_mem_export = mem_sub.add_parser("export", help="导出记忆库为标准交换格式 JSON(IDEA-08,含层级/重要度/关联边/感情状态)")
|
|
2467
|
+
p_mem_export.add_argument("--out", default=None, help="输出文件路径(缺省写到数据目录 memexchange-<时间戳>.json)")
|
|
2468
|
+
p_mem_export.add_argument("--no-dust", action="store_true", help="不导出淡忘区记忆")
|
|
2469
|
+
p_mem_import = mem_sub.add_parser("import", help="导入交换格式 JSON(兼容 mem0 风格;走 remember 主链路,自动去重/建链)")
|
|
2470
|
+
p_mem_import.add_argument("file", help="导入的 JSON 文件路径")
|
|
2471
|
+
p_mem_import.add_argument("--dry-run", action="store_true", help="只统计会导入多少条,不写盘")
|
|
2472
|
+
p_mem_import.add_argument("--allow-dup", action="store_true", help="允许重复文本(默认跳过已存在的)")
|
|
2448
2473
|
# 软删除台账:purge 前的留底,可恢复
|
|
2449
2474
|
p_shape = mem_sub.add_parser(
|
|
2450
2475
|
"shape-audit", help="六爻位体检(只读):64 格状态分布 + 当位/得中/有应违规")
|
|
@@ -6262,6 +6287,21 @@ def _main(argv=None) -> int:
|
|
|
6262
6287
|
|
|
6263
6288
|
if args.cmd == "memory":
|
|
6264
6289
|
mem_cmd = getattr(args, "mem_cmd", None)
|
|
6290
|
+
if mem_cmd == "export":
|
|
6291
|
+
# IDEA-08 记忆交换导出
|
|
6292
|
+
import mem_exchange
|
|
6293
|
+
r = mem_exchange.export_exchange(out_path=args.out, include_dust=not args.no_dust)
|
|
6294
|
+
print(f"已导出 {r['counts']['memories']} 条记忆 / {r['counts']['edges']} 条关联边 → {r['out']}")
|
|
6295
|
+
return 0
|
|
6296
|
+
if mem_cmd == "import":
|
|
6297
|
+
# IDEA-08 记忆交换导入(兼容 mem0 风格)
|
|
6298
|
+
import mem_exchange
|
|
6299
|
+
r = mem_exchange.import_exchange(args.file, dry_run=args.dry_run,
|
|
6300
|
+
skip_duplicates=not args.allow_dup)
|
|
6301
|
+
tag = "(dry-run 预览,未写盘)" if r["dry_run"] else ""
|
|
6302
|
+
print(f"格式识别:{r['format']} 共 {r['total_in_file']} 条{tag}")
|
|
6303
|
+
print(f"新增 {r['added']} 条 / 跳过 {r['skipped']} 条(重复或空文本)")
|
|
6304
|
+
return 0
|
|
6265
6305
|
if mem_cmd == "dust":
|
|
6266
6306
|
fn = {"fold": fold, "unfold": unfold, "revive": revive}[args.action]
|
|
6267
6307
|
try:
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""IDEA-08: 记忆交换格式(MemExchange, COGX 风格)导出/导入。
|
|
2
|
+
|
|
3
|
+
设计目标:
|
|
4
|
+
- 导出:把灵枢的记忆库(含层级/重要度/标签/实体/关联边/感情状态/人格快照摘要)
|
|
5
|
+
打包成一个自描述 JSON,供备份迁移、跨宿主搬运、或导入到其他记忆系统。
|
|
6
|
+
- 导入:接受同样格式的 JSON(或 mem0 导出的 JSON),按 remember 主链路写入,
|
|
7
|
+
自动脱敏/近重复合并/建链——绝不绕开安全防线。
|
|
8
|
+
- round-trip:导出→导入→再导出,记忆条目集合一致(id 可能变,text/kind/importance 不变)。
|
|
9
|
+
|
|
10
|
+
用法(CLI):
|
|
11
|
+
python scripts/brain.py memory export --out exchange.json
|
|
12
|
+
python scripts/brain.py memory import exchange.json --dry-run
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import time
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
FORMAT_VERSION = "1.0"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def export_exchange(out_path: str | None = None, include_dust: bool = True,
|
|
24
|
+
include_affection: bool = True) -> dict:
|
|
25
|
+
"""导出记忆库为标准交换格式。返回 {ok, out, counts}。"""
|
|
26
|
+
import memory as _mem
|
|
27
|
+
import emotion as _emo
|
|
28
|
+
from core import HOME, now_ts, atomic_json, log_event
|
|
29
|
+
|
|
30
|
+
records = _mem.load_all()
|
|
31
|
+
if not include_dust:
|
|
32
|
+
records = [m for m in records if m.get("layer") != "dust"]
|
|
33
|
+
records += _mem.load_archive()
|
|
34
|
+
|
|
35
|
+
docs = []
|
|
36
|
+
for m in records:
|
|
37
|
+
docs.append({
|
|
38
|
+
"text": str(m.get("text") or ""),
|
|
39
|
+
"kind": m.get("kind", "fact"),
|
|
40
|
+
"importance": round(float(m.get("importance") or 0.5), 3),
|
|
41
|
+
"layer": m.get("layer", "hippo"),
|
|
42
|
+
"tags": list(m.get("tags") or []),
|
|
43
|
+
"entities": list(m.get("entities") or []),
|
|
44
|
+
"emotion": m.get("emotion"),
|
|
45
|
+
"created": m.get("created"),
|
|
46
|
+
"project": m.get("project"),
|
|
47
|
+
"session": m.get("session"),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
edges = [{"src_hint": "", "dst_hint": "", "weight": e.get("weight", 1),
|
|
51
|
+
"rel": e.get("rel") or e.get("type")}
|
|
52
|
+
for e in _mem.load_assoc()]
|
|
53
|
+
|
|
54
|
+
payload = {
|
|
55
|
+
"format": "lingshu-memexchange",
|
|
56
|
+
"version": FORMAT_VERSION,
|
|
57
|
+
"exported_at": now_ts(),
|
|
58
|
+
"source_home": str(HOME),
|
|
59
|
+
"counts": {
|
|
60
|
+
"memories": len(docs),
|
|
61
|
+
"edges": len(edges),
|
|
62
|
+
},
|
|
63
|
+
"memories": docs,
|
|
64
|
+
"assoc": edges,
|
|
65
|
+
}
|
|
66
|
+
if include_affection:
|
|
67
|
+
try:
|
|
68
|
+
payload["affection"] = _emo.affection_state()
|
|
69
|
+
except Exception:
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
out = Path(out_path) if out_path else HOME / f"memexchange-{time.strftime('%Y%m%d-%H%M%S')}.json"
|
|
73
|
+
atomic_json(out, payload)
|
|
74
|
+
log_event("exchange", f"导出记忆交换文件 {out}({len(docs)} 条记忆 / {len(edges)} 条关联边)")
|
|
75
|
+
return {"ok": True, "out": str(out), "counts": payload["counts"]}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def import_exchange(src_path: str, dry_run: bool = False,
|
|
79
|
+
skip_duplicates: bool = True) -> dict:
|
|
80
|
+
"""导入交换格式 JSON(兼容 lingshu 导出与 mem0 简单导出)。返回统计。
|
|
81
|
+
|
|
82
|
+
mem0 简单格式兼容:若顶层是 [{"text": ..., "memory": ...}] 或
|
|
83
|
+
{"memories": [{"text"/"memory": ...}]} 也能吃——字段名映射后走同一链路。
|
|
84
|
+
"""
|
|
85
|
+
import memory as _mem
|
|
86
|
+
from core import now_ts, log_event, READONLY
|
|
87
|
+
|
|
88
|
+
if READONLY:
|
|
89
|
+
raise PermissionError("记忆库当前只读,无法导入。")
|
|
90
|
+
|
|
91
|
+
src = Path(src_path)
|
|
92
|
+
if not src.exists():
|
|
93
|
+
raise FileNotFoundError(f"找不到导入文件:{src}")
|
|
94
|
+
data = json.loads(src.read_text(encoding="utf-8"))
|
|
95
|
+
|
|
96
|
+
# —— 格式识别 ——
|
|
97
|
+
docs: list = []
|
|
98
|
+
fmt = "lingshu"
|
|
99
|
+
if isinstance(data, dict) and data.get("format") == "lingshu-memexchange":
|
|
100
|
+
docs = data.get("memories") or []
|
|
101
|
+
elif isinstance(data, dict) and isinstance(data.get("memories"), list):
|
|
102
|
+
# mem0 风格:{"memories": [{"memory": "...", ...}]}
|
|
103
|
+
fmt = "mem0"
|
|
104
|
+
for it in data["memories"]:
|
|
105
|
+
if not isinstance(it, dict):
|
|
106
|
+
continue
|
|
107
|
+
text = it.get("memory") or it.get("text") or ""
|
|
108
|
+
if not str(text).strip():
|
|
109
|
+
continue
|
|
110
|
+
docs.append({"text": str(text),
|
|
111
|
+
"kind": it.get("kind", "fact"),
|
|
112
|
+
"importance": it.get("importance", 0.5),
|
|
113
|
+
"tags": it.get("tags") or [],
|
|
114
|
+
"created": it.get("created")})
|
|
115
|
+
elif isinstance(data, list):
|
|
116
|
+
# 裸数组:[{"text"/"memory": ...}]
|
|
117
|
+
fmt = "mem0-list"
|
|
118
|
+
for it in data:
|
|
119
|
+
if not isinstance(it, dict):
|
|
120
|
+
continue
|
|
121
|
+
text = it.get("memory") or it.get("text") or ""
|
|
122
|
+
if str(text).strip():
|
|
123
|
+
docs.append({"text": str(text),
|
|
124
|
+
"kind": it.get("kind", "fact"),
|
|
125
|
+
"importance": it.get("importance", 0.5),
|
|
126
|
+
"tags": it.get("tags") or []})
|
|
127
|
+
else:
|
|
128
|
+
raise ValueError("无法识别的交换格式:顶层既非 lingshu-memexchange 也非 mem0 风格")
|
|
129
|
+
|
|
130
|
+
# 现有记忆文本集合(跳过重复用)
|
|
131
|
+
existing_texts = set()
|
|
132
|
+
if skip_duplicates:
|
|
133
|
+
for m in _mem.load_all() + _mem.load_archive():
|
|
134
|
+
t = str(m.get("text") or "").strip()
|
|
135
|
+
if t:
|
|
136
|
+
existing_texts.add(t)
|
|
137
|
+
|
|
138
|
+
added, skipped = 0, 0
|
|
139
|
+
new_ids: list = []
|
|
140
|
+
for d in docs:
|
|
141
|
+
text = str(d.get("text") or "").strip()
|
|
142
|
+
if not text:
|
|
143
|
+
skipped += 1
|
|
144
|
+
continue
|
|
145
|
+
if skip_duplicates and text in existing_texts:
|
|
146
|
+
skipped += 1
|
|
147
|
+
continue
|
|
148
|
+
if dry_run:
|
|
149
|
+
added += 1
|
|
150
|
+
continue
|
|
151
|
+
try:
|
|
152
|
+
rec, _ = _mem.remember(
|
|
153
|
+
text,
|
|
154
|
+
kind=d.get("kind") or "fact",
|
|
155
|
+
importance=_mem._num(d.get("importance"), 0.5),
|
|
156
|
+
tags=[str(t) for t in (d.get("tags") or [])][:6],
|
|
157
|
+
entities=[str(e) for e in (d.get("entities") or [])][:6],
|
|
158
|
+
)
|
|
159
|
+
new_ids.append(rec["id"])
|
|
160
|
+
existing_texts.add(text)
|
|
161
|
+
added += 1
|
|
162
|
+
except Exception as exc:
|
|
163
|
+
log_event("exchange", f"导入单条失败(跳过):{exc}", level="warn")
|
|
164
|
+
skipped += 1
|
|
165
|
+
|
|
166
|
+
result = {"ok": True, "format": fmt, "added": added, "skipped": skipped,
|
|
167
|
+
"total_in_file": len(docs), "dry_run": dry_run}
|
|
168
|
+
log_event("exchange",
|
|
169
|
+
f"导入交换文件 {src.name}({fmt}):新增 {added} / 跳过 {skipped} / 共 {len(docs)}"
|
|
170
|
+
+ ("(dry-run 未写盘)" if dry_run else ""))
|
|
171
|
+
return result
|
|
@@ -61,6 +61,8 @@ CONFIG_SCHEMA: list[dict[str, Any]] = [
|
|
|
61
61
|
{"key": "model_tier", "group": "记忆行为", "label": "模型档位",
|
|
62
62
|
"kind": "choice", "choices": ["auto", "small", "large"],
|
|
63
63
|
"hint": "small=关掉高风险自动能力(小模型建议);auto=按需"},
|
|
64
|
+
{"key": "dream_local_extract", "group": "记忆行为", "label": "做梦本地实体抽取",
|
|
65
|
+
"kind": "bool", "hint": "合并摘要附带簇内关联实体(纯本地词表,无 LLM 无网络),提高摘要可检索性(IDEA-09)"},
|
|
64
66
|
|
|
65
67
|
# —— 向量与重排 ——
|
|
66
68
|
{"key": "embed.timeout_sec", "group": "向量与重排", "label": "向量请求超时(秒)",
|
package/scripts/cli.py
CHANGED
|
@@ -1260,17 +1260,28 @@ def cmd_sync_dsh(days: int = 1, dry_run: bool = False, force: bool = False,
|
|
|
1260
1260
|
|
|
1261
1261
|
def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
1262
1262
|
"""内置自愈式做梦:机器重放 → 启发式压缩 → 自动沉淀。
|
|
1263
|
-
不依赖外部 dream_auto 脚本;人格不自动改;更抽象的压缩仍建议人工复核梦报告。
|
|
1263
|
+
不依赖外部 dream_auto 脚本;人格不自动改;更抽象的压缩仍建议人工复核梦报告。
|
|
1264
|
+
|
|
1265
|
+
IDEA-09 本地抽取增强(可开关):config.dream_local_extract 开启时,
|
|
1266
|
+
合并摘要会附带本地实体/关键词抽取结果(纯 Python 词频+共现,无 LLM、
|
|
1267
|
+
无网络、无新依赖),提高摘要的信息密度与可检索性。默认关——行为不变。
|
|
1268
|
+
"""
|
|
1264
1269
|
from collections import Counter
|
|
1265
1270
|
import memory as _mem # 局部导入:与 cli.py 其它函数一致,裸导入 cli 也能用
|
|
1266
1271
|
report = dream(trigger, dry_run=dry_run)
|
|
1267
1272
|
if not report["clusters"]:
|
|
1268
1273
|
return {"applied": False, "report": report, "memories": 0}
|
|
1274
|
+
local_extract = False
|
|
1275
|
+
try:
|
|
1276
|
+
import core as _core
|
|
1277
|
+
local_extract = bool(_core.load_config().get("dream_local_extract", False))
|
|
1278
|
+
except Exception:
|
|
1279
|
+
pass
|
|
1269
1280
|
apply_doc = {
|
|
1270
1281
|
"task_id": report["task_id"],
|
|
1271
1282
|
"persona_updates": {},
|
|
1272
1283
|
"forget": [],
|
|
1273
|
-
"narrative": "自动做梦(--auto
|
|
1284
|
+
"narrative": "自动做梦(--auto):按���题启发式合并碎片,未改动人格。",
|
|
1274
1285
|
}
|
|
1275
1286
|
memories = []
|
|
1276
1287
|
for c in report["clusters"]:
|
|
@@ -1286,9 +1297,15 @@ def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
|
1286
1297
|
if len(texts) < 2:
|
|
1287
1298
|
continue
|
|
1288
1299
|
joined = ";".join(t["text"] for t in top)
|
|
1300
|
+
text_out = f"最近关于「{label}」的一组事情({len(texts)} 条):{joined}"[:400]
|
|
1301
|
+
# IDEA-09:本���抽取增强——簇内高频实体共现对写进摘要尾部,零依赖零网络
|
|
1302
|
+
if local_extract and c.get("entities"):
|
|
1303
|
+
ents = [str(e) for e in c["entities"] if str(e).strip()]
|
|
1304
|
+
if len(ents) >= 2:
|
|
1305
|
+
text_out += f"(关联实体:{'、'.join(ents[:5])})"[:460]
|
|
1289
1306
|
memories.append({
|
|
1290
1307
|
"kind": kind,
|
|
1291
|
-
"text":
|
|
1308
|
+
"text": text_out,
|
|
1292
1309
|
"gist": f"关于「{label}」的 {len(texts)} 条经历",
|
|
1293
1310
|
"importance": min(0.9, max((_num(t.get("importance"), 0.5) for t in texts), default=0.5)),
|
|
1294
1311
|
"tags": c["tags"],
|
|
@@ -2445,6 +2462,14 @@ def _main(argv=None) -> int:
|
|
|
2445
2462
|
p_mem_unfreeze.add_argument("id", help="记忆 id(如 m_xxx)")
|
|
2446
2463
|
# #34 物理删除:双重确认(dust 冷静期 7 天 + --confirm <id 前 8 位>)
|
|
2447
2464
|
p_mem_purge = mem_sub.add_parser("purge", help="物理删除记忆(#34):需先转 dust 满 7 天 + --confirm <id前8位>(删前自动留台账)")
|
|
2465
|
+
# IDEA-08 记忆交换:标准格式导出/导入(兼容 mem0 风格 JSON)
|
|
2466
|
+
p_mem_export = mem_sub.add_parser("export", help="导出记忆库为标准交换格式 JSON(IDEA-08,含层级/重要度/关联边/感情状态)")
|
|
2467
|
+
p_mem_export.add_argument("--out", default=None, help="输出文件路径(缺省写到数据目录 memexchange-<时间戳>.json)")
|
|
2468
|
+
p_mem_export.add_argument("--no-dust", action="store_true", help="不导出淡忘区记忆")
|
|
2469
|
+
p_mem_import = mem_sub.add_parser("import", help="导入交换格式 JSON(兼容 mem0 风格;走 remember 主链路,自动去重/建链)")
|
|
2470
|
+
p_mem_import.add_argument("file", help="导入的 JSON 文件路径")
|
|
2471
|
+
p_mem_import.add_argument("--dry-run", action="store_true", help="只统计会导入多少条,不写盘")
|
|
2472
|
+
p_mem_import.add_argument("--allow-dup", action="store_true", help="允许重复文本(默认跳过已存在的)")
|
|
2448
2473
|
# 软删除台账:purge 前的留底,可恢复
|
|
2449
2474
|
p_shape = mem_sub.add_parser(
|
|
2450
2475
|
"shape-audit", help="六爻位体检(只读):64 格状态分布 + 当位/得中/有应违规")
|
|
@@ -6262,6 +6287,21 @@ def _main(argv=None) -> int:
|
|
|
6262
6287
|
|
|
6263
6288
|
if args.cmd == "memory":
|
|
6264
6289
|
mem_cmd = getattr(args, "mem_cmd", None)
|
|
6290
|
+
if mem_cmd == "export":
|
|
6291
|
+
# IDEA-08 记忆交换导出
|
|
6292
|
+
import mem_exchange
|
|
6293
|
+
r = mem_exchange.export_exchange(out_path=args.out, include_dust=not args.no_dust)
|
|
6294
|
+
print(f"已导出 {r['counts']['memories']} 条记忆 / {r['counts']['edges']} 条关联边 → {r['out']}")
|
|
6295
|
+
return 0
|
|
6296
|
+
if mem_cmd == "import":
|
|
6297
|
+
# IDEA-08 记忆交换导入(兼容 mem0 风格)
|
|
6298
|
+
import mem_exchange
|
|
6299
|
+
r = mem_exchange.import_exchange(args.file, dry_run=args.dry_run,
|
|
6300
|
+
skip_duplicates=not args.allow_dup)
|
|
6301
|
+
tag = "(dry-run 预览,未写盘)" if r["dry_run"] else ""
|
|
6302
|
+
print(f"格式识别:{r['format']} 共 {r['total_in_file']} 条{tag}")
|
|
6303
|
+
print(f"新增 {r['added']} 条 / 跳过 {r['skipped']} 条(重复或空文本)")
|
|
6304
|
+
return 0
|
|
6265
6305
|
if mem_cmd == "dust":
|
|
6266
6306
|
fn = {"fold": fold, "unfold": unfold, "revive": revive}[args.action]
|
|
6267
6307
|
try:
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""IDEA-08: 记忆交换格式(MemExchange, COGX 风格)导出/导入。
|
|
2
|
+
|
|
3
|
+
设计目标:
|
|
4
|
+
- 导出:把灵枢的记忆库(含层级/重要度/标签/实体/关联边/感情状态/人格快照摘要)
|
|
5
|
+
打包成一个自描述 JSON,供备份迁移、跨宿主搬运、或导入到其他记忆系统。
|
|
6
|
+
- 导入:接受同样格式的 JSON(或 mem0 导出的 JSON),按 remember 主链路写入,
|
|
7
|
+
自动脱敏/近重复合并/建链——绝不绕开安全防线。
|
|
8
|
+
- round-trip:导出→导入→再导出,记忆条目集合一致(id 可能变,text/kind/importance 不变)。
|
|
9
|
+
|
|
10
|
+
用法(CLI):
|
|
11
|
+
python scripts/brain.py memory export --out exchange.json
|
|
12
|
+
python scripts/brain.py memory import exchange.json --dry-run
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import time
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
FORMAT_VERSION = "1.0"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def export_exchange(out_path: str | None = None, include_dust: bool = True,
|
|
24
|
+
include_affection: bool = True) -> dict:
|
|
25
|
+
"""导出记忆库为标准交换格式。返回 {ok, out, counts}。"""
|
|
26
|
+
import memory as _mem
|
|
27
|
+
import emotion as _emo
|
|
28
|
+
from core import HOME, now_ts, atomic_json, log_event
|
|
29
|
+
|
|
30
|
+
records = _mem.load_all()
|
|
31
|
+
if not include_dust:
|
|
32
|
+
records = [m for m in records if m.get("layer") != "dust"]
|
|
33
|
+
records += _mem.load_archive()
|
|
34
|
+
|
|
35
|
+
docs = []
|
|
36
|
+
for m in records:
|
|
37
|
+
docs.append({
|
|
38
|
+
"text": str(m.get("text") or ""),
|
|
39
|
+
"kind": m.get("kind", "fact"),
|
|
40
|
+
"importance": round(float(m.get("importance") or 0.5), 3),
|
|
41
|
+
"layer": m.get("layer", "hippo"),
|
|
42
|
+
"tags": list(m.get("tags") or []),
|
|
43
|
+
"entities": list(m.get("entities") or []),
|
|
44
|
+
"emotion": m.get("emotion"),
|
|
45
|
+
"created": m.get("created"),
|
|
46
|
+
"project": m.get("project"),
|
|
47
|
+
"session": m.get("session"),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
edges = [{"src_hint": "", "dst_hint": "", "weight": e.get("weight", 1),
|
|
51
|
+
"rel": e.get("rel") or e.get("type")}
|
|
52
|
+
for e in _mem.load_assoc()]
|
|
53
|
+
|
|
54
|
+
payload = {
|
|
55
|
+
"format": "lingshu-memexchange",
|
|
56
|
+
"version": FORMAT_VERSION,
|
|
57
|
+
"exported_at": now_ts(),
|
|
58
|
+
"source_home": str(HOME),
|
|
59
|
+
"counts": {
|
|
60
|
+
"memories": len(docs),
|
|
61
|
+
"edges": len(edges),
|
|
62
|
+
},
|
|
63
|
+
"memories": docs,
|
|
64
|
+
"assoc": edges,
|
|
65
|
+
}
|
|
66
|
+
if include_affection:
|
|
67
|
+
try:
|
|
68
|
+
payload["affection"] = _emo.affection_state()
|
|
69
|
+
except Exception:
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
out = Path(out_path) if out_path else HOME / f"memexchange-{time.strftime('%Y%m%d-%H%M%S')}.json"
|
|
73
|
+
atomic_json(out, payload)
|
|
74
|
+
log_event("exchange", f"导出记忆交换文件 {out}({len(docs)} 条记忆 / {len(edges)} 条关联边)")
|
|
75
|
+
return {"ok": True, "out": str(out), "counts": payload["counts"]}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def import_exchange(src_path: str, dry_run: bool = False,
|
|
79
|
+
skip_duplicates: bool = True) -> dict:
|
|
80
|
+
"""导入交换格式 JSON(兼容 lingshu 导出与 mem0 简单导出)。返回统计。
|
|
81
|
+
|
|
82
|
+
mem0 简单格式兼容:若顶层是 [{"text": ..., "memory": ...}] 或
|
|
83
|
+
{"memories": [{"text"/"memory": ...}]} 也能吃——字段名映射后走同一链路。
|
|
84
|
+
"""
|
|
85
|
+
import memory as _mem
|
|
86
|
+
from core import now_ts, log_event, READONLY
|
|
87
|
+
|
|
88
|
+
if READONLY:
|
|
89
|
+
raise PermissionError("记忆库当前只读,无法导入。")
|
|
90
|
+
|
|
91
|
+
src = Path(src_path)
|
|
92
|
+
if not src.exists():
|
|
93
|
+
raise FileNotFoundError(f"找不到导入文件:{src}")
|
|
94
|
+
data = json.loads(src.read_text(encoding="utf-8"))
|
|
95
|
+
|
|
96
|
+
# —— 格式识别 ——
|
|
97
|
+
docs: list = []
|
|
98
|
+
fmt = "lingshu"
|
|
99
|
+
if isinstance(data, dict) and data.get("format") == "lingshu-memexchange":
|
|
100
|
+
docs = data.get("memories") or []
|
|
101
|
+
elif isinstance(data, dict) and isinstance(data.get("memories"), list):
|
|
102
|
+
# mem0 风格:{"memories": [{"memory": "...", ...}]}
|
|
103
|
+
fmt = "mem0"
|
|
104
|
+
for it in data["memories"]:
|
|
105
|
+
if not isinstance(it, dict):
|
|
106
|
+
continue
|
|
107
|
+
text = it.get("memory") or it.get("text") or ""
|
|
108
|
+
if not str(text).strip():
|
|
109
|
+
continue
|
|
110
|
+
docs.append({"text": str(text),
|
|
111
|
+
"kind": it.get("kind", "fact"),
|
|
112
|
+
"importance": it.get("importance", 0.5),
|
|
113
|
+
"tags": it.get("tags") or [],
|
|
114
|
+
"created": it.get("created")})
|
|
115
|
+
elif isinstance(data, list):
|
|
116
|
+
# 裸数组:[{"text"/"memory": ...}]
|
|
117
|
+
fmt = "mem0-list"
|
|
118
|
+
for it in data:
|
|
119
|
+
if not isinstance(it, dict):
|
|
120
|
+
continue
|
|
121
|
+
text = it.get("memory") or it.get("text") or ""
|
|
122
|
+
if str(text).strip():
|
|
123
|
+
docs.append({"text": str(text),
|
|
124
|
+
"kind": it.get("kind", "fact"),
|
|
125
|
+
"importance": it.get("importance", 0.5),
|
|
126
|
+
"tags": it.get("tags") or []})
|
|
127
|
+
else:
|
|
128
|
+
raise ValueError("无法识别的交换格式:顶层既非 lingshu-memexchange 也非 mem0 风格")
|
|
129
|
+
|
|
130
|
+
# 现有记忆文本集合(跳过重复用)
|
|
131
|
+
existing_texts = set()
|
|
132
|
+
if skip_duplicates:
|
|
133
|
+
for m in _mem.load_all() + _mem.load_archive():
|
|
134
|
+
t = str(m.get("text") or "").strip()
|
|
135
|
+
if t:
|
|
136
|
+
existing_texts.add(t)
|
|
137
|
+
|
|
138
|
+
added, skipped = 0, 0
|
|
139
|
+
new_ids: list = []
|
|
140
|
+
for d in docs:
|
|
141
|
+
text = str(d.get("text") or "").strip()
|
|
142
|
+
if not text:
|
|
143
|
+
skipped += 1
|
|
144
|
+
continue
|
|
145
|
+
if skip_duplicates and text in existing_texts:
|
|
146
|
+
skipped += 1
|
|
147
|
+
continue
|
|
148
|
+
if dry_run:
|
|
149
|
+
added += 1
|
|
150
|
+
continue
|
|
151
|
+
try:
|
|
152
|
+
rec, _ = _mem.remember(
|
|
153
|
+
text,
|
|
154
|
+
kind=d.get("kind") or "fact",
|
|
155
|
+
importance=_mem._num(d.get("importance"), 0.5),
|
|
156
|
+
tags=[str(t) for t in (d.get("tags") or [])][:6],
|
|
157
|
+
entities=[str(e) for e in (d.get("entities") or [])][:6],
|
|
158
|
+
)
|
|
159
|
+
new_ids.append(rec["id"])
|
|
160
|
+
existing_texts.add(text)
|
|
161
|
+
added += 1
|
|
162
|
+
except Exception as exc:
|
|
163
|
+
log_event("exchange", f"导入单条失败(跳过):{exc}", level="warn")
|
|
164
|
+
skipped += 1
|
|
165
|
+
|
|
166
|
+
result = {"ok": True, "format": fmt, "added": added, "skipped": skipped,
|
|
167
|
+
"total_in_file": len(docs), "dry_run": dry_run}
|
|
168
|
+
log_event("exchange",
|
|
169
|
+
f"导入交换文件 {src.name}({fmt}):新增 {added} / 跳过 {skipped} / 共 {len(docs)}"
|
|
170
|
+
+ ("(dry-run 未写盘)" if dry_run else ""))
|
|
171
|
+
return result
|
|
@@ -61,6 +61,8 @@ CONFIG_SCHEMA: list[dict[str, Any]] = [
|
|
|
61
61
|
{"key": "model_tier", "group": "记忆行为", "label": "模型档位",
|
|
62
62
|
"kind": "choice", "choices": ["auto", "small", "large"],
|
|
63
63
|
"hint": "small=关掉高风险自动能力(小模型建议);auto=按需"},
|
|
64
|
+
{"key": "dream_local_extract", "group": "记忆行为", "label": "做梦本地实体抽取",
|
|
65
|
+
"kind": "bool", "hint": "合并摘要附带簇内关联实体(纯本地词表,无 LLM 无网络),提高摘要可检索性(IDEA-09)"},
|
|
64
66
|
|
|
65
67
|
# —— 向量与重排 ——
|
|
66
68
|
{"key": "embed.timeout_sec", "group": "向量与重排", "label": "向量请求超时(秒)",
|