# Memory

General memory storage, retrieval, linking, and document chunk insertion.

Config only:

- `operation`: `insert`, `ingest`, `get`, `list`, `search`, `update`, `delete`, `add_link`, `remove_link`
- `namespace_id`: ULID of the memory namespace `insert` and `ingest` write into
- `chunk_chars`, `chunk_overlap_chars`, `sentence_aware_chunking`: chunking settings for `ingest`

Runtime payload goes on canonical `input`. There is no config payload fallback.

Memory metadata uses three separate axes: `links` are provenance and relationships, `initial_relevancy` is write-time signal quality/usefulness, and `half_life_seconds` is durability. Relevancy decays over time into `current_relevancy`. Search additionally returns `semantic_score`, the query match score.

`insert`, `ingest`, `search` and an `update` that changes `text` embed with the workspace's embedding model, chosen in the Memory view; search considers only memories embedded with that same model. With none chosen, those operations fail with `No embedding model configured`. A `model` field in an older saved config is ignored, and no payload can choose a provider or model.

## Links

A link records where a memory came from or how it relates to another memory. Every link is `{ "relation", "source" }`.

- `source` — terminal provenance. Accepts every source kind and is never followed.
- `related` — an undirected association between two memories. Requires a `memory` source.
- `supersedes` — directed from the newer memory to the older one it replaces. Requires a `memory` source.

Source kinds are `external_url`, `external_reference`, `canopy_document`, `table_row`, and `memory`.

```json
{ "relation": "source", "source": { "kind": "external_url", "value": "https://example.com/notes/alpha" } }
```

Rules:

- A memory links to any given target at most once, whatever the relation.
- Two memories are connected by at most one link, in one direction.
- At most 32 links are incident to a memory, counting links it owns and links naming it. A mutation can fail because the other memory is full.
- `related` and `supersedes` must stay inside one namespace, and a memory cannot link to itself.
- Supersession is linear and acyclic: a memory supersedes at most one predecessor and is superseded by at most one successor.

Superseding replaces a memory rather than deleting it. The older memory disappears from `search` and from `memory_recall`, so a correction wins instead of competing with the note it corrects. It stays visible to `get`, `list`, and the workspace resource catalog so it can still be managed, and it becomes active again if the `supersedes` link is removed.

Reads keep the memory and its surrounding graph state separate. `get`, `list`, and `search` return the memory under `memory`, with `superseded_by` and `links` beside it. `superseded_by` names the newer memory, or is null when nothing replaces this one.

```json
{
  "memory": { "id": "01J...", "namespace_id": "01J...", "title": "alpha", "text": "alpha" },
  "superseded_by": "01J...",
  "links": []
}
```

## Input Contracts

`insert` accepts a memory insert object or an array of memory insert objects. Each object requires `text`; `title` is optional. The namespace comes from node config; an object carrying `namespace_id` is rejected.

Single insert:

```json
{
  "title": "Alpha notes",
  "text": "alpha",
  "links": [
    { "relation": "source", "source": { "kind": "external_url", "value": "https://example.com/notes/alpha" } }
  ],
  "initial_relevancy": 1,
  "half_life_seconds": 86400,
  "properties": { "kind": "note" }
}
```

Bulk insert:

```json
[
  {
    "text": "alpha",
    "links": [
      { "relation": "source", "source": { "kind": "table_row", "value": { "table_id": "01J00000000000000000000000", "row_id": "row-1" } } }
    ],
    "initial_relevancy": 1,
    "half_life_seconds": 86400,
    "properties": { "kind": "note" }
  },
  {
    "text": "beta",
    "properties": { "kind": "note" }
  }
]
```

`ingest` accepts a text/content object or `{ "documents": [...] }`. The node chunks each item and inserts one memory per chunk. Each chunk's title is derived from its own text. Each chunk inherits the input `links`, `properties`, `initial_relevancy`, and `half_life_seconds`. The namespace comes from node config.

Single document insert:

```json
{
  "text": "Long document text...",
  "links": [
    { "relation": "source", "source": { "kind": "external_url", "value": "https://example.com/doc" } }
  ],
  "initial_relevancy": 0.9,
  "half_life_seconds": 86400,
  "properties": { "kind": "article" }
}
```

Bulk document insert:

```json
{
  "documents": [
    {
      "text": "First document...",
      "properties": { "kind": "note" }
    },
    {
      "text": "Second document...",
      "properties": { "kind": "note" }
    }
  ]
}
```

`get` requires `id`.

```json
{
  "id": "01J00000000000000000000000"
}
```

`list` requires `namespace_id`.

```json
{
  "namespace_id": "01J00000000000000000000001",
  "link": { "relation": "source", "source": { "kind": "canopy_document", "value": "01J00000000000000000000000" } },
  "superseded": false,
  "properties": {
    "mode": "all",
    "all": [{ "op": "eq", "key": "kind", "value": "note" }],
    "any": []
  }
}
```

`search` requires `namespace_id` and `text`.

```json
{
  "namespace_id": "01J00000000000000000000001",
  "text": "alpha",
  "limit": 10,
  "min_semantic_score": 0.3,
  "min_current_relevancy": 0.5,
  "include_superseded": false,
  "properties": {
    "mode": "all",
    "all": [{ "op": "eq", "key": "kind", "value": "note" }],
    "any": []
  }
}
```

`update` requires `id`. `title` replaces the title; changing `text` keeps the existing title. `properties` replaces the full property object. Links are not updated here; use `add_link` and `remove_link`.

```json
{
  "id": "01J00000000000000000000000",
  "title": "Alpha notes v2",
  "text": "alpha v2",
  "initial_relevancy": 0.8,
  "half_life_seconds": null,
  "properties": { "kind": "note", "source_id": "doc-1" }
}
```

`delete` requires `id`.

```json
{
  "id": "01J00000000000000000000000"
}
```

`add_link` and `remove_link` require `id` and `link`. Links are values, so removal takes the whole link rather than an identifier.

```json
{
  "id": "01J00000000000000000000000",
  "link": { "relation": "supersedes", "source": { "kind": "memory", "value": "01J00000000000000000000001" } }
}
```

## Contract

- `namespace_id` is a namespace ULID, never a name: a namespace is renamed freely, so nothing resolves one by name. A namespace that does not exist is rejected rather than created.
- `namespace_id` config is required for `insert` and `ingest`; their input payloads do not carry a namespace. One node writes one corpus.
- `namespace_id` is required in the payload for `list` and `search`. A `search` over a namespace that does not exist returns no hits.
- Bulk `insert` uses an array of insert objects. Wrapper objects such as `{ "texts": [...] }` or `{ "memories": [...] }` are not accepted.
- Bulk `ingest` uses `{ "documents": [...] }`.
- `namespace_id` is payload data for the reads and `update`.
- For `ingest`, chunking settings are static config.
- `insert` and `ingest` accept `source` links only. `related` and `supersedes` name a memory id that does not exist yet at insert time, so add them afterwards with `add_link`.
- Every memory has a `title`: trimmed, non-blank, at most 255 characters. An `insert` object without `title` gets one derived from `text`: whitespace runs collapsed to one space, then the first 120 characters, trimmed. `ingest` always derives each chunk's title from that chunk.
- A `title` key inside `properties` is ordinary property data, not the memory's title.
- `properties` is memory metadata on insert and update.
- `properties` is a filter on list and search.
- `list` returns active and superseded memories unless `superseded` is set, and names each replacement in `superseded_by`.
- `search` hides superseded memories unless `include_superseded` is set.
- Read outputs nest the memory under `memory`, with `superseded_by` and `links` as sibling fields rather than memory fields.
- `initial_relevancy` is not search confidence. Use high values for direct/authoritative signal and lower values for noisy or weak sources.
- `half_life_seconds` controls durability: shorter for volatile knowledge, longer or omitted for stable knowledge.
- `min_semantic_score` gates query match; `min_current_relevancy` gates current signal quality after decay.
- `update.properties` replaces the full property object. It does not merge.
- Adding or removing a link does not change a memory's `updated_at`.
- A namespace change is rejected while the memory has an incident `related` or `supersedes` link.
- Deleting a memory removes links it owns and links naming it.
- Outputs return raw memory JSON with `properties`.
- Prefer this node for memory CRUD and content ingestion. `embed_document` remains available for older workflows, but `memory.ingest` is the more general surface. Use `memory_recall` for bounded AI context.
