Recall pipeline
A recall first tries two cheaper tiers: the Redis hot tier and the pointer
tier (see three-tier retrieval). When neither
answers, the query reaches the cold tier, recallCold, which runs the seven
stages on this page. A request that sets minSimilarity skips the first two
tiers and always runs cold, and so does a request that sets asOf (it skips
the query cache too, because only the cold tier can read a past instant).
Source
Everything here is in
packages/core/src/cognitive/recall-cold.ts.
The files next to it hold the pieces it calls:
| File | What it holds |
|---|---|
index.ts | recall(): the token budget gate, the query cache and the hot, pointer, cold cascade |
recall-hot.ts | Hot tier: a Redis sorted set of recently active facts |
recall-pointer.ts | Pointer tier: full-text and LSH narrowing, then exact cosine |
recall-relevance.ts | The activation and worth factors, and the “nothing relevant” floor |
worth.ts | The worth serving gate |
recmem.ts | The recurrence gate in front of the optional rerank |
hyde.ts | The optional HyDE step |
The stage numbers below follow the header comment of recall-cold.ts. The
code runs them in a slightly different order: the hints of stage 3 are loaded
last, for the served page only, because they do not change the score.
Search modes
POST /recall takes an optional mode:
mode | What runs |
|---|---|
auto (default) | Vector candidates. Falls back to full-text when no embedder is configured or the provider does not answer. |
semantic | Vector candidates only. Answers 503 semantic_search_unavailable when the query cannot be embedded. |
hybrid | Vector candidates plus the full-text arms, fused by rank. |
lexical | Full-text only. The stages below do not run. |
The seven stages
1. Parse
The query text is embedded with the configured embedding provider, unless the
request already carries a vector. Filters (kinds, scope, scopeRef,
actorId) are read from the request.
2. Candidates
Three searches collect candidates, and the raw cosine of each one is kept apart from its full-text rank:
- Facts: HNSW cosine search over
halfvecembeddings. There is one index per embedding dimension. - Entities: cosine search over entity embeddings, weighted ×0.85, because an entity is context and not an answer.
- Other kinds: cosine over decisions, strategies, workflows, skills and
episodes.
task,eventandreasoningare searched only when the request lists them inkinds.
In hybrid mode two full-text arms are added: one over facts and one over
the other kinds. A candidate that both arms found keeps both pieces of
evidence. minSimilarity drops any candidate whose measured cosine is below
it, even if full-text also matched it.
With asOf, each arm keeps only the rows whose validity interval contains
that instant (validFrom <= asOf < validTo). The filter runs in SQL before
the arm’s limit and again when the hits are loaded.
3. Relation and hyperedge hints
For the hits on the served page, the engine loads their open relations and
the hyperedges they belong to, and attaches them to the hit as relations and
hyperedges. The other members of a hyperedge are named on the hit; they are
never added to the results as hits of their own. POST /recall and
memory_recall return both fields when the request sets includeGraph: true;
by default they are left out to keep the response small. With asOf, the
relations are the ones valid at that instant.
4. ACT-R activation
Activation is ln(∑ t_j^-0.5) over the recall log (mnemo_recall_log),
using the last 20 recalls of each candidate. It is a tie-break only: it
multiplies the score by 1 + 0.02 × tanh(A), so at most ×1.02. With an empty
recall log it adds nothing.
5. Score
score = relevance × kind weight × worth prior × activation tie-break- Relevance is the cosine. In
hybridmode with full-text evidence it is a reciprocal rank fusion (k = 60) of the semantic rank and the full-text rank, normalised so that rank 1 in both scores 1. While an embedding migration is running, the full-text rank weighs more. - Kind weight is 1, except 0.85 for entities.
- Worth prior is
1 + 0.1 × (worth − 0.5), between 0.95 and 1.05.
Before scoring, a fact with accumulated negative evidence is dropped by the
worth gate (it must have worth > 0.5 and a Wilson lower bound of at least
0.3). Facts that were never recalled are exempt. includeLowWorth: true
turns the gate off. Hits with identical content are then deduplicated.
A hit whose content looks like a prompt injection is demoted and carries its
injectionScore.
6. Sensitivity ceiling
A candidate above the caller’s sensitivity ceiling is dropped as if it did
not exist. Recall does not report that something was hidden, and a direct
read of the same record answers 404, not 403, so a caller cannot probe for
what exists. Contested facts are not hidden: they are returned with
status: "contested".
7. Assemble
Each hit carries its security labels as structured fields, never as text
spliced into the content. Over HTTP a hit has id, kind, content,
score, similarity (the raw cosine, when one was measured), validFrom,
validTo, tags, sensitivity, status, injectionScore and
trust: "untrusted", which is set on every hit because retrieved content is
data, whatever it says.
The response also carries nothingRelevant, which is true when no eligible
candidate reaches the relevance floor. The floor is
MNEMO_RECALL_RELEVANCE_FLOOR when set, otherwise the default of the
embedding model. Only bge-m3 has a default (0.50); with no floor, only an
empty result counts as nothing relevant.
Opt-in steps
- LLM rerank.
rerank: trueonPOST /recallasks the configured LLM to reorder the served page. A recurrence gate runs first and skips the call when the hits are thematically scattered (recurrenceThreshold, default 0.6). A rerank changes the order, notscoreorsimilarity. If the LLM fails or times out, the original order is returned and the response saysdebug.rerankDegraded: true. - HyDE. The core query type has a
hydeflag: the LLM writes a hypothetical answer, and its embedding is averaged with the query embedding before stage 2.POST /recalltakes it ashyde: true; the MCP tools do not expose it.
After the stages
- Each returned fact is written to
mnemo_recall_log, which is what stage 4 reads on the next recall. - Up to three of the returned facts are promoted to the hot tier.
- The composition engine runs over the served hits.
A recall with asOf does none of this: reading the past is not use, so it
writes no recall log, promotes nothing, and changes no worth, activation or
co-activation.
Tracing a recall
Send debug: true and the response lists the stages that ran in
debug.trace, with candidate counts and timings:
curl -X POST http://localhost:3939/recall \
-H "Authorization: Bearer mns_live_..." \
-H "Content-Type: application/json" \
-d '{"query": "what language should we use with Acme?", "mode": "hybrid", "debug": true}'The stage names in the trace are embed, hot_tier, pointer_tier, cache,
vector, lexical, nonfact_candidates, fusion, eligibility, dedup,
activation, graph, rerank and response.