Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Memory API

Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.

Memory and embedding endpoints for persistent vector storage. The backend uses PostgreSQL with pgvector for similarity search and ETS for fast key-value access.

Overview

The memory system provides two storage modes:

ModeBackendUse Case
Key-valueETS + WALFast TTL-based caching, reflections
Vector searchPostgreSQL + pgvectorSemantic similarity search

Memory entries are scoped to agent_id and user_uuid. Users can only access their own entries unless they are admin.

Store a Memory Entry

POST /api/v1/memory/store

Store a key-value pair with optional embedding and TTL. The agent_id is supplied in the request body (not as a path parameter); it defaults to "default" when absent.

Request

{
  "agent_id": "research-bot",
  "key": "lesson_learned_42",
  "value": "Always validate input before processing in Erlang",
  "ttl": 86400,
  "embedding": [0.1, 0.2, 0.3, 0.4]
}
FieldRequiredDescription
keyYesUnique key within the agent’s namespace
valueYesString value to store
agent_idNoAgent namespace (default "default", max 128 chars)
ttlNoTime-to-live in seconds (0 = no expiry, negative rejected). Values above one year are clamped to 365 days
embeddingNoPre-computed embedding vector. Auto-generated if omitted

Response

{
  "status": "ok"
}

If no embedding is provided, the system auto-generates one from the value using the configured embedding model. Embedding generation is best-effort and does not fail the store operation.

Retrieve a Memory Entry

GET /api/v1/memory/:agent_id/:key

Retrieve a stored memory entry by key.

Response

{
  "key": "lesson_learned_42",
  "value": "Always validate input before processing in Erlang",
  "created_at": 1716192000000
}

Error Responses

CodeDescription
404Key not found
410Entry has expired
503Memory service disabled

Delete a Memory Entry

DELETE /api/v1/memory/:agent_id/:key

Delete a specific memory entry. Only the owner can delete entries.

Response

{
  "status": "ok"
}

Search Memory

GET /api/v1/memory/:agent_id/search?q=<query>&limit=20

Full-text search across memory entries for an agent. Answers the standard Paginated envelope (not a bare results list).

Parameters

ParameterDefaultDescription
q(required)Search query string
limit20Maximum results (clamped 0..200)
offset0Pagination offset

Response

{
  "items": [
    {
      "key": "lesson_learned_42",
      "value": "Always validate input before processing in Erlang",
      "created_at": 1716192000000
    }
  ],
  "total": 1,
  "limit": 20,
  "offset": 0,
  "page": 1,
  "total_pages": 1,
  "has_more": false
}
POST /api/v1/memory/:agent_id/vector-search

Semantic similarity search using pgvector. Requires pgvector to be enabled.

Request (by text)

{
  "text": "input validation best practices",
  "limit": 10,
  "threshold": 0.75
}

Request (by embedding)

{
  "embedding": [0.1, 0.2, 0.3, 0.4],
  "limit": 10,
  "threshold": 0.75
}
FieldRequiredDescription
textOne of text/embeddingQuery text (auto-embedded)
embeddingOne of text/embeddingPre-computed embedding vector (all elements must be numbers — 400 otherwise)
limitNoMaximum results (default: 20; must be an integer in 1..200 — 400 otherwise)
thresholdNoMinimum similarity score 0.0–1.0 (default: 0.75 — out-of-range answers 400)

Response

{
  "results": [
    {
      "key": "lesson_learned_42",
      "value": "Always validate input before processing in Erlang",
      "similarity": 0.92
    }
  ]
}

List Memory Entries

GET /api/v1/memory/:agent_id

Paginated list of all memory entries for an agent (no /list suffix).

Parameters

ParameterDefaultDescription
limit50Maximum entries per page (clamped 0..200)
offset0Pagination offset

Only limit/offset are read on this route — page/per_page are NOT supported here (the handler parses the query itself rather than using the shared parser).

Response

{
  "items": [
    {
      "key": "lesson_learned_42",
      "value": "Always validate input before processing in Erlang",
      "created_at": 1716192000000
    }
  ],
  "total": 1,
  "limit": 50,
  "offset": 0,
  "page": 1,
  "total_pages": 1,
  "has_more": false
}

Clear Memory

POST /api/v1/memory/:agent_id/clear

Delete memory entries for an agent. A non-admin caller wipes only their OWN rows inside the agent namespace; an admin wipes the whole namespace. (A request with neither identity scope signal answers 404 — deliberately indistinguishable from an absent agent.) The legacy DELETE verb is not accepted on this route — it is POST-enforced.

Response

{
  "status": "ok"
}

Pin a Memory Entry

POST /api/v1/memory/:agent_id/:key/pin

Pin or unpin a memory entry. Pinned entries are exempt from importance decay.

Request

{
  "pinned": true
}

Response

{
  "status": "ok",
  "pinned": true
}

Get Reflections

GET /api/v1/memory/:agent_id/reflections

Retrieve memory entries with keys matching reflection:*. Filtered by user ownership. Answers the standard paginated envelope (limit default 50, clamped 0..200, offset supported):

{
  "items": [
    {
      "key": "reflection:session_42",
      "value": "The user prefers concise explanations"
    }
  ],
  "total": 1,
  "limit": 50,
  "offset": 0,
  "page": 1,
  "total_pages": 1,
  "has_more": false
}

Memory Statistics

GET /api/v1/memory/stats

Admin-only (403 otherwise). Returns global memory usage statistics:

{
  "enabled": true,
  "total_entries": 1500
}

A per-agent variant also exists — GET /api/v1/memory/:agent_id/stats (ownership-filtered) answers {"agent_id": "...", "key_count": N, "total_size": bytes}.

Trigger Importance Decay

POST /api/v1/memory/:agent_id/decay

Admin only. Manually trigger the importance decay process for a specific agent’s memory namespace, reducing the relevance of old, unpinned entries.

Response

{
  "status": "ok",
  "forgotten": 23
}

Agent ID

The agent_id path parameter identifies the memory namespace. Default is "default". Maximum length is 128 characters.

User Scoping

Memory entries are tagged with user_uuid at store time. The following rules apply:

Non-admin users see only their own entries Admin users see all entries System entries (no user_uuid, the "system" placeholder) are visible only to the system caller — a regular user does NOT see them Ownership is checked on retrieve, delete, pin, and clear operations; a foreign overwrite or delete answers 404 (never 403 — no existence oracle for foreign keys)

When the memory subsystem is disabled the handlers answer 503 with {"error": "memory_subsystem_disabled", "enabled": false} (a documented flat shape, not the standard envelope).