关于 switch-project
用于更改当前目录所用项目范围或启用全局记忆搜索的 Mem0 技能。它将项目映射和搜索设置保存在本地文件中。
主要功能
- 01为目录设置项目范围
- 02启用全局记忆搜索
- 03关闭全局记忆搜索
- 04在本地文件中保存设置
适用场景
- 01将记忆搜索限定到指定项目
- 02跨项目和用户搜索记忆
- 03恢复按项目划分的搜索范围
MCP 相关
通过 Mem0 MCP 的 search_memories 工具搜索记忆,以验证项目范围变更。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mem0ai/ mem0 --skill switch-project安装后在 Claude Code 中输入/switch-project确认已加载。
详细介绍
Mem0 项目切换
覆盖当前目录的自动 project_id 检测,或启用全局搜索模式。
用法
/mem0:switch-project <project-name>— 切换到指定的项目范围/mem0:switch-project --global— 启用全局搜索(所有记忆、所有用户、所有项目)/mem0:switch-project --no-global— 禁用全局搜索并返回按项目划分的范围
执行
如果提供了 --global 标志:
-
使用 Bash 工具在
~/.mem0/settings.json中设置global_search: true:python3 -c " import json, os settings_file = os.path.expanduser('~/.mem0/settings.json') settings = {} if os.path.isfile(settings_file): with open(settings_file) as f: settings = json.load(f) settings['global_search'] = True with open(settings_file, 'w') as f: json.dump(settings, f, indent=2) print('Global search enabled') " -
输出:
Global search enabled. Searches now return all memories across all users and projects. Writes still use the current user_id and app_id. Restart the session for the change to take effect.
如果提供了 --no-global 标志:
-
使用 Bash 工具在
~/.mem0/settings.json中设置global_search: false:python3 -c " import json, os settings_file = os.path.expanduser('~/.mem0/settings.json') settings = {} if os.path.isfile(settings_file): with open(settings_file) as f: settings = json.load(f) settings['global_search'] = False with open(settings_file, 'w') as f: json.dump(settings, f, indent=2) print('Global search disabled') " -
输出:
Global search disabled. Searches now return only memories scoped to the current project. Restart the session for the change to take effect.
如果提供了项目名称(没有标志):
-
如果未提供项目名称,请询问:“此目录应使用什么 project_id?”
-
使用 Bash 工具将映射写入
~/.mem0/project_map.json:python3 -c " import json, os map_file = os.path.expanduser('~/.mem0/project_map.json') mapping = {} if os.path.isfile(map_file): with open(map_file) as f: mapping = json.load(f) mapping[os.getcwd()] = '<PROJECT_NAME>' os.makedirs(os.path.dirname(map_file), exist_ok=True) with open(map_file, 'w') as f: json.dump(mapping, f, indent=2) print(f'Mapped {os.getcwd()} -> <PROJECT_NAME>') "(将
<PROJECT_NAME>替换为用户选择的项目名称。) -
通过搜索现有记忆进行验证:
- 使用
query="project"、filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<PROJECT_NAME>"}]}、top_k=1调用search_memories
- 使用
-
输出:
Switched to project <PROJECT_NAME>. <N> memories found for this project. Note: This override persists across sessions for this directory.
评论
支持 Markdown