# Memory

> What the agent remembers, what each turn carries, how it finds the rest, and how a finished conversation becomes an episode.

Source: https://nestorhome.dev/docs/agent/memory/

Nestor keeps **memories**, lasting facts ("Léa is vegetarian"), and **episodes**, what each past
conversation was about, both rebuilt from the journal.

*Memories, by person and for the whole household*

## What a turn carries

Memories are dated: of two that disagree, the model keeps the later. Episodes are seen only by
their participants. Tools reach the rest:

| Tool                | Does                                                                   |
| ------------------- | ---------------------------------------------------------------------- |
| `recall`            | searches memories and past conversations, between two dates if asked   |
| `read_conversation` | rereads one conversation word for word                                 |
| `remember`          | keeps a memory                                                         |
| `correct_memory`    | fixes one                                                              |
| `forget`            | drops one                                                              |

## Finding by words and by meaning

Words go through SQLite's full-text index (accents ignored), meaning through an embedding model and
[sqlite-vec](https://github.com/asg017/sqlite-vec). Search by meaning is optional: point
`memory.embedder` at an embedding model.

```yaml
models:
  embed:
    type: embedding
    provider: openai-compatible
    base_url: https://openrouter.ai/api/v1
    api_key: ${MODEL_API_KEY}
    model: openai/text-embedding-3-small
memory:
  embedder: embed
```

Any OpenAI-compatible embeddings server works, such as `llama-server --embeddings`. Vectors are
recomputed in the background after a model change.

## When a conversation is over

When a conversation ends, the consolidation model writes its episode and keeps the lasting facts
the agent missed. After a stop, Nestor catches up at the next start.

## Settings

| Setting                  | Default         | What it does                                                    |
| ------------------------ | --------------- | --------------------------------------------------------------- |
| `memory.strategy`        | `both`          | `recent`: the latest only; `search`: only what the words find   |
| `memory.recent`          | 150             | memories in the household layer                                 |
| `memory.found`           | 12              | memories the words may add beyond them                          |
| `memory.recent_episodes` | 3               | latest conversations of whoever speaks                          |
| `memory.found_episodes`  | 4               | older conversations their words may add                         |
| `memory.embedder`        | none            | the embedding model, for search by meaning                      |
| `memory.query_timeout_s` | 1               | seconds to embed a question before searching by words only      |
| `memory.consolidation`   | `agent.written` | the model that writes episodes                                  |
