Architecture

How recall works

The pipeline behind a search: candidate selection, hybrid scoring, reranking, and the resolver that keeps memory consistent.

Architecture3 pages

Recall is the part users feel. A question is typed in chat or by an agent, and the answer depends on whether the right five memories came back out of thousands. Memo does it in four stages, all server-side.

1. Normalise the query

Text is lower-cased and tokenised. Words are stemmed, stop words are dropped, and CJK runs are split into characters and bigrams because there are no spaces to split on. Hyphenated and signed tokens such as utc+8 also produce their parts, so a search for utc still matches.

2. Select candidates

  • Personal memory is filtered to the account and, for agent calls, the requested kind.
  • Code memory is filtered to the repository plus anything shared with the account, and optionally by type and path.
  • Pending captures and superseded rows are excluded before scoring, not after.

3. Score and rerank

Vector similarity
What it captures
Meaning-level closeness between query and memory, computed with a local embedding model.
Lexical overlap
What it captures
Exact words and rare terms, weighted by inverse document frequency.
Importance
What it captures
How much the memory should matter by default.
Recency
What it captures
Older memories decay smoothly; a fresh correction beats a stale fact.
Path and scope
What it captures
For code: whether the memory names the file or directory being edited, and how narrow its scope is.
Confidence and usage
What it captures
How often a code rule has been relied on, and how confident the writer was.
Feedback
What it captures
memory_feedback nudges memories that were marked helpful or not.

Scores are combined, normalised to the best hit and cut relative to it. A query with no real match returns an empty or very short list rather than a page of weak guesses — which matters when an agent decides whether to trust the result.

4. Resolve writes

The same pipeline runs in reverse when memory is written. Before storing an unkeyed write, the resolver looks for the closest existing memories in the same category:

  • Near-duplicate. Same category, high similarity and no changed slot: the existing row takes the fuller text and the higher importance, and the response says merged.
  • Changed value. The statement matches except for one slot — a day, a package manager, a city: the old row is marked superseded and a new row carries the current value.
  • Negation or change language. Words such as never, no longer, instead, 改为, 不再 flip the meaning, so the new memory supersedes the old one.

Keyed code writes skip the similarity search: the key is the identity, so the row is updated in place.

Why superseded rows remain

Superseded memory is kept for history but excluded from every read path. If you need a clean store, delete the memory or export and re-import.

Why no vector index

At this scale — thousands of memories per account — ranking in the application is faster than maintaining an approximate index, and it keeps the path, confidence and usage signals on equal footing with the vector score. The vector column is still stored in pgvector, so an index can be added later without changing the schema.