[Bug] Memory plugin recalls nothing with a logit-scale reranker: configured threshold is clamped to [0,1] and scores are clamped before comparison
Issue Origin
Claude Code memory plugin — examples/claude-code-memory-plugin (also affects the Cursor / Codex / Trae / zcode copies, see Affected code paths).
Bug Description
When OpenViking is configured with a local reranker that emits raw logits — e.g. bge-reranker-v2-m3 served by llama.cpp through the OpenAI-compatible /v1/rerank endpoint — auto-recall injects zero memories for nearly every prompt, even though the server returns well-ranked, clearly relevant hits for the exact same query.
The plugin still assumes cosine-style scores in [0, 1], but bge-family rerankers return log-odds in roughly [-11, +6], where relevant hits are normally negative. The server passes reranker scores through unchanged (openviking/.../openai_rerank.py), and its own rerank.threshold is expected to be negative for these models (we run -8.0, which cleanly separates relevant from irrelevant in our corpus).
Three independent client-side filters then each destroy the whole result set:
scripts/config.mjs:245clamps the configured threshold into[0, 1], so a negative threshold cannot be expressed at all — settingscoreThreshold: -8silently becomes0.scripts/auto-recall.mjs:184hardcodesscore_threshold: 0on thefindfallback request, so the server drops every negative-scored hit before the client ever sees it.scripts/auto-recall.mjs:424andscripts/shared/recall-core.mjs:602compareclampScore(it.score) >= threshold, flattening every negative score to0before the comparison. The sameclampScore()is applied inrankItem()(auto-recall.mjs,recall-core.mjs:213), so ranking loses all resolution across the negative range too.
Because the failure is a silent empty result rather than an error, it presents as "the memory plugin recalls nothing", and the natural (wrong) conclusion is that the reranker model is bad.
Steps to Reproduce
- Serve a bge-family reranker locally, e.g. llama.cpp with
bge-reranker-v2-m3(--embedding --pooling rank), and point OpenViking's rerank provider at it. - Set the server-side rerank threshold to a value appropriate for logits, e.g.
"threshold": -8.0— this is required for this model family, since relevant hits score negative. - Install the Claude Code memory plugin and let the
UserPromptSubmitauto-recall hook run against a corpus that does contain relevant memories. - Inspect
~/.openviking/state/last-recall.json.
Expected Behavior
The plugin treats the reranker score as an opaque, monotonically increasing relevance value and applies the operator-configured threshold as-is, so recall returns the same hits the server considers relevant.
Actual Behavior
count: 0, reason: "no_results" on essentially every prompt. In our deployment 78 of 88 recall queries came back empty (~89%), while the server returned good hits for the same queries. Latency also compounds: the hook burns all three paths (context face → endpoint recall → find fallback) before giving up, taking 52–65 s per prompt.
Minimal Reproducible Example
Same query, same corpus, only min_score varied on POST /api/v1/search/recall:
min_score sent to server |
hits returned |
|---|---|
0.35 (plugin default scoreThreshold) |
0 |
0.0 (hardcoded on the find fallback) |
0 |
-8.0 (the server's own rerank threshold) |
8 |
Score distribution in that run: relevant hits landed at -4.00 … -7.48; the best irrelevant hit scored -11.0. The model separates the classes cleanly — the client-side [0, 1] assumption is the only thing destroying the result set.
After patching the six sites below locally (no model change, same reranker, same corpus):
| before | after | |
|---|---|---|
| recalled entries | 0 (no_results) |
7 |
| path taken | 3 failed stages in sequence | context face succeeds on the first request |
| latency | 52–65 s | 15.9 s |
Proposed Fix
Treat scores as opaque; keep clampScore() only where a [0, 1] value is genuinely required for display.
--- a/examples/claude-code-memory-plugin/scripts/config.mjs
+++ b/examples/claude-code-memory-plugin/scripts/config.mjs
@@ -243,9 +243,9 @@
- scoreThreshold: Math.min(1, Math.max(0, num(
+ scoreThreshold: num(
process.env.OPENVIKING_SCORE_THRESHOLD,
num(cc.scoreThreshold, 0.35),
- ))),
+ ),
--- a/examples/claude-code-memory-plugin/scripts/auto-recall.mjs
+++ b/examples/claude-code-memory-plugin/scripts/auto-recall.mjs
@@ -184 +184 @@
- const body = { query, target_uri: resolvedUri, limit, score_threshold: 0 };
+ const body = { query, target_uri: resolvedUri, limit, score_threshold: Number(cfg.scoreThreshold) };
@@ -83 +83 @@ (rankItem)
- const base = clampScore(item.score);
+ const base = (typeof item.score === "number" && Number.isFinite(item.score)) ? item.score : 0;
@@ -424 +424 @@
- const filtered = raw.filter(it => clampScore(it.score) >= cfg.scoreThreshold);
+ const filtered = raw.filter(it => (typeof it.score === "number" && Number.isFinite(it.score)) ? it.score >= cfg.scoreThreshold : false);
--- a/examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs
@@ -213 +213 @@
- const base = clampScore(item.score);
+ const base = (typeof item.score === "number" && Number.isFinite(item.score)) ? item.score : 0;
@@ -602 +602 @@
- const filtered = raw.filter((it) => clampScore(it.score) >= scoreThreshold);
+ const filtered = raw.filter((it) => (typeof it.score === "number" && Number.isFinite(it.score)) ? it.score >= scoreThreshold : false);
Notes on the shape of the fix:
- The default of
0.35is fine to keep for cosine-scored deployments; the problem is only that a negative value cannot be configured. - An alternative (or complement) would be for the server to advertise the score scale in the search response so clients can adapt automatically, since the plugin cannot know which reranker family is behind the endpoint. Whatever direction you prefer, sites 1–3 above look wrong under any scale convention: clamping a configured threshold and hardcoding
score_threshold: 0both silently override the operator. recall-core.mjs:609also reportsscore: clampScore(it.score)in the state file; leaving it clamped makes every logged hit read0, which makes this class of problem hard to diagnose. Reporting the raw score there helped a lot.
We're happy to send a PR if this direction looks right.
Affected code paths
The same clampScore + threshold logic is duplicated across other integrations, so the same deployment would break there too. Code search for clampScore in this repo returns 17 files; the ones carrying the ranking/filter pair are:
examples/memory-plugin-shared/lib/recall-core.mjsexamples/claude-code-memory-plugin/scripts/shared/recall-core.mjsexamples/codex-memory-plugin/scripts/shared/recall-core.mjs(+ itsscripts/auto-recall.mjs)examples/zcode-memory-plugin/scripts/shared/recall-core.mjsexamples/dsh-memory-plugin/shared/recall-core.mjsexamples/opencode-plugin/lib/shared/recall-core.mjsexamples/pi-coding-agent-extension/shared/recall-core.mjsexamples/openclaw-plugin/memory-ranking.ts(TypeScript port of the same ranking)
examples/claude-code-memory-plugin/scripts/debug-recall.mjs and skill-experience.mjs clamp as well, so the debug tooling reports 0 for every negative-scored hit — which is what made this hard to diagnose from the logs.
Since examples/memory-plugin-shared/lib/recall-core.mjs already exists as a shared copy, fixing it there plus the per-integration copies would cover all of them consistently.
OpenViking Version
Server 0.4.16.dev0; plugin openviking-memory 0.4.4 (current main of the marketplace subdir).
OS
Windows 11 (server and reranker both local; reranker served by llama.cpp on GPU).
Two follow-ups from continuing to run this setup. The first shows the scale assumption is not only in the plugin — it is in the server config contract too. The second is a separate, smaller mismatch found in the same area.
1. The [0, 1] assumption also lives in the server's rerank config contract
guides/01-configuration.md documents the rerank threshold as:
|
threshold| float | Score threshold between0.0and1.0; results below this are filtered out. Default:0.1|
…while the same section invites operators to plug in any OpenAI-compatible rerank endpoint:
|
provider| str |"vikingdb","cohere", or"openai"… | |api_base| str | Endpoint URL (foropenaiprovider) | |timeout| float | … Increase for slow or cold-starting local rerank servers. |
Those two are in tension. The documented example uses qwen3-rerank, which is squashed into [0, 1], but the most common open reranker family — bge-reranker-* — returns raw logits (roughly -11 … +6 in our corpus, with relevant hits normally negative). With provider: openai + a local llama.cpp /v1/rerank endpoint, a documented-range threshold of 0.1 discards every result.
Our working config is therefore outside the documented range:
"rerank": {
"provider": "openai",
"api_base": "http://<host>/v1/rerank",
"model": "bge-reranker-v2-m3",
"threshold": -8
}
This works, but only because the server passes reranker scores through unchanged (openai_rerank.py) and does not actually clamp to the documented range. So the value that makes the system work is one the documentation says is invalid.
Why this matters for the original report: the plugin bug and this are the same root cause — "reranker scores are cosine-like values in [0, 1]" — expressed in two places. Fixing only the plugin leaves an operator reading guides/01-configuration.md with no way to know a negative threshold is both necessary and allowed.
Suggested direction: either (a) document that the valid range depends on the reranker's scoring convention and that logit-scale models need a negative threshold, or (b) normalize scores at the provider boundary so [0, 1] becomes true for every backend. (a) is cheap and unblocks operators today; (b) would let the plugin's original assumption stand.
There is one more consequence worth flagging, because it is not obvious from the docs: with rerank enabled, this threshold also gates recursive expansion, not just final filtering —
# retrieve/hierarchical_retriever.py (recursive search)
if self._rerank_client and mode == RetrieverMode.THINKING:
query_scores = await self._rerank_scores(query, documents, query_scores)
for r, score in zip(results, query_scores, strict=True):
final_score = alpha * score + (1 - alpha) * current_score if current_score else score
if not self._passes_threshold(final_score, effective_threshold, score_gte):
continue
concepts/07-retrieval.md presents this loop in terms of embedding_score, so the rerank substitution isn't visible from the docs. The practical effect for logit-scale rerankers: a threshold low enough to retain relevant hits (-8) is also low enough that almost no directory is pruned, so the recursive search keeps expanding. We measured ~61 vector-search calls on an unscoped query, and raising the threshold trades recall for latency rather than being a free win (-8: 16.8 s / 6 entries → -6: 13.5 s / 6 → -4: 13.1 s / 3).
2. recallContextTimeoutMs is unreachable in exactly the configuration the docs recommend
agent-integrations/01-overview.md § Low-latency recall recommends turning both optional model calls off:
export OPENVIKING_RECALL_QUERY_EXPANSION=off
export OPENVIKING_RECALL_COMPRESS=off
and the same section says the deadline can be pinned:
Set
OPENVIKING_RECALL_CONTEXT_TIMEOUT_MS(orplugin.recallContextTimeoutMs) to pin it — keep it above the fuses the request will spend and below the Agent's own hook timeout.
But in examples/claude-code-memory-plugin/scripts/shared/recall-core.mjs:
export function contextRequestTimeoutMs(cfg = {}, body = {}) {
const wantsRewrite = body.rewrite !== undefined;
const wantsExpansion = Boolean(body.session_id) && body.query_expansion !== "off";
if (!wantsRewrite && !wantsExpansion) return undefined; // ← returns here
const configured = Number(cfg.recallContextTimeoutMs); // ← never reached
if (Number.isFinite(configured) && configured > 0) return Math.max(1000, Math.floor(configured));
...
}
With expansion off and no rewrite — the exact combination the low-latency section recommends — the function returns before reading the configured value, and the request falls back to the plugin's ordinary timeoutMs.
That fallback is defensible as a design (no fuses spent ⇒ no extended deadline), so this may be a docs bug rather than a code bug. But the two cannot both be right, and it bites the low-latency configuration specifically: in our case the server needed ~14 s while the ordinary timeout was 15 s, so the first path failed on a margin, and setting recallContextTimeoutMs: 25000 had no effect. We only got a stable single-request path after raising timeoutMs itself to 30 s.
Suggested direction: either let an explicit recallContextTimeoutMs win regardless of which fuses the request spends (it is an explicit operator override), or amend the docs to say it only applies to requests that spend the expansion or rewrite fuse.
Environment for both: server 0.4.16.dev0, plugin 0.4.4, reranker bge-reranker-v2-m3 served by llama.cpp (--embedding --pooling rank) behind provider: openai.