POST /memory/search

语义搜索记忆,返回按相关度排序的匹配结果。

POST /cells/{cellID}/memory/search

认证

Authorization: Bearer $TOKEN

请求参数

请求体(JSON)

字段类型必填默认值说明
querystring✅—搜索查询文本
layerstring否—限定搜索的层
limitint否10返回结果数量上限

请求示例

搜索与"编辑器配置"相关的记忆:

curl -X POST "http://localhost:9091/cells/dept-legal/memory/search" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "编辑器配置",
    "limit": 5
  }'

在 agent_memory 层中搜索:

curl -X POST "http://localhost:9091/cells/dept-legal/memory/search" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "项目技术栈",
    "layer": "agent_memory",
    "limit": 10
  }'

响应

成功(200 OK)

[
  {
    "id": "mem-abc123",
    "layer": "about_me",
    "kind": "preference",
    "content": "我喜欢使用 Vim 键位的编辑器",
    "namespace": "",
    "actor": "alice",
    "score": 0.87,
    "created_at": "2026-09-20T10:30:00Z",
    "accessed_at": "2026-09-21T08:15:00Z"
  },
  {
    "id": "mem-ghi789",
    "layer": "agent_memory",
    "kind": "fact",
    "content": "VS Code 配置了 Go 扩展和 Vim 模拟",
    "namespace": "agent-coder",
    "actor": "alice",
    "score": 0.72,
    "created_at": "2026-09-18T09:00:00Z",
    "accessed_at": "2026-09-19T11:20:00Z"
  }
]

条目字段

字段类型说明
idstring条目唯一 ID
layerstring所属层
kindstring记忆类别
contentstring记忆内容
namespacestring命名空间
actorstring归属 actor
scorefloat语义相关度得分(0–1,越高越相关)
created_atstring创建时间(RFC 3339)
accessed_atstring最近访问时间(RFC 3339)

注意事项

错误码

HTTP错误说明
400—query 为空
401—Token 缺失或无效
403—Token 权限不足

相关端点