Use the SearchMemories interface to retrieve structured memories and service-generated memory files based on a query text.
Prerequisites
-
An AgentStorage instance has been created and its status is
normal, and you have obtained the instance endpoint and instance name. -
An API Key has been created.
-
Scope rules:
appIdis required and cannot be*; other fields default to__default__when omitted, and only match all values when*is explicitly passed. Memory stores that includefileoutput do not yet support wildcard Scope search; use exact Scopes and, when necessary, combine withfilterto further narrow the range.
Request parameters
|
Field |
Type |
Required |
Description |
|
|
string |
Yes |
The name of the target memory store. |
|
|
string |
Yes |
The query text, up to 8192 Unicode characters by default. |
|
|
object |
Yes |
The base query scope. |
|
|
object |
No |
A Scope Filter combined with |
|
|
object |
No |
The exact full Scope of the current conversation, used as a soft ranking signal; it must fall within the |
|
|
int |
No |
The maximum number of results returned per category, default 10, upper limit 50. |
|
|
boolean |
No |
Whether to enable Rerank for structured memories, default |
|
|
boolean |
No |
Whether to include the corresponding short-term message evidence for structured memories, default |
|
|
float |
No |
Compatibility field, range |
|
|
object |
No |
Explicit result thresholds. When both internal thresholds are set, AND logic applies. |
|
|
float |
No |
Range |
|
|
float |
No |
Range |
|
|
object |
No |
Exact match conditions for the Metadata of structured memories. At most 16 keys, each key up to 64 Unicode characters and each value up to 1024 Unicode characters; both keys and values are strings, and multiple key-value pairs are combined with AND logic. |
scope and filter can resolve to at most 1000 unique conversation Scopes; when exceeded, 400 INVALID_PARAMETER is returned. When Scope query is temporarily unavailable, 503 SERVICE_UNAVAILABLE is returned. Memory stores that include file output do not yet support wildcard Scope search; use exact Scopes and, when necessary, combine with filter to further narrow the range.
metadata performs exact matching on the full string; characters such as *, ?, commas, and equals signs are treated as ordinary characters, making it suitable for retrieving long values such as UUIDs and trace IDs. When the key count or key-value length limits are exceeded, 400 INVALID_PARAMETER is returned. For the general definition, see [Metadata](../common-objects.md#metadata).
topK applies separately to results and fileResults. Due to relevance filtering, deduplication, or insufficient visible data, the actual number of results may be less than topK; applications should not rely on a fixed number of returned items.
Request example
When using API Key authentication, pass the instance name and API Key through the x-ots-instancename and x-ots-apikey request headers.
curl -X POST https://<endpoint>/SearchMemories \
-H "x-ots-instancename: <instance-name>" \
-H "x-ots-apikey: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"memoryStoreName": "agent_memory",
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "*",
"runId": "*"
},
"filter": {"op": "eq", "field": "text", "value": "*sess*"},
"contextScope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "assistant",
"runId": "session-001"
},
"query": "用户喜欢什么饮品",
"topK": 5,
"enableRerank": true,
"includeEvidence": true,
"thresholds": {
"minSimilarity": 0.3,
"minScore": 0.2
},
"metadata": {
"source": "chat"
}
}'
Response
|
Field |
Description |
|
|
The list of structured memory results; |
|
|
The long-term memory unit; see the table below for field definitions. |
|
|
The normalized relevance score ( |
|
|
The normalized cosine similarity between the query and the memory ( |
|
|
The final ranking score that may be returned when |
|
|
The ranking explanation returned alongside |
|
|
The hit source, for example |
|
|
The list of memory file results; |
|
|
The short-term message evidence returned when |
|
|
The Scope used for the query. |
|
|
The memory store name. |
results and fileResults are returned for all memory stores, so clients can use the same response structure. Dual-output memory stores return at most topK structured results and topK file results, respectively.
fileResults elements have the following fields.
|
Field |
Description |
|
|
Fixed as |
|
|
The memory file ID. |
|
|
The memory file path. |
|
|
The file summary, which is also the text that participates in retrieval. |
|
|
The ID of the matched file version. |
|
|
The sequence number of the matched file version. |
|
|
The normalized relevance score ( |
|
|
The normalized cosine similarity between the file summary and the query ( |
Response example for a dual-output memory store:
By default, results are sorted by score in descending order. Only when the response includes rankingScore are the results re-sorted by rankingScore in descending order; session soft ranking does not overwrite score.
results[].unit has the following internal fields. The memory unit fields returned by ListMemories and GetMemory are consistent with these. embedding vectors are not returned in the response.
|
Field |
Description |
|
|
The long-term memory unit ID. |
|
|
The associated conversation key. |
|
|
The Scope to which the memory belongs; the object contains four fields: |
|
|
The memory fragment ID. |
|
|
The memory unit type, for example |
|
|
The memory name, up to 64 characters; for legacy data or when the field is empty, clients can fall back to displaying |
|
|
The memory text. |
|
|
The text used for retrieval. |
|
|
The keyword list, up to 8 keywords, each up to 32 characters. |
|
|
The list of source message IDs. |
|
|
The type label. |
|
|
The date bucket. |
|
|
The metadata object (key-value pairs provided at write time). |
|
|
The metadata as a JSON string. |
|
|
The flattened metadata string, used for filtering. |
|
|
Whether it has been deleted. |
|
|
The creation time. |
|
|
The effective time of the fact, event, or plan described; it may be earlier or later than the memory write time. |
|
|
The time of the most recent server-side update to the memory unit. |
|
|
The time source, for example |
|
|
The original precision of |
|
|
The salience score. |
|
|
The version number. |
|
|
The speaker involved in the memory (returned when the field is non-empty). |
|
|
The topic label (returned when the field is non-empty). |
|
|
The list of related entities (returned when the field is non-empty). |
|
|
Time anchor information (returned when the field is non-empty). |
|
|
The list of source message references; each element contains |
|
|
The replacement chain information when the memory is merged or updated (returned when the field is non-empty). |
|
|
Provenance fields carried by memories produced or rewritten by memory consolidation (Dream) (returned when the field is non-empty). |
When contextScope is provided, the service can prioritize memories from the current conversation among candidates with similar semantic relevance. This field only affects ranking and does not expand the data range specified by scope and filter, nor can it bypass thresholds or compatibility thresholds.
{
"memoryStoreName": "agent_memory",
"results": [
{
"unit": {
"id": "1b88d0d65a5b6c0d9142e9b7c7347048",
"conversation_key": "app-001/user-001/assistant/session-001",
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "assistant",
"runId": "session-001"
},
"memcell_id": "87e8805d6df9866dce823d135cfd6dff",
"unit_type": "entity_fact",
"text": "[2026-08-25T05:52:19Z] 我写脚本只用 Python。",
"search_text": "用户编程语言偏好\n我写脚本只用 Python。\nkeywords: Python, 脚本, 编程语言, 偏好\nPython 脚本语言 技术偏好\nuser\n记住:我的内部工号是 FALCON-9931,常驻杭州,写脚本只用 Python。\ntime: 2026-08-25T05:52:19Z",
"keywords": [
"Python",
"脚本",
"编程语言",
"偏好"
],
"source_turn_ids": [
"aa5f2e1d34b8ced5b044239f0fc75bee"
],
"source_turn_refs": [
{
"messageId": "aa5f2e1d34b8ced5b044239f0fc75bee",
"timestampMs": 1787637139185
}
],
"type_label": "profile_fact",
"date_bucket": "2026-08",
"metadata": {
"content_hash": "4ec0592b5550159a3f77b9dc62bca64e",
"session_date": "5:52 AM on 25 August, 2026",
"source_quote": "写脚本只用 Python"
},
"metadata_json": "{\"content_hash\":\"4ec0592b5550159a3f77b9dc62bca64e\",\"session_date\":\"5:52 AM on 25 August, 2026\",\"source_quote\":\"写脚本只用 Python\"}",
"metadata_flat": "content_hash=4ec0592b5550159a3f77b9dc62bca64e,session_date=5:52 AM on 25 August, 2026,source_quote=写脚本只用 Python",
"deleted": false,
"created_at": "2026-08-25T05:52:19.185Z",
"salience": 0.8,
"version": 1,
"title": "用户编程语言偏好",
"effective_at": "2026-08-25T05:52:19Z",
"updated_at": "2026-08-25T05:52:30.509Z",
"time_source": "source_message",
"time_precision": "second"
},
"score": 0.3358759430317645,
"similarity": 0.2652787210590392,
"source": "vector"
},
{
"unit": {
"id": "546b00a31ddd5e76e309e2da5cb0030e",
"conversation_key": "app-001/user-001/assistant/session-001",
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "assistant",
"runId": "session-001"
},
"memcell_id": "87e8805d6df9866dce823d135cfd6dff",
"unit_type": "entity_fact",
"text": "[2026-08-25T05:52:19Z] 我常驻杭州。",
"search_text": "用户常驻地\n我常驻杭州。\nkeywords: 杭州, 常驻, 地理位置\n杭州 常驻地 地理位置\nuser\n记住:我的内部工号是 FALCON-9931,常驻杭州,写脚本只用 Python。\ntime: 2026-08-25T05:52:19Z",
"keywords": [
"杭州",
"常驻",
"地理位置"
],
"source_turn_ids": [
"aa5f2e1d34b8ced5b044239f0fc75bee"
],
"source_turn_refs": [
{
"messageId": "aa5f2e1d34b8ced5b044239f0fc75bee",
"timestampMs": 1787637139185
}
],
"type_label": "profile_fact",
"date_bucket": "2026-08",
"metadata": {
"content_hash": "9f9821b441975f392313a2d7aec6ed6e",
"session_date": "5:52 AM on 25 August, 2026",
"source_quote": "常驻杭州"
},
"metadata_json": "{\"content_hash\":\"9f9821b441975f392313a2d7aec6ed6e\",\"session_date\":\"5:52 AM on 25 August, 2026\",\"source_quote\":\"常驻杭州\"}",
"metadata_flat": "content_hash=9f9821b441975f392313a2d7aec6ed6e,session_date=5:52 AM on 25 August, 2026,source_quote=常驻杭州",
"deleted": false,
"created_at": "2026-08-25T05:52:19.185Z",
"salience": 0.8,
"version": 1,
"title": "用户常驻地",
"effective_at": "2026-08-25T05:52:19Z",
"updated_at": "2026-08-25T05:52:30.509Z",
"time_source": "source_message",
"time_precision": "second"
},
"score": 0.32277120656532554,
"similarity": 0.25208147048454044,
"source": "vector"
},
{
"unit": {
"id": "4f6ddad33fad6f52d475c69708b44dd1",
"conversation_key": "app-001/user-001/assistant/session-001",
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "assistant",
"runId": "session-001"
},
"memcell_id": "87e8805d6df9866dce823d135cfd6dff",
"unit_type": "entity_fact",
"text": "[2026-08-25T05:52:19Z] 我的内部工号是 FALCON-9931。",
"search_text": "用户内部工号\n我的内部工号是 FALCON-9931。\nkeywords: 工号, FALCON-9931, 内部标识\nFALCON-9931 工号 身份标识\nuser\n记住:我的内部工号是 FALCON-9931,常驻杭州,写脚本只用 Python。\ntime: 2026-08-25T05:52:19Z",
"keywords": [
"工号",
"FALCON-9931",
"内部标识"
],
"source_turn_ids": [
"aa5f2e1d34b8ced5b044239f0fc75bee"
],
"source_turn_refs": [
{
"messageId": "aa5f2e1d34b8ced5b044239f0fc75bee",
"timestampMs": 1787637139185
}
],
"type_label": "profile_fact",
"date_bucket": "2026-08",
"metadata": {
"content_hash": "d0b62aedd9294009f14ed6ab951ebfed",
"session_date": "5:52 AM on 25 August, 2026",
"source_quote": "我的内部工号是 FALCON-9931"
},
"metadata_json": "{\"content_hash\":\"d0b62aedd9294009f14ed6ab951ebfed\",\"session_date\":\"5:52 AM on 25 August, 2026\",\"source_quote\":\"我的内部工号是 FALCON-9931\"}",
"metadata_flat": "content_hash=d0b62aedd9294009f14ed6ab951ebfed,session_date=5:52 AM on 25 August, 2026,source_quote=我的内部工号是 FALCON-9931",
"deleted": false,
"created_at": "2026-08-25T05:52:19.185Z",
"salience": 0.8,
"version": 1,
"title": "用户内部工号",
"effective_at": "2026-08-25T05:52:19Z",
"updated_at": "2026-08-25T05:52:30.509Z",
"time_source": "source_message",
"time_precision": "second"
},
"score": 0.2805238412257555,
"similarity": 0.23675615504707195,
"source": "vector"
}
],
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "*",
"runId": "*"
}
}