Memory search
Lindorm Long-term Memory Service supports keyword retrieval, vector retrieval, and hybrid retrieval, and lets you query the source records and evidence associated with memories. This topic describes how to search memories and expand memory sources.
Workflow
Tracing a memory back to its source is a chain of three API calls:
Search memories — Call
POST /lmemo/v1/memories/searchto retrieve theidandkindof the memories relevant to a query. This call is documented in Search memories.Retrieve the memory record — Call
GET /lmemo/v1/memory-records/{memory_id}to retrieve the memory record, which includes the source relationship fieldsmem_cell_id,parent_id, andparent_type..Expand memory sources — Call
POST /lmemo/v1/memories/source-expandto query parent episodic memories, sibling event logs, source segments, and raw evidence snippets in batches. This call is documented in Expand memory sources.
Prerequisites
You have enabled LindormTable, the search engine, the vector engine, and the AI engine, and completed the Long-term Memory Service activation configuration.
You have created a project and obtained a valid Secret Key (SK).
Request details
Item | Description |
Request URL | The complete URL formed by combining the service endpoint and the API path. |
Authentication | Include |
Project scope | Determined by the SK. You do not need to provide |
User scope | Determined by the user parameters for each API. |
Request format | The JSON request body uses |
Response format | A successful response contains |
Your application is responsible for validating user identities.
Before you run the example commands in this topic, set the following shell variables. Replace ENDPOINT with the service endpoint, including the protocol, hostname, and port. Replace SK with the Secret Key (SK) of your project.
ENDPOINT="<service endpoint>"
SK="<project SK>"The IDs in the example commands are example values. Replace them with actual values.
Search memories
Query relevant memories by user ID and search query. Specify memory kinds, retrieval methods, and filter conditions as needed.
Request example
The following example shows a memory search request:
curl --request POST "${ENDPOINT}/lmemo/v1/memories/search" \
--header "Authorization: Bearer ${SK}" \
--header "Content-Type: application/json" \
--data-raw '{
"user_id": "u1",
"query": "What beverages does the user like?",
"limit": 20
}'Request parameters
Pass the following parameters in the JSON request body.
Parameter | Type | Required | Description |
| string | Yes | The user ID. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
| string | Yes | The search query. The value must contain 1 to 4096 characters and cannot contain only whitespace characters. |
| integer | No | The number of results to return. Valid values: 1 to 100. Default value: 20. |
| array | No | Limits the search to the specified memory kinds. For the valid kinds and where each kind appears in the response, see Memory kinds. |
| string | No | The retrieval method. Valid values: |
| string | No |
|
| object | No | The filter conditions. For more information, see Filter conditions. |
| double | No | Filters out results with a score lower than this value. Valid values: 0 to 1. [TODO: confirm - default value, and whether the threshold applies before or after reranking] |
| double | No | The channel switch for vector retrieval. Valid values: 0 to 1. A value of 0 disables the channel, and a positive value enables it. For more information, see Retrieval modes. |
| double | No | The channel switch for keyword retrieval. Valid values: 0 to 1. A value of 0 disables the channel, and a positive value enables it. For more information, see Retrieval modes. |
| boolean | No | Specifies whether to use a reranking model. Default value: false. For the fallback behavior when reranking fails or the reranking model service is unavailable, see Reranking behavior. |
Response example
The following example shows a response that contains one matched memory:
{
"request_id": "req-xxx",
"data": {
"memories": [
{
"id": "mem-...",
"kind": "event_log",
"content": "The user likes lattes",
"score": 0.87
}
],
"event_logs": [
{
"id": "mem-...",
"kind": "event_log",
"content": "The user likes lattes",
"score": 0.87
}
],
"episodic_memories": [],
"agent_cases": [],
"agent_skills": [],
"retrieval_metadata": {
"mode": "rrf",
"is_multi_round": false,
"round1_count": 1,
"final_count": 1,
"rerank_applied": false,
"vector_lane_enabled": true,
"keyword_lane_enabled": true,
"retrieval_count": 1,
"rerank_requested": false
}
}
}Response parameters
Field | Description |
| The request ID. |
| The complete list of matched results. Each matched item always contains four fields: |
| The matched results of kind |
| The matched results of kind |
| The matched results of kind |
| The matched results of kind |
| The retrieval metadata. |
The grouping arrays contain the same results as memories, grouped by kind. Matches of kind profile_item appear only in memories; no separate profile_items field is available.
To trace a matched memory back to its source segments and raw evidence snippets, follow the call chain in Workflow and Procedure. To retrieve the complete user profile for a profile_item match, call GET /lmemo/v1/profiles/{user_id}.
Memory kinds
The following table maps each memory kind to its location in the search response, its validity as a record_kinds value, and its validity as a refs kind value for source expansion.
Kind | Search response location | Valid | Valid |
|
| Yes | Yes |
|
| Yes | Yes |
|
| Yes | No. Read |
| No dedicated array. | Yes | Yes |
|
| Yes | Yes |
|
| Yes | Yes |
| [Description pending] | No | Yes. [TODO: confirm - how to obtain a |
Retrieval modes
The intent_mode parameter selects the retrieval strategy:
rrf(default): Retrieves results based onsearch_typeand the channel switches. When both channels are enabled, the API uses RRF fusion ranking.agentic: Uses LLM-assisted multi-round retrieval for complex queries and typically has higher latency.
The channel switches vector_weight and keyword_weight enable or disable the two retrieval channels:
Valid values: 0 to 1. A value of 0 disables the corresponding channel, and a positive value enables it.
If both values are 0, the API falls back to the default channels for
search_type.hybriduses RRF fusion ranking and does not apply numeric weighting.
Reranking behavior
Reranking is subject to the following fallback behavior:
If reranking fails, the API returns the original ranking results.
If the reranking model service is unavailable, the response sets
retrieval_metadata.rerank_unavailabletotrue.If no reranking client is configured, the API does not rerank results and sets
retrieval_metadata.rerank_appliedtofalsein the response.
Filter conditions
The filters object supports and and or condition groups. Each condition includes field, operator, and value. For a single-field equality condition, you can use the shorthand form of a single-field object. The eq operator is supported for scalar fields.
The following example shows a search request with filter conditions:
curl --request POST "${ENDPOINT}/lmemo/v1/memories/search" \
--header "Authorization: Bearer ${SK}" \
--header "Content-Type: application/json" \
--data-raw '{
"user_id": "u1",
"query": "What beverages does the user like?",
"filters": {
"and": [
{
"field": "session_id",
"operator": "eq",
"value": "session-001"
},
{
"agent_id": "a1"
}
],
"or": []
}
}'Other keys at the top level of filters are treated as and equivalent conditions.
Expand memory sources
The source expansion API queries parent episodic memories, sibling event logs, source segments (source_memcells), and raw conversation evidence (raw_evidence_snippets) in batches, based on the source relationships explicitly provided in refs. Replace the memory ID and the source segment ID (mem_cell_id) in the following commands with the values returned in the memory record.
Procedure
Call the memory search API to retrieve the
idandkindof relevant memories, excluding results of kindprofile_item.Call
GET /lmemo/v1/memory-records/{memory_id}?user_id=<user_id>to retrieve the memory record, includingmem_cell_id,parent_id, andparent_type.Build
refsand call the source expansion API. To query source segments and sibling event logs, providemem_cell_id. To query the parent episodic memory of an event log, provide itsparent_idand confirm thatparent_type=episodic_memory.
Request example
The following example shows a source expansion request:
curl --request POST "${ENDPOINT}/lmemo/v1/memories/source-expand" \
--header "Authorization: Bearer ${SK}" \
--header "Content-Type: application/json" \
--data-raw '{
"user_id": "u1",
"refs": [
{
"id": "mem-event-001",
"kind": "event_log",
"mem_cell_id": "cell-001",
"parent_id": "mem-episode-001"
}
],
"include_raw_evidence_snippets": true,
"query": "The user's beverage preferences",
"raw_evidence_recent_memcells": 0
}'Request parameters
Pass the following parameters in the JSON request body.
Parameter | Type | Required | Description |
| string | Yes | The user ID. |
| array | No | The memory references to expand. The default value is an empty array. Each item must contain a valid |
| string | No | Used to rank the relevance of evidence snippets. The maximum length is 4096 characters. |
| boolean | No | Specifies whether to return parent episodic memories in |
| boolean | No | Specifies whether to return sibling event logs in |
| boolean | No | Specifies whether to return source segments in |
| boolean | No | Specifies whether to return raw evidence snippets in |
| integer | No | Valid values: 0 to 100. Default value: 16. |
| integer | No | Valid values: 0 to 500. Default value: 64. |
| integer | No | Valid values: 0 to 100. Default value: 16. |
| integer | No | Valid values: 0 to 32. Default value: 8. |
| integer | No | The context window for evidence snippets. Valid values: 0 to 3. Default value: 1. [TODO: confirm - the unit of the context window] |
| integer | No | The number of recent source segments to scan when retrieving evidence. Valid values: 0 to 300. Default value: 80. |
The refs item fields:
Field | Description |
| Optional. The input reference ID, used to identify the reference and exclude matched sibling event logs. It is not used alone to find a source. |
| Required. Valid values: |
| Required to query source segments and sibling event logs. |
| Provide this field when |
When you build refs, select results of kind event_log, episodic_memory, agent_memory, agent_case, or agent_skill. Read profile_item results through the user profile API.
Response example
The following example shows the shape of an empty expansion response:
{
"request_id": "req-xxx",
"data": {
"parent_episodes": [],
"sibling_event_logs": [],
"source_memcells": [],
"raw_evidence_snippets": [],
"expansion_metadata": {
"input_refs": 1,
"unique_mem_cells": 1,
"parent_episodes": 0,
"sibling_event_logs": 0,
"source_memcells": 0,
"raw_evidence_snippets": 0
}
}
}On a successful expansion, source_memcells and sibling_event_logs are populated for a reference that provides mem_cell_id, and parent_episodes is populated for an event log reference that provides a parent_id with parent_type=episodic_memory. raw_evidence_snippets are returned only when include_raw_evidence_snippets is true and a non-empty query is provided.
Response parameters
Field | Description |
| The request ID. |
| The parent episodic memories. Items are memory records and do not contain |
| The sibling event logs. Items are memory records and do not contain |
| The source segments. Items include |
| The raw evidence snippets. Items include |
| The expansion counters: |
For the other fields of the memory records in parent_episodes and sibling_event_logs, see the response in Memory records API.
By default, raw evidence retrieval covers both the specified source segments and the 80 most recent source segments for the same user. To limit retrieval to the specified sources, set raw_evidence_recent_memcells to 0 and provide mem_cell_id in refs.