dream
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMem0 Dream — Memory Consolidation
Mem0 Dream — 记忆整合
This skill performs a memory consolidation pass: it fetches all project memories,
identifies near-duplicates, flags contradictions, and prunes stale entries based on
configured retention policies. All proposed changes are shown as a diff for user
approval before anything is modified.
IMPORTANT: Execute steps strictly in order (1 → 2 → 3 → 4 → 5 → 6). Each step depends on the previous one. Do NOT run steps in parallel or skip ahead.
该技能执行记忆整合流程:获取所有项目记忆,识别近似重复内容,标记矛盾条目,并根据配置的保留策略清理过期记录。在进行任何修改前,所有拟议变更都会以差异对比形式展示,供用户审批。
重要提示:严格按顺序执行步骤(1 → 2 → 3 → 4 → 5 → 6)。每个步骤依赖前一步骤。请勿并行运行或跳过步骤。
Step 1: Load Retention Policies
步骤1:加载保留策略
Determine the active retention policy by running the parser script. Use the
appropriate variable for the current platform (,
, or ):
PLUGIN_ROOT${CLAUDE_PLUGIN_ROOT}${CODEX_PLUGIN_ROOT}${CURSOR_PLUGIN_ROOT}bash
python3 "<PLUGIN_ROOT>/scripts/parse_mem0_config.py" "<cwd>"Parse the JSON output (a dict of ). If the script fails
or returns , fall back to these built-in defaults:
category → days | null{} | Default retention |
|---|---|
| 90 days |
| 90 days |
| all others | no pruning |
Store the resolved policies for use in Step 3.
通过运行解析脚本确定当前生效的保留策略。根据当前平台使用对应的变量(、或):
PLUGIN_ROOT${CLAUDE_PLUGIN_ROOT}${CODEX_PLUGIN_ROOT}${CURSOR_PLUGIN_ROOT}bash
python3 "<PLUGIN_ROOT>/scripts/parse_mem0_config.py" "<cwd>"解析JSON输出(格式为的字典)。如果脚本执行失败或返回,则使用以下内置默认值:
分类 → 天数 | null{} | 默认保留时长 |
|---|---|
| 90天 |
| 90天 |
| 其他所有类型 | 不清理 |
保存解析后的策略,供步骤3使用。
Step 2: Fetch ALL Project Memories
步骤2:获取所有项目记忆
Call to retrieve every memory for the active project:
get_memoriespython
get_memories(
filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<active_project_id>"}]},
page_size=200,
)If the response indicates more pages exist, paginate until all memories are fetched.
Collect the full list before proceeding. If zero memories are found, print:
No memories found for project <project_id>. Nothing to consolidate.…and stop.
调用接口获取当前项目的全部记忆:
get_memoriespython
get_memories(
filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<active_project_id>"}]},
page_size=200,
)如果响应显示存在更多分页内容,需分页获取直到所有记忆都被收集。在继续下一步前需收集完整列表。如果未找到任何记忆,打印:
未找到项目<project_id>的记忆。无需进行整合。并终止流程。
Step 3: Analyze — Find Issues
步骤3:分析——查找问题
Work entirely in-memory; do not modify anything yet.
Group memories by (use when the field is absent).
For each group, identify the following:
metadata.type"unknown"全程在内存中操作;暂不修改任何内容。
按对记忆进行分组(当该字段不存在时使用)。针对每个分组,识别以下内容:
metadata.type"unknown"3a. Near-duplicate pairs (merge candidates)
3a. 近似重复对(合并候选)
Two memories are near-duplicates when they express the same fact or decision but
phrased differently (e.g., "Use PostgreSQL for auth" and "Auth DB is PostgreSQL").
Heuristics — two memories are near-duplicates if all of these hold:
- Similarity threshold: estimated cosine similarity > 0.9 (use noun/keyword overlap as proxy — if >60% of significant nouns overlap, treat as >0.9 similarity).
- Same .
metadata.type - Neither memory is pinned ().
metadata.pinned != true
For each qualifying pair, draft a merged version that is more complete and specific
than either original.
当两条记忆表达相同事实或决策但表述不同时(例如:"使用PostgreSQL作为认证数据库"和"认证数据库为PostgreSQL"),视为近似重复。
判定规则——当以下所有条件满足时,两条记忆为近似重复:
- 相似度阈值:估算余弦相似度>0.9(使用名词/关键词重叠作为替代指标——如果超过60%的重要名词重叠,则视为相似度>0.9)。
- 相同的。
metadata.type - 两条记忆均未被固定()。
metadata.pinned != true
针对每符合条件的记忆对,草拟一个比原内容更完整、更具体的合并版本。
3b. Contradictions
3b. 矛盾内容
Two memories contradict when they assert opposing facts about the same topic
(e.g., "Deploy to ECS" vs. "Deploy to Vercel").
Identify the likely winner: the more recent memory with higher confidence wins.
Store both IDs and their content for user review.
当两条记忆针对同一主题断言相反事实时(例如:"部署到ECS" vs "部署到Vercel"),视为矛盾。
确定更合理的胜出者:更新的记忆且置信度更高的胜出。保存两条记忆的ID和内容供用户审核。
3c. Prune candidates
3c. 清理候选
A memory is a prune candidate when any of the following is true:
- Its has a retention policy and the memory is older than the configured number of days (compare
metadata.typeto today).created_at - Its confidence score is below 0.3 AND it contains no information unique to this project (no file paths, identifiers, or domain-specific nouns).
Always skip memories where , regardless of age or
confidence.
metadata.pinned == true当满足以下任一条件时,记忆可作为清理候选:
- 其有保留策略,且记忆已超过配置的天数(将
metadata.type与当前日期对比)。created_at - 置信度得分低于0.3,且不包含该项目独有的信息(无文件路径、标识符或领域特定名词)。
无论时长或置信度如何,始终跳过的记忆。
metadata.pinned == trueStep 4: Print Diff Report
步骤4:打印差异报告
Print a structured diff to the terminal before making any changes. Use exactly
this format:
undefined在进行任何修改前,向终端打印结构化差异报告。严格使用以下格式:
undefineddream — consolidation report
dream — 整合报告
Merges (<N>):
[mem0:<id1>] + [mem0:<id2>] → "<merged content, 100 chars>"
Conflicts (<N>):
[mem0:<idA>] vs [mem0:<idB>] — "<topic>" [A/B/skip]
Prune (<N>):
[mem0:<id>] — <type>, <age>d old
Proposed: <N> merges, <N> prunes, <N> conflicts. Apply? [Y/n]
If there are zero items in any category, omit that section entirely.
If there are zero total proposals (no merges, no prunes, no conflicts), print:
Dream complete. No duplicate, contradictory, or stale memories found.
…and stop.
---合并项(<N>):
[mem0:<id1>] + [mem0:<id2>] → "<合并后的内容,限100字符>"
冲突项(<N>):
[mem0:<idA>] vs [mem0:<idB>] — "<主题>" [选择A/B/跳过]
清理项(<N>):
[mem0:<id>] — <类型>,已创建<age>天
拟执行:<N>次合并,<N>次清理,<N>个冲突。是否应用?[Y/n]
如果某分类下无条目,则完全省略该部分。
如果没有任何拟议变更(无合并、无清理、无冲突),打印:
Dream完成。未发现重复、矛盾或过期的记忆。
并终止流程。
---Step 5: Wait for User Input and Apply
步骤5:等待用户输入并应用变更
5a. Contradictions
5a. 处理矛盾内容
For each pair in the report, wait for the user to type , , or
(case-insensitive). If they enter nothing (empty), treat as .
CONFLICTABskipskipRecord the winner for each pair before proceeding to the final apply confirmation.
针对报告中的每个对,等待用户输入、或(不区分大小写)。如果用户输入为空(直接回车),视为。
CONFLICTABskipskip在进入最终确认步骤前,记录每对冲突的胜出者。
5b. Final confirmation
5b. 最终确认
After all conflict resolutions are collected, prompt:
Apply? [Y/n]If the user types or (case-insensitive), print
and stop.
nnoCancelled. No changes made.If the user confirms (, , or empty / Enter), apply all changes in this order:
Yyes收集完所有冲突的解决方案后,提示:
是否应用?[Y/n]如果用户输入或(不区分大小写),打印并终止流程。
nno已取消。未进行任何修改。如果用户确认(输入、或直接回车),按以下顺序应用所有变更:
YyesMerges
合并操作
For each approved merge pair:
delete_memory(<id1>)delete_memory(<id2>)- with:
add_memorytext="<merged content>"user_id=<active_user_id>- (top-level, not in metadata)
app_id=<active_project_id> metadata={"type": "<original type>", "branch": "<active_branch>", "confidence": <higher of the two original scores>, "source": "mem0-dream"}infer=False
针对每个已批准的合并对:
delete_memory(<id1>)delete_memory(<id2>)- 调用接口,参数如下:
add_memorytext="<合并后的内容>"user_id=<active_user_id>- (顶级参数,不在metadata中)
app_id=<active_project_id> metadata={"type": "<原类型>", "branch": "<当前分支>", "confidence": <两个原记忆中较高的置信度>, "source": "mem0-dream"}infer=False
Contradictions (resolved)
已解决的矛盾内容
For each resolved conflict where the user chose A or B:
- Delete the loser (the non-chosen memory):
delete_memory(memory_id=<loser_id>)
Contradictions where the user chose are left untouched.
skip针对每个用户选择了A或B的已解决冲突:
- 删除失败的记忆(未被选中的记忆):
delete_memory(memory_id=<loser_id>)
用户选择的矛盾内容将保持不变。
skipPrunes
清理操作
For each prune candidate:
delete_memory(<memory_id>)
针对每个清理候选:
delete_memory(<memory_id>)
Step 6: Print Summary
步骤6:打印汇总
After all changes are applied, print:
Dream complete — merged: <N>, pruned: <N>, conflicts resolved: <N>, skipped: <N>所有变更应用完成后,打印:
Dream完成 — 合并:<N>,清理:<N>,已解决冲突:<N>,已跳过:<N>Auto mode
自动模式
When invoked with (e.g., ), run non-interactively:
--auto/mem0:dream --auto- Merges: applied automatically (no contradiction, both are compatible).
- Prunes: applied automatically (age/confidence-based, no ambiguity).
- Contradictions: skipped — they require human judgment.
当使用参数调用时(例如:),以非交互模式运行:
--auto/mem0:dream --auto- 合并操作:自动应用(无矛盾,内容兼容)。
- 清理操作:自动应用(基于时长/置信度,无歧义)。
- 矛盾内容:跳过——需要人工判断。
Concurrency guard
并发防护
Before doing any work, check for a lock file at :
/tmp/mem0_dream_auto.lock- If the lock file exists and is less than 10 minutes old, print and stop.
[mem0-dream --auto] Another run in progress — skipping. - Otherwise, create the lock file (write the current timestamp). Delete it when done (in all exit paths).
在执行任何操作前,检查锁文件:
/tmp/mem0_dream_auto.lock- 如果锁文件存在且创建时间不超过10分钟,打印并终止流程。
[mem0-dream --auto] 另一个运行实例正在进行中 — 已跳过。 - 否则,创建锁文件(写入当前时间戳)。在所有退出路径中删除该文件。
Execution
执行流程
In auto mode:
- Load policies and fetch memories (Steps 1–3) as normal.
- Apply merges and prunes silently without printing the diff or prompting.
- Print a compact summary:
[mem0-dream --auto] project=<id> merged=<N> pruned=<N> conflicts_skipped=<N> - If contradictions were detected but skipped, check if a reminder already exists before storing one:
mem0-dream-auto- Search for existing reminders:
search_memories(query="mem0-dream contradictions manual review", filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<active_project_id>"}, {"metadata": {"source": "mem0-dream-auto"}}]}, top_k=1) - If a result exists with similarity > 0.9, skip storing the reminder (one already exists).
- If no match, store the reminder:
pythonadd_memory( text="mem0-dream detected <N> contradiction(s) requiring manual review. Run /mem0:dream to resolve them interactively.", user_id="<active_user_id>", app_id="<active_project_id>", metadata={"type": "task_learning", "source": "mem0-dream-auto", "branch": "<active_branch>"}, infer=False, ) - Search for existing reminders:
在自动模式下:
- 正常加载策略并获取记忆(步骤1–3)。
- 静默应用合并和清理操作,不打印差异报告或提示用户。
- 打印简洁汇总:
[mem0-dream --auto] project=<id> merged=<N> pruned=<N> conflicts_skipped=<N> - 如果检测到矛盾内容但已跳过,在存储提醒前检查是否已存在提醒:
mem0-dream-auto- 搜索现有提醒:
search_memories(query="mem0-dream contradictions manual review", filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<active_project_id>"}, {"metadata": {"source": "mem0-dream-auto"}}]}, top_k=1) - 如果存在相似度>0.9的结果,跳过存储提醒(已存在)。
- 如果无匹配结果,存储提醒:
pythonadd_memory( text="mem0-dream检测到<N>个需要人工审核的矛盾内容。运行/mem0:dream以交互方式解决。", user_id="<active_user_id>", app_id="<active_project_id>", metadata={"type": "task_learning", "source": "mem0-dream-auto", "branch": "<active_branch>"}, infer=False, ) - 搜索现有提醒:
See also
另请参阅
- — targeted deletion of specific memories (search + confirm + delete)
/mem0:forget - — quick quality scan without applying changes
/mem0:health --deep
- — 定向删除特定记忆(搜索 + 确认 + 删除)
/mem0:forget - — 快速质量扫描,不应用变更
/mem0:health --deep