存储库

存储库 - 创建、列出、删除。

存储库(store)就是您读写所依据的 user_id - 每个最终用户、智能体或主题一个隔离的记忆空间。存储库是显式的:必须先创建,再向其中存储或从中召回,否则调用返回 404。每个账户自带一个 default 存储库,因此无需创建即可开始。

隔离如何嵌套。账户拥有多个工作区;每个工作区隔离自己的记忆、API 密钥和用量(计费在账户层面共享)。存储库位于工作区之内:同一工作区的密钥共享其存储库,不同工作区之间绝不互见彼此的记忆。account → workspace → store (user_id) → memories
mem.create_store("alice")        # create (idempotent)
mem.list_stores()              # [{"user_id","created_at"}, ...]
mem.delete_store("alice")        # delete the store + all its memories
await mem.createStore("alice");
await mem.listStores();          // [{ user_id, created_at }, ...]
await mem.deleteStore("alice");     // store + all its memories
mem.create_store("alice").await?;
let stores = mem.list_stores().await?;
mem.delete_store("alice").await?;
# create
curl -X POST https://api.wontopos.com/api/v1/memory/collection \
  -H "X-API-Key: $WOS_API_KEY" -H "Content-Type: application/json" -d '{"user_id":"alice"}'
# list
curl https://api.wontopos.com/api/v1/memory/collections -H "X-API-Key: $WOS_API_KEY"
# delete (store + all its memories)
curl -X DELETE https://api.wontopos.com/api/v1/memory/collection \
  -H "X-API-Key: $WOS_API_KEY" -H "Content-Type: application/json" -d '{"user_id":"alice"}'
真实响应 - 创建
{ "user_id": "alice", "status": "created" }   // "exists" if it already did
真实响应 - 列出
{ "collections": [
  { "user_id": "default", "created_at": "2026-06-26T02:23:14Z" },
  { "user_id": "alice",   "created_at": "2026-06-26T02:24:01Z" }
], "count": 2 }
对不存在的存储库执行召回
{ "error": { "type": "not_found_error",
  "message": "Store 'ghost' does not exist. Create it first with
              POST /api/v1/memory/collection {\"user_id\":\"ghost\"}, then store or recall." } }
为每个最终用户使用一个存储库("alice""user_42"),使每个人的记忆彼此独立;个人智能体则用单个 default 存储库即可。您也可以在控制台(Memory ids → Issue)中创建和浏览存储库,无需写代码。删除存储库是永久性的 - 其下所有记忆都会被删除。 存储 id 在保存前会被折叠:转为小写,且 [a-z0-9_] 之外的字符变为 _,因此 Alice.Smithalice-smith 指向同一个存储。若第二个 id 折叠后与已有 id 相同,会以 409 拒绝,而不是悄悄共享。id 本身还须符合 [A-Za-z0-9][A-Za-z0-9._-]{0,63},所以电子邮件地址或非拉丁字符的名称不能作为存储 id,请改用内部标识符。

列出与删除存储库

mem.list_stores()                # [{"user_id","created_at"}, …]
mem.delete_store("alice")      # the store and every memory in it
await mem.listStores();
await mem.deleteStore("alice");
let stores = mem.list_stores().await?;
mem.delete_store("alice").await?;
curl -X POST   .../api/v1/memory/collections -d '{}'
curl -X DELETE .../api/v1/memory/collection  -d '{"user_id":"alice"}'