Recall, traces and profiles
Hybrid search, the token budget, why a candidate was dropped, and prompt-ready profiles.
search() returns three things: memories (facts for the prompt), chunks (source text for grounding) and a trace. Memories are packed first; chunks share what is left of the budget.
const { memories, chunks, trace } = await memnest.search(question, scope, { tokenBudget: 400 }); // memnest.searchMemories(…) skips chunk retrieval entirely.
Options
| Option | Default | What it does |
|---|---|---|
tokenBudget | 2000 | Most tokens to return. trace.budget.used is exactly the included total. |
candidates | 50 | Pool size requested from each retriever. |
rerank | off | An LLM pass over the top 20, dropping scores below 0.2. Costs a model call. |
minVectorScore | 0 | Ignore vector hits at or below this cosine similarity. Vector search always returns something, so this floor matters. |
The trace
Every candidate from either retriever appears once, with where it was found and what happened to it: lexicalRank and lexicalScore, vectorRank and vectorScore, the fused rrfScore, a rerankScore when reranked, its token cost, and either included or a reason:
| Reason | Meaning |
|---|---|
not-latest | A newer version replaced it. This is the one that makes stale answers impossible. |
forgotten | Someone forgot it. |
expired | Its validUntil has passed. |
rerank | The reranker scored it too low. |
budget | It did not fit in the token budget. |
When an answer looks wrong, the trace usually says why in one line: the fact was there but excluded, or never retrieved at all.
Degradation is explicit
When a retriever cannot run, trace.degraded says why instead of quietly returning less:
lexical-only: the store has no vector search (SQLite).lexical-only: no embedding provider configured.lexical-only: container has no embeddings yet— runmemnest backfill.lexical-only: query embedding failed (…).rerank failed (…); fused order kept.
The engine never branches on which store it has, only on what that store reports it can do.
How ranking works
Keyword and vector search run in parallel and are fused with reciprocal rank fusion (k = 60), which needs no score calibration between the two. The fused list is filtered to what is still true, optionally reranked, then packed until the budget is spent. user is treated as a stopword for keyword search, because extraction writes nearly every memory about "the user", and it would otherwise match everything.
Profiles
A profile is the summary you put in a system prompt every turn, instead of searching for basics:
const { text, stable, recent, stale } = await memnest.profile(scopeOf('user:123')); // About the user: // - The user works at Stripe as a product manager. // - The payments service of the user runs on MySQL. // // Recent activity: // - The user has a dentist appointment on 2026-03-11.
- A cached read. Rebuilt after 10 memory changes or once a day, never on every write, and claimed atomically so concurrent writers never both rebuild.
- Safe even when stale. Forgetting or superseding a memory removes every profile line citing it immediately, so a profile can lag but cannot contradict what is stored.
- Guarded. Model-written lines must cite real memories and carry no pronouns or secrets, or a deterministic builder answers instead and the reason is recorded.
- Works with no model at all, built deterministically by ranking memories.