---
type: api
title: Remember a session memory
description: "Writes one memory to the session memory store. Pass `id` to revise an existing memory. The revision replaces the memory in full."
url: https://www.elastic.co/elastic/docs-builder/docs/5002/api/kibana-serverless/operation/operation-post-context-engine-memory-remember
resource: https://www.elastic.co/elastic/docs-builder/docs/5002/api/kibana-serverless/operation/operation-post-context-engine-memory-remember
products:
  - Kibana
---

# Remember a session memory

Authentication: required

Availability: Experimental

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/context_engine/memory/_remember`
- `POST` `/s/{space_id}/api/context_engine/memory/_remember`

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Description

Writes one memory to the session memory store. Pass `id` to revise an existing memory. The revision replaces the memory in full.

Returns 202 with the memory id and writes the memory in the background, because semantic indexing runs inside the write. The memory becomes searchable after the background write completes.

Requires the `contextEngine:write` privilege. Without `user_id`, the route writes the memory for the caller's user profile, and a caller without a user profile gets a 403. Naming another user in `user_id` also requires `contextEngine:manage_memory`.

Each AI index in `ai_index_ids` must exist in this space, and the caller requires the Elasticsearch `write` privilege on its backing index. Otherwise, the route rejects the request and writes nothing.

After authorization, validation, and feature-flag checks pass, the route writes one `memory_remember` audit event per request, when the background write finishes or when it rejects the request. The route does not report a failed background write in the response. Instead, it logs the error to the Kibana logs and writes a failure audit event.

Returns a 404 response when Context Engine is turned off in this space (`contextEngine:enabled`), when memory is turned off (`contextEngine:memoryEnabled`), or when an AI index in `ai_index_ids` does not exist.

**For more information, refer to the [Context Engine documentation](https://www.elastic.co/docs/explore-analyze/ai-features/context-engine).**

## Required privileges

- Privileges: `contextEngine:write. Extended privileges (optional, expand functionality when granted): contextEngine:manage_memory`

## Header parameters

- `kbn-xsrf` (string) — required
  A required header to protect against CSRF attacks

## Request body

`application/json`

- `ai_index_ids` (string[] · max items: 100) — optional
  The AI indices that dreaming promotes the memory into. Each must exist in this space, and the caller requires the Elasticsearch `write` privilege on its backing index.
- `attributes` (map string to string) — optional
  String hints about the memory for dreaming. Accepts up to 50 entries, with non-blank keys of 1 to 256 characters.
  Map values (string · max length: 1024)
- `content` (string · min length: 1 · max length: 65536) — required
  The memory text. Elasticsearch indexes this field for semantic search.
- `id` (string · min length: 1 · max length: 256) — optional
  The id of an existing memory to revise. The revision replaces the memory in full, and the route does not check whether the id exists. Omit this field to generate a new id.
- `session_id` (string · min length: 1 · max length: 256) — required
  The session the memory comes from.
- `user_id` (string · min length: 1 · max length: 1024) — optional
  The Kibana user profile UID that the memory belongs to. Omit this field to use the caller's user profile. Naming another user requires `contextEngine:manage_memory`.

## Responses

#### `202`

The route accepted the memory and is writing it in the background. It becomes searchable after the write completes.

`application/json`

- `id` (string)
  The id of the memory. Pass it as `id` to revise the memory.
#### `403`

`user_id` is missing and the caller has no user profile, `user_id` names another user and the caller lacks `contextEngine:manage_memory`, or the caller cannot write to one of the AI indices.

`application/json`

- `error` (string)
  The HTTP status text.
- `message` (string)
  A human-readable error message.
- `statusCode` (number)
  The HTTP status code.
#### `404`

Context Engine or memory is turned off, or an AI index does not exist.

`application/json`

- `error` (string)
  The HTTP status text.
- `message` (string)
  A human-readable error message.
- `statusCode` (number)
  The HTTP status code.
## Code examples

#### Console

```console
POST kbn:/api/context_engine/memory/_remember
{
  "session_id": "8f3c2a1e",
  "ai_index_ids": ["ops-memory"],
  "content": "checkout-service latency alert fired. Root cause is a connection pool limit after the 3.2 deploy.",
  "attributes": { "incident": "INC-4211" }
}
```

#### curl

```curl
curl \
  -X POST "https://${KIBANA_URL}/api/context_engine/memory/_remember" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -H "kbn-xsrf: true" \
  -d '{
    "session_id": "8f3c2a1e",
    "ai_index_ids": ["ops-memory"],
    "content": "checkout-service latency alert fired. Root cause is a connection pool limit after the 3.2 deploy.",
    "attributes": { "incident": "INC-4211" }
  }'
```

## Response examples

#### Memory accepted

`application/json`

The route accepted the memory and is writing it in the background. It becomes searchable after the write completes

```json
{
  "id": "7c1f0b2e-5a43-4b0e-9a57-2f0f6f1d3a10"
}
```

#### AI index not writable

`application/json`

The caller lacks the Elasticsearch `write` privilege on an AI index's backing index

```json
{
  "error": "Forbidden",
  "message": "AI index \u0027ops-memory\u0027 is not writable. Writing to it needs the Elasticsearch \u0027write\u0027 privilege on its backing index.",
  "statusCode": 403
}
```

#### Missing manage memory privilege

`application/json`

`user_id` names another user and the caller lacks `contextEngine:manage_memory`

```json
{
  "error": "Forbidden",
  "message": "Acting on the memory of another user requires the [contextEngine:manage_memory] privilege.",
  "statusCode": 403
}
```

#### No user profile

`application/json`

`user_id` is missing and the caller has no user profile

```json
{
  "error": "Forbidden",
  "message": "The caller has no user profile, so the request cannot be attributed to a user. Log in to Kibana once to create a profile, use an API key whose owner has one, or set \u0060user_id\u0060 if you have the \u0060contextEngine:manage_memory\u0060 privilege.",
  "statusCode": 403
}
```

#### AI index not found

`application/json`

An AI index in `ai_index_ids` does not exist in this space

```json
{
  "error": "Not Found",
  "message": "AI index \u0027ops-memory\u0027 not found",
  "statusCode": 404
}
```

#### Context Engine turned off

`application/json`

Context Engine is turned off in this space

```json
{
  "error": "Not Found",
  "message": "Not Found",
  "statusCode": 404
}
```

#### Memory turned off

`application/json`

Context Engine memory is turned off

```json
{
  "error": "Not Found",
  "message": "Context Engine memory is turned off.",
  "statusCode": 404
}
```

