User context
You can retrieve a user profile and related memories from Long-term Memory Service in a single request. This topic describes how to use the returned user context in your application to build an Agent system prompt, generate answers, or display retrieval results.
Prerequisites
You have enabled LindormTable, the search engine, the vector engine, and the AI engine.
You have completed the Long-term Memory Service setup.
You have created a project and obtained a valid project access key (SK).
Request syntax
| Method | URI |
| POST | /lmemo/v1/users/{user_id}/context |
The request URL is the complete URL formed by combining the service endpoint and the API path.
Authentication — Include the SK in the request header as
Authorization: Bearer sk-....Request format — The JSON request body uses
Content-Type: application/json.Response format — A successful response contains
request_idanddata. For the error format, see Service Overview: Response Description.Project scope — Determined by the SK. You do not need to provide
project_id.User scope — Determined by the user parameter of each operation. For this operation,
user_idin the request path determines the user scope, and your application is responsible for verifying the user identity.
Prepare connection information
Set the following variables in the shell session in which you run the request examples:
ENDPOINT="<service endpoint>"
SK="<project SK>"Replace
<service endpoint>with the service endpoint, including the protocol, hostname, and port.Replace
<project SK>with your project SK.
Retrieve user context
Retrieve the user profile and related memories based on the user ID and the query.
This operation does not verify end-user identities. Your application is responsible for verifying the identity of a user before you pass the user ID in the request path. Otherwise, the request can return the profile and memories of a different user.
Request example
Run the following command to retrieve the user context for a user. Replace the example user ID u1 in the request path with the ID of the target user.
curl --request POST "${ENDPOINT}/lmemo/v1/users/u1/context" \
--header "Authorization: Bearer ${SK}" \
--header "Content-Type: application/json" \
--data-raw '{
"query": "What drinks does the user like?",
"memory_limit": 20
}'Request parameters
The following table describes the path parameter.
| Parameter | Required | Description |
user_id | Yes | The ID of the user whose profile and related memories are retrieved. |
Pass the following parameters in the JSON request body.
The request body and its query field are required. If the request body is missing, query is not provided, or query contains only whitespace characters, the operation returns 400 bad_request.
| Parameter | Type | Required | Description |
query | string | Yes | The text used to retrieve the user profile and related memories. The value must contain 1 to 2000 characters and cannot be blank. |
memory_limit | integer | No | The number of memories to return. Valid values: 1 to 100. Default value: 20. |
record_kinds | array | No | Restricts the memory types. For valid values, see Memory Search API. |
search_type | string | No | The search method. Valid values: vector, keyword, and hybrid. Default value: hybrid. |
intent_mode | string | No | Valid values: rrf and agentic. Default value: rrf. |
min_score | double | No | The minimum hit score. Valid values: 0 to 1. |
vector_weight, keyword_weight | double | No | The weights that act as lane switches. Valid values: 0 to 1. If both values are 0, the operation falls back to the default lane for search_type. |
rerank | boolean | No | Specifies whether to enable reranking. Default value: false. |
To verify how a request was processed, check retrieval_metadata in the response.
Response example
The following example shows a successful response:
{
"request_id": "req-xxx",
"data": {
"profile": {
"user_id": "u1",
"traits": {
"favorite_drink": "latte"
},
"summary": "...",
"updated_at": "2026-07-24T08:00:00Z"
},
"memories": [
{
"id": "mem-...",
"kind": "event_log",
"content": "The user likes latte",
"score": 0.87
}
],
"event_logs": [
{
"id": "mem-...",
"kind": "event_log",
"content": "The user likes latte",
"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
A successful response contains request_id and data. The following table describes the fields in data.
| Field | Type | Description |
profile | object | The user profile. This field is always returned. If the user has no user profile, traits is a null object. |
memories | array | The complete list of hits. Each hit contains id, kind, content, and score. A hit whose kind is profile_item appears only in memories, and the complete data for that hit is in profile in the same response. |
event_logs, episodic_memories, agent_cases, agent_skills | array | The same hits as memories, grouped by kind. The kind values correspond to the memory types that record_kinds accepts. |
retrieval_metadata | object | Metadata about how the request was processed, such as the retrieval mode and whether reranking was applied. |
Next steps
User context does not include conversation history. To retrieve the most recent conversation messages, call
GET /lmemo/v1/sessions/{session_id}/messages. For more information, see Conversations and Messages API.To display the evidence behind a memory, use the memory record fields
event_timeandmentioned_at, which the user context response does not return. Retrieve them from the Memory Record API or Memory Search API: Extended Memory Sources. Unlikeevent_timeandmentioned_at,created_atindicates the storage time.