Memory

更新时间:
复制 MD 格式

阿里云百炼 CLI 管理长期记忆与用户画像的命令速查。

在终端管理阿里云百炼长期记忆:记忆的增删改查、用户画像 schema 的创建与查询。

说明长期记忆相关能力目前仅对中国站(aliyun.com)账号开放。

重要任意命令追加 --help 可查看完整参数说明,例如 bl memory search --help。本文命令明细以 bl 2.2.1 为基准核实。

在各功能页也可查看对应用法,见 记忆库。

命令速查

bl memory add

从消息或自定义内容添加记忆。需要 API Key 鉴权。

语法

bl memory add --user-id <id> [--messages <json>] [--content <text>] [flags]
参数类型必填说明
--user-id <id>string是用户 ID
--messages <json>string否消息 JSON 数组:[{"role":"user","content":"..."},...]
--content <text>string否要记忆的自定义内容文本
--profile-schema <id>string否用于用户画像的 Profile Schema ID
--memory-library-id <id>string否记忆库 ID(用于隔离记忆空间)

示例:添加用户自定义记忆内容

bl memory add --user-id user1 --content "用户喜欢使用 Python 编程"

通过查询文本或消息搜索记忆节点。需要 API Key 鉴权。

语法

bl memory search --user-id <id> [--query <text>] [flags]
参数类型必填说明
--user-id <id>string是用户 ID
--query <text>string否搜索查询文本
--messages <json>string否用于上下文搜索的消息 JSON 数组
--top-k <n>number否返回结果数量(默认:10)
--memory-library-id <id>string否记忆库 ID

示例:搜索用户指定的内存节点

bl memory search --user-id user1 --query "编程偏好"

bl memory list

列出用户的记忆节点。需要 API Key 鉴权。

语法

bl memory list --user-id <id> [flags]
参数类型必填说明
--user-id <id>string是用户 ID
--page-size <n>number否每页结果数(默认:10)
--page <n>number否页码(默认:1)
--memory-library-id <id>string否记忆库 ID

示例:列出指定用户的记忆节点

bl memory list --user-id user1

bl memory update

更新记忆节点内容。需要 API Key 鉴权。

语法

bl memory update --node-id <id> --user-id <id> --content <text>
参数类型必填说明
--node-id <id>string是记忆节点 ID
--user-id <id>string是用户 ID
--content <text>string是记忆节点的新内容
--memory-library-id <id>string否记忆库 ID(非默认记忆库)

示例:更新指定记忆节点的内容

bl memory update --node-id node_xxx --user-id user1 --content "更新后的记忆内容"

bl memory delete

删除记忆节点。需要 API Key 鉴权。

语法

bl memory delete --node-id <id> --user-id <id>
参数类型必填说明
--node-id <id>string是记忆节点 ID
--user-id <id>string是用户 ID
--memory-library-id <id>string否记忆库 ID(非默认记忆库)

示例:删除指定的记忆节点

bl memory delete --node-id node_xxx --user-id user1

bl memory profile create

创建用于记忆画像的用户 Profile Schema。需要 API Key 鉴权。

语法

bl memory profile create --name <name> --attributes <json> [flags]
参数类型必填说明
--name <name>string是Schema 名称
--description <text>string否Schema 描述
--attributes <json>string是属性 JSON 数组:[{"name":"age","description":"age"}]

示例:创建用户记忆画像的 Schema

bl memory profile create --name "user_basic" --attributes '[{"name":"age","description":"年龄"},{"name":"hobby","description":"爱好"}]'

bl memory profile get

通过 Schema ID 和用户 ID 获取用户画像。需要 API Key 鉴权。

语法

bl memory profile get --schema-id <id> --user-id <id>
参数类型必填说明
--schema-id <id>string是Profile Schema ID
--user-id <id>string是用户 ID

示例:获取指定用户的画像数据

bl memory profile get --schema-id schema_xxx --user-id user1