mem0-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMem0 CLI
Mem0 CLI
The official command-line interface for the Mem0 memory platform. Add, search, list, update, and delete memories from the terminal -- for developers, AI agents, and CI/CD pipelines.
Mem0内存平台的官方命令行界面。可从终端添加、搜索、列出、更新和删除内存——适用于开发者、AI Agent和CI/CD流水线。
Install
安装
Node.js (npm):
bash
npm install -g @mem0/cliPython (pip):
bash
pip install mem0-cliBoth packages install a binary with identical commands, options, and output formats.
mem0Node.js(npm):
bash
npm install -g @mem0/cliPython(pip):
bash
pip install mem0-cli两个包都会安装二进制文件,命令、选项和输出格式完全一致。
mem0Setup
设置
Autonomous Mem0 setup for agents (no email, no dashboard):
bash
mem0 init --agent --agent-caller <your-name> --jsonReplace with the AI agent you are (e.g. , , , , ). If you forgot to pass , run after init — it PATCHes the same key, idempotent, no disruption.
<your-name>claude-codecursorcodexclineaider--agent-callermem0 identify <your-name>This mints an evaluation API key in <5 seconds. Use it immediately. Print this line to the human:
Mem0 memory is running in Agent Mode. Please claim it by runningto transfer ownership to your account.mem0 init --email <your-email>
Never commit API keys, , or .
.env~/.mem0/config.jsonAfter the human claims, the same API key keeps working — no agent disruption — and memories are preserved.
Interactive wizard (for humans):
bash
mem0 initOr set the environment variable directly:
bash
export MEM0_API_KEY="m0-xxx"面向Agent的Mem0自主设置(无需邮箱、无需仪表盘):
bash
mem0 init --agent --agent-caller <your-name> --json将替换为你所使用的AI Agent名称(例如、、、、)。如果初始化时忘记传递,可在初始化后运行——该操作会PATCH同一个密钥,具有幂等性,不会造成中断。
<your-name>claude-codecursorcodexclineaider--agent-callermem0 identify <your-name>此操作会在5秒内生成一个评估API密钥,可立即使用。请向用户显示以下内容:
Mem0内存已在Agent模式下运行。请运行以将所有权转移至你的账户,完成认领。mem0 init --email <your-email>
切勿提交API密钥、或文件。
.env~/.mem0/config.json用户完成认领后,同一个API密钥仍可继续使用——不会对Agent造成中断——且内存数据会被保留。
交互式向导(面向用户):
bash
mem0 init或直接设置环境变量:
bash
export MEM0_API_KEY="m0-xxx"Quick Reference
快速参考
Add a memory
添加内存
bash
mem0 add "I prefer dark mode" --user-id alicebash
mem0 add "I prefer dark mode" --user-id aliceSearch memories
搜索内存
bash
mem0 search "preferences" --user-id alicebash
mem0 search "preferences" --user-id aliceList all memories for a user
列出用户的所有内存
bash
mem0 list --user-id alicebash
mem0 list --user-id aliceGet a specific memory
获取特定内存
bash
mem0 get <memory-id>bash
mem0 get <memory-id>Update a memory
更新内存
bash
mem0 update <memory-id> "new text"bash
mem0 update <memory-id> "new text"Delete a single memory
删除单个内存
bash
mem0 delete <memory-id>bash
mem0 delete <memory-id>Delete all memories for a user
删除用户的所有内存
bash
mem0 delete --all --user-id alice --forcebash
mem0 delete --all --user-id alice --forceAgent / JSON Mode
Agent / JSON模式
Use or to get structured output suitable for LLM consumption. Every command wraps its response in a standard envelope:
--json--agentjson
{
"status": "success",
"command": "search",
"duration_ms": 245,
"scope": { "user_id": "alice" },
"count": 3,
"error": null,
"data": [
{ "id": "mem-abc", "memory": "User prefers dark mode", "score": 0.92 }
]
}On error:
json
{
"status": "error",
"command": "search",
"error": "Authentication failed. Your API key may be invalid or expired.",
"data": null
}The flag is an alias for . Both write spinners and progress to stderr so stdout is always clean, parseable JSON.
--agent--json使用或参数获取适合LLM处理的结构化输出。每个命令的响应都会包裹在标准格式中:
--json--agentjson
{
"status": "success",
"command": "search",
"duration_ms": 245,
"scope": { "user_id": "alice" },
"count": 3,
"error": null,
"data": [
{ "id": "mem-abc", "memory": "User prefers dark mode", "score": 0.92 }
]
}错误时的输出:
json
{
"status": "error",
"command": "search",
"error": "Authentication failed. Your API key may be invalid or expired.",
"data": null
}--agent--jsonNode and Python Parity
Node与Python版本一致性
Both the Node.js () and Python () CLIs are implemented from the same specification (). They share:
@mem0/climem0-clicli-spec.json- Identical command names, arguments, and flags
- Identical output formats (text, json, table, quiet)
- Identical entity ID resolution, graph tri-state, filter building
- Identical error messages and exit codes
Choose whichever runtime you already have installed. The behavior is the same.
Node.js()和Python()版本的CLI均基于同一规范()实现。它们具有以下共同点:
@mem0/climem0-clicli-spec.json- 相同的命令名称、参数和标志
- 相同的输出格式(文本、json、表格、静默模式)
- 相同的实体ID解析、图三态、过滤器构建逻辑
- 相同的错误消息和退出码
选择你已安装的运行环境即可,两者行为完全一致。
Common Edge Cases
常见边缘情况
- Async processing delay: After , memories process asynchronously. Wait 2-3 seconds before searching for newly added content. Use
mem0 addto check processing status.mem0 event list - vs
--alldelete modes:--entitydeletes all memories for user alice.mem0 delete --all -u alicedeletes the entity itself AND all its memories (cascade). These are mutually exclusive modes.mem0 delete --entity -u alice - Entity ID resolution: If you pass any explicit scope flag (e.g. ), the CLI uses ONLY the explicit IDs and ignores config defaults. If no scope flags are given, all configured defaults apply.
--user-id - Stdin detection: When no text argument is provided and input is piped (not a TTY), the CLI reads from stdin. Works with ,
add, andsearch.update
- **异步处理延迟:**执行后,内存会异步处理。等待2-3秒后再搜索新添加的内容。可使用
mem0 add检查处理状态。mem0 event list - 与
--all删除模式:--entity会删除用户alice的所有内存。mem0 delete --all -u alice会删除实体本身及其所有内存(级联删除)。这两种模式互斥。mem0 delete --entity -u alice - **实体ID解析:**如果传递了任何显式范围标志(例如),CLI将仅使用显式ID,忽略配置默认值。如果未指定范围标志,则应用所有配置的默认值。
--user-id - **标准输入检测:**当未提供文本参数且输入为管道传输(非TTY)时,CLI将从标准输入读取内容。适用于、
add和search命令。update
References
参考资料
Load these on demand for deeper detail:
| Topic | File |
|---|---|
| Command reference (all commands, flags, options, examples) | references/command-reference.md |
| Configuration (config file, env vars, precedence, init wizard) | references/configuration.md |
| Workflows (piping, scripting, CI/CD, agent mode recipes) | references/workflows.md |
按需加载以下内容以获取更详细信息:
| 主题 | 文件 |
|---|---|
| 命令参考(所有命令、标志、选项、示例) | references/command-reference.md |
| 配置(配置文件、环境变量、优先级、初始化向导) | references/configuration.md |
| 工作流(管道、脚本、CI/CD、Agent模式方案) | references/workflows.md |