Memory search

Updated at:

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:

  1. Search memories — Call POST /lmemo/v1/memories/search to retrieve the id and kind of the memories relevant to a query. This call is documented in Search memories.

  2. Retrieve the memory record — Call GET /lmemo/v1/memory-records/{memory_id} to retrieve the memory record, which includes the source relationship fields mem_cell_id, parent_id, and parent_type..

  3. Expand memory sources — Call POST /lmemo/v1/memories/source-expand to 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 Authorization: Bearer sk-... in the request header.

Project scope

Determined by the SK. You do not need to provide project_id.

User scope

Determined by the user parameters for each API.

Request format

The JSON request body uses Content-Type: application/json.

Response format

A successful response contains request_id and data. For error formats, see Service overview: Response format.

Important

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

user_id

string

Yes

The user ID. Only letters, digits, underscores (_), and hyphens (-) are allowed.

query

string

Yes

The search query. The value must contain 1 to 4096 characters and cannot contain only whitespace characters.

limit

integer

No

The number of results to return. Valid values: 1 to 100. Default value: 20.

record_kinds

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.

search_type

string

No

The retrieval method. Valid values: vector, keyword, hybrid. Default value: hybrid. For more information, see Retrieval modes.

intent_mode

string

No

rrf (default) or agentic. For more information, see Retrieval modes.

filters

object

No

The filter conditions. For more information, see Filter conditions.

min_score

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]

vector_weight

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.

keyword_weight

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.

rerank

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

request_id

The request ID.

data.memories

The complete list of matched results. Each matched item always contains four fields: id, kind, content, and score.

data.event_logs

The matched results of kind event_log.

data.episodic_memories

The matched results of kind episodic_memory.

data.agent_cases

The matched results of kind agent_case.

data.agent_skills

The matched results of kind agent_skill.

data.retrieval_metadata

The retrieval metadata. rerank_applied is set to false when no reranking client is configured. rerank_unavailable is set to true when the reranking model service is unavailable; this field is absent from the success-path response example. The meanings of mode, is_multi_round, round1_count, final_count, vector_lane_enabled, keyword_lane_enabled, retrieval_count, and rerank_requested are [Description pending].

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 record_kinds value

Valid refs kind

event_log

event_logs

Yes

Yes

episodic_memory

episodic_memories

Yes

Yes

profile_item

memories only

Yes

No. Read profile_item results through the user profile API.

agent_memory

No dedicated array. agent_memory includes agent_case and agent_skill.

Yes

Yes

agent_case

agent_cases

Yes

Yes

agent_skill

agent_skills

Yes

Yes

mem_cell

[Description pending]

No

Yes. [TODO: confirm - how to obtain a mem_cell reference for source expansion]

Retrieval modes

The intent_mode parameter selects the retrieval strategy:

  • rrf (default): Retrieves results based on search_type and 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.

  • hybrid uses 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_unavailable to true.

  • If no reranking client is configured, the API does not rerank results and sets retrieval_metadata.rerank_applied to false in 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

  1. Call the memory search API to retrieve the id and kind of relevant memories, excluding results of kind profile_item.

  2. Call GET /lmemo/v1/memory-records/{memory_id}?user_id=<user_id> to retrieve the memory record, including mem_cell_id, parent_id, and parent_type.

  3. Build refs and call the source expansion API. To query source segments and sibling event logs, provide mem_cell_id. To query the parent episodic memory of an event log, provide its parent_id and confirm that parent_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

user_id

string

Yes

The user ID.

refs

array

No

The memory references to expand. The default value is an empty array. Each item must contain a valid kind. For the item fields, see the refs item fields table in this section. [TODO: confirm - the API behavior when refs is empty]

query

string

No

Used to rank the relevance of evidence snippets. The maximum length is 4096 characters.

include_parent_episodes

boolean

No

Specifies whether to return parent episodic memories in parent_episodes. Default value: true.

include_sibling_event_logs

boolean

No

Specifies whether to return sibling event logs in sibling_event_logs. Default value: true.

include_source_memcells

boolean

No

Specifies whether to return source segments in source_memcells. Default value: true.

include_raw_evidence_snippets

boolean

No

Specifies whether to return raw evidence snippets in raw_evidence_snippets. Default value: false. Raw evidence snippets are returned only when a non-empty query is provided.

max_parent_episodes

integer

No

Valid values: 0 to 100. Default value: 16.

max_sibling_event_logs

integer

No

Valid values: 0 to 500. Default value: 64.

max_source_memcells

integer

No

Valid values: 0 to 100. Default value: 16.

max_raw_evidence_snippets

integer

No

Valid values: 0 to 32. Default value: 8.

raw_evidence_window

integer

No

The context window for evidence snippets. Valid values: 0 to 3. Default value: 1. [TODO: confirm - the unit of the context window]

raw_evidence_recent_memcells

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

id

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.

kind

Required. Valid values: mem_cell, episodic_memory, event_log, agent_memory, agent_case, and agent_skill. For where each kind comes from, see Memory kinds.

mem_cell_id

Required to query source segments and sibling event logs.

parent_id

Provide this field when kind=event_log and you need to query a parent episodic memory. The value must be the episodic memory ID.

Note

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

request_id

The request ID.

data.parent_episodes

The parent episodic memories. Items are memory records and do not contain score.

data.sibling_event_logs

The sibling event logs. Items are memory records and do not contain score.

data.source_memcells

The source segments. Items include raw_messages, participants, start_at, and end_at. This list is not exhaustive.

data.raw_evidence_snippets

The raw evidence snippets. Items include content, event_time, score, and source_message_ids. This list is not exhaustive.

data.expansion_metadata

The expansion counters: input_refs, unique_mem_cells, parent_episodes, sibling_event_logs, source_memcells, and raw_evidence_snippets. [Description pending]

For the other fields of the memory records in parent_episodes and sibling_event_logs, see the response in Memory records API.

Note

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.