// COMPLETE REFERENCE

Memory OS internals

Chapter 756 5 min read English Stable reference URL

How the durable memory service stores, deduplicates, ranks and serves the rows behind the Memory app. This page is the implementation reference; for what the assistant remembers in a conversation, read the Memory app page instead.

Authority: botserver/crates/botmemory/ (feature memory-os, listed in all-apps), migration 6.5.88-user-memories, and the boot wiring in botserver/src/main_module/routes/feature_merge_office/ai_os.rs and botserver/src/core/bot/memory_hook.rs.

Two stores, one reader

The chat pipeline reads two unrelated tables, and a chapter that treats them as one system is wrong:

Store Table Written by Read by
Memory OS (botmemory) user_memories /api/memory/*, the Memory app recall injection (memory_hook::inject_recall)
Chat memory (botsettings) chat_preferences remember that … turns, Settings › Memory the per-turn memory note (core/user_memory/capture.rs)

botmemory owns user_memories only. The legacy REMEMBER/RECALL keywords are a third mechanism (Redis key/value) and are unchanged.

Row shape

botmemory/src/models.rs:29-44:

Column Notes
owner_user_id the only identity reads and writes filter on
org_id, branch_id copied from the verified token; branch_id also scopes dedupe
scope private or branch (ensure_scope, models.rs:117-123)
kind free-form lowercase label, ≤32 characters, blank becomes fact
content non-empty, ≤4000 characters
confidence REAL 0.0–1.0, default 0.8
pinned ranking input for recall
superseded_by lineage pointer; rows with a value are hidden from reads
embedding_ref column exists but nothing ever writes it — recall is lexical, not vector search
source manual, conversation:<session>, or an import label

Write path and dedupe

store::insert (store.rs:224-257) normalizes content before comparing: ASCII punctuation is dropped, whitespace runs collapse, the result is lowercased (normalize_content, store.rs:67-75), so "Prefers dark mode." and "prefers dark mode" are the same memory.

The decision table (decide_dedupe, store.rs:82-144) is applied against the owner’s live candidates in the same branch:

Situation Outcome
Normalized content equal, wording also equal, incoming confidence higher new row inserted, incumbent gets superseded_by
Normalized content equal, same wording, confidence not higher skipped, incumbent returned
Normalized content equal, different spacing/punctuation skipped
Wording equal (case-insensitive) and confidence ≥ incumbent supersede
Wording equal, confidence lower skipped
No match fresh row

POST /api/memory/items answers {"status": "created" | "superseded" | "skipped_existing", "memory": {…}}, so the client sees which branch ran (api.rs:128-156).

Recall injection

inject_recall (memory_hook.rs:28-61) is called before generation (pipeline/enriched_llm/mod.rs:156) with a fixed 512-token budget and branch_claim = None. Consequences worth knowing:

  • Only rows owned by the caller reach the prompt; scope = 'branch' rows are listed by the API but never injected in chat.
  • The block is appended to the existing system message, or inserted as a new first system message when none exists.

Inside botmemory, recall is a pipeline, not a search engine (recall.rs:12-113):

Step Rule
Candidate fetch newest 12 live rows, pinned first (RECALL_ROW_LIMIT)
Ranking pinned desc, then lexical overlap with the query words (≥2 characters), then updated_at desc
Assembly header Relevant user context: then - [kind] content, each line clipped to 300 characters
Budget max_tokens × 4 characters; a partial line is only appended when more than 16 characters remain
Failure any database or pool error logs and returns an empty block, so chat continues without memory

Extraction hook (wired, inert)

maybe_extract (extract.rs:126-188) is called after a completed turn (pipeline/llm/stream.rs:514). It samples 20% of turns by default (state.rs:12-13) and always runs when the user wrote remember that or lembre que (extract.rs:21,42-45). The model must answer with a strict JSON array of {kind, content, confidence}; parsing accepts fenced JSON, a bare array or {"memories": […]} and keeps at most 8 items, clamping confidence and content (extract.rs:65-122).

The service installed at boot passes an LLM function that always returns Err("LLM not wired for memory extraction") (ai_os.rs:104-116, memory_hook.rs:10-15). Every extraction therefore logs and returns, and no row is written from a conversation today. Recall of rows created through the API or the app still works.

Forget is not this store

Chat requests such as “forget that …” are handled by core/user_memory/forget.rs, which deletes chat_preferences rows, not user_memories. Deleting a row the Memory app shows goes through DELETE /api/memory/items/{id}.

HTTP surface

Mounted with the memory service at ai_os.rs:104-120; identity is a verified HS256 JWT, and a Zitadel subject is mapped to the same UUIDv5 the auth provider uses (api.rs:51-71).

Method Path Behaviour
GET /api/memory/items?kind=&q=&scope=&offset= visible rows, fixed page size 100
POST /api/memory/items create with dedupe; body {kind?, content, scope?, pinned?}
PUT /api/memory/items/{id} partial update of an owned row
DELETE /api/memory/items/{id} permanent delete of an owned row
POST /api/memory/import up to 500 items; dry_run: true projects counts
GET /api/memory/export every live row owned by the caller

q strips % and _ before the ILIKE filter (store.rs:368-375). Import reports created, superseded, skipped and, for a dry run, would_create (models.rs:103-114). The generated reference api-memory lists one row per method and path pair, including combinations the router does not serve.

// SEARCH ESC
Pagefind · 236 pages · 4 books Enter to open ↑ ↓ to move