POST /memory/search
语义搜索记忆,返回按相关度排序的匹配结果。
POST /cells/{cellID}/memory/search
认证
Authorization: Bearer $TOKEN
请求参数
请求体(JSON)
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
query | string | ✅ | — | 搜索查询文本 |
layer | string | 否 | — | 限定搜索的层 |
limit | int | 否 | 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"
}
]
条目字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 条目唯一 ID |
layer | string | 所属层 |
kind | string | 记忆类别 |
content | string | 记忆内容 |
namespace | string | 命名空间 |
actor | string | 归属 actor |
score | float | 语义相关度得分(0–1,越高越相关) |
created_at | string | 创建时间(RFC 3339) |
accessed_at | string | 最近访问时间(RFC 3339) |
注意事项
- 搜索结果按
score降序排列。 - 语义搜索是显式检索路径,不设
RecallQualityOK门控——即使条目被 Digest 标记为stale或Conflicted,显式搜索仍会返回。这是设计意图:记忆中心必须展示冲突,否则无人能解决。 actor由服务端从 token 中提取,搜索结果自动按 actor 可见性过滤。
错误码
| HTTP | 错误 | 说明 |
|---|---|---|
| 400 | — | query 为空 |
| 401 | — | Token 缺失或无效 |
| 403 | — | Token 权限不足 |
相关端点
- GET /memory — 按层列表(不需要语义匹配时用这个)
- GET /memory/counts — 层计数
- POST /memory — 保存记忆