ConceptsThree-tier retrieval

Three-tier retrieval

POST /recall does not always run the full search. It tries cheaper tiers first and stops at the first one that answers well enough.

POST /recall
  │  tokenBudget decides which tiers may run
  ▼
Embed the query        skipped when the request carries `vector`
  ▼
Result cache           a near-identical query (cosine ≥ 0.95) from the last 5 minutes
  ▼ miss
Tier 1  Hot            Redis sorted set of recently recalled facts
  ▼ fewer than 3 hits with activation above 0.7
Tier 2  Pointer        full-text terms ∪ LSH bands, then exact cosine
  ▼ fewer than 3 hits with score above 0.7
Tier 3  Cold           seven stages over Postgres and pgvector

The orchestration is recallWithCaches in packages/core/src/cognitive/index.ts. A request with minSimilarity skips the hot and pointer tiers and goes to the cold tier. A request with asOf skips the cache as well: those tiers know only the present (see Bitemporal model).

Tier 1: hot

Source: packages/core/src/cognitive/recall-hot.ts.

The hot tier is one Redis sorted set per workspace (mnemo:{workspaceId}:hot:facts). It holds facts only. Each time a fact is served, its score in the set goes up by one.

On a query, the tier takes the highest-scored facts, keeps the ones that share terms with the query, and scores each with its ACT-R activation, computed from the recall log and squashed to 0 to 1. A fact recalled in the last five minutes gets +0.3. The tier answers only when at least three candidates have an activation above 0.7. Otherwise the query falls through.

The tier is skipped when Redis is not configured, when the query asks only for kinds other than facts, and when the query has fewer than two content terms. A Redis error counts as a miss, not as a failed recall.

Tier 2: pointer

Source: packages/core/src/cognitive/recall-pointer.ts.

Also facts only. It gathers a small candidate set without touching the vector index: facts that match the query terms in full-text, united with facts that share an LSH band with the query embedding (SimHash over the first 64 dimensions, 6 bands of 8 planes). It then computes the exact cosine for each candidate and scores it as cosine × worth. The tier answers only when at least three hits score above 0.7, and the hits it serves are promoted to the hot tier.

Tier 3: cold

Source: packages/core/src/cognitive/recall-cold.ts. Seven stages, in order:

  1. Parse. The query becomes an embedding plus filters.
  2. Candidates. HNSW over facts, cosine over the other kinds and over entities, plus full-text arms in hybrid mode. The raw cosine and the lexical rank of each candidate are kept apart.
  3. Relation and hyperedge hints. The relations and hyperedges of the served page are attached as context. They are never injected as hits. includeGraph: true returns them on each hit as relations and hyperedges.
  4. ACT-R activation. A(t) = ln(Σ t_j^-0.5) over the memory’s recall log. It is a bounded tie-break: it multiplies the score by 1 to 1.02.
  5. Score. relevance × kind weight × worth prior × activation tie-break. Relevance is the cosine, or the fused rank in hybrid mode. The kind weight is 1 for every kind except entities (0.85). The worth prior moves the score by 0.95 to 1.05.
  6. Sensitivity ceiling. A memory above the credential’s ceiling is left out. Reading one directly answers 404, not 403, so its existence cannot be probed. Contested facts are returned and flagged.
  7. Assemble. Hits carry structured labels (kind, status, similarity, injectionScore, validity). Labels are never interpolated into the content.

Two filters run inside the cascade. The worth gate drops a fact that has evidence against it: it is served only when its worth is above 0.5 and its Wilson lower bound is at least 0.3. A fact that has never been rated is exempt, and includeLowWorth: true turns the gate off. Deduplication removes hits with identical content.

Ranking is relevance first. Pinning a fact does not raise it in recall: a pin only protects the fact from consolidation merges.

Opt-in steps

  • LLM rerank. Send rerank: true. The model reorders the served page without changing score or similarity. It is skipped when the candidates are thematically scattered (recurrenceThreshold, default 0.6), and debug.rerankDegraded reports a failed or timed-out rerank.
  • HyDE. hyde: true on POST /recall adds a hypothetical-document step: the LLM writes a short answer and its embedding is averaged with the query’s. No MCP argument sets it.

Token budget

A request can say how much context the caller has left. tokenBudget prunes the cascade (applyTokenBudget in recall-pointer.ts):

tokenBudgetTiers that runHits
Below 500None; recall is empty0
Below 2,000HotUp to 3
Below 8,000Hot and pointerUp to 5
8,000 or moreAll threetopK
OmittedAll threetopK

MNEMO_RECALL_DEFAULT_TOKEN_BUDGET sets a server default for requests that omit it.

When a component is down

SituationResult
Redis unavailable or not configuredThe hot tier is a miss. The pointer and cold tiers still run.
Embedding provider missing or not answeringmode: "auto" falls back to full-text. mode: "semantic" fails with semantic_search_unavailable.

Inspecting a recall

  • debug: true on POST /recall returns debug.trace: the stages that ran, with candidate counts and timings.
  • POST /recall/explain runs a recall and returns the per-hit signals the plain response hides: worth, Wilson lower bound, injection score, relations and the tier that served the hit.
  • POST /recall/hot queries the hot tier alone and returns an empty list on a miss.

In docs/STATUS.md the hot tier is stable and the pointer and cold tiers are beta. Stage 4 reads mnemo_recall_log and adds nothing while that log is empty. Mnemosyne is alpha, on the 3.6.x line, and the API can still change within 3.x.