mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6125] The Game Master's lorebook search always finds something, even when the lorebook has nothing to do with the question #3402
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#3402
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6125
Originally assigned to: @SpicyMarinara on GitHub.
When the Game Master searches an enabled lorebook, the search can never come back empty. If the lorebook has any vectorized entries at all, the search returns its best-ranked entries no matter how unrelated they are - so a book about an orchard answers a question about the docks, and the Game Master is told it found a match.
How to reproduce (try it yourself)
Before you start you need two things: an embedding connection the chat can use (Settings -> Connections, or the local embedder) - vectorize with the same connection you then chat on - and a chat connection that supports native tool calls.
Orchard Valley. Add three entries, none of which mentions docks, harbours, ships or shipping:Elena- keyselena, orchard- "Elena tends the orchard on the northern hill and bakes pear tarts."Winter Festival- keysfestival- "The village lights lanterns on the longest night."The Quarry Road- keysquarry- "A rutted track climbs to the abandoned granite quarry."Orchard Valleyfor it. Go to Chat Settings -> Function Calling, pick a connection that supports native tool calls (the lore-search switch stays greyed out until you do), then turn on the lore-search switch ("Search enabled, vectorized lore by meaning…"). You can leave the general tools toggle off; this switch attaches the search on its own.Who runs the docks in this town?What you'll see:
"count": 3- all three entries handed back for a book that says nothing about docks, most of them with"similarity": 0. (Don't compare thequeryfield in the result to the sentence you typed; it echoes whatever wording the Game Master chose.)What should happen:
"count": 0with an empty result list, so the Game Master is told plainly that nothing in the book matched, instead of being handed the least-irrelevant entries.There is a two-second version with no provider involved: a small script driving the real
resolveGenerationToolsandexecuteToolCallForModelthrough a deterministic mock embedder reproduces the same result (count: 3, scores0.214 / 0 / 0).Where it is
packages/server/src/services/generation/tool-resolution-runtime.ts,searchLorebookForTools(lines 832-845 at staging52799569c): when any entry in scope has a vector, it callssemanticShortlistLorebookEntries(vectorized, query, { ...lorebookEmbeddingOptions, topK: 20 })- no minimum similarity is passed - and returns immediately, before the substring branch at :856-871 ever runs.packages/server/src/services/lorebook/embeddings.ts,semanticShortlistLorebookEntries(:255-270): scores, sorts,.slice(0, topK), thenreturn matches.length > 0 ? matches : null. A non-empty list is the only gate.calibrateLorebookSimilarity(:114-118) clamps to[0,1], so an unrelated entry lands on exactly0and is still returned.packages/server/src/services/tools/tool-executor.ts:804-806passes{ query, category, results, count }to the model verbatim.What's happening
The semantic shortlist is a plain top-20 ranker with no notion of "not good enough". Similarity is calibrated against three fixed, mutually unrelated sentences, so genuine noise calibrates to about zero - and zero survives the ranker, because the only thing checked is whether the list is non-empty. Since this branch returns early, the keyword branch that would have produced an empty list never runs; and in Game mode the search is called with vectors required, so today the tool can report "no match" only when it has no vectors at all, never when it has vectors and none of them are relevant.
Suggested fix
Give the shortlist a minimum-relevance argument, and have the lore-search tool return an empty result set when nothing clears it, so the model can distinguish "nothing matched" from "here is the closest thing I have". Alternatively, or in addition, tell the model explicitly in the result when the top row did not beat the unrelated-text baseline.
On where the number comes from: the codebase already has two floors to look at -
SEMANTIC_SUMMARY_MIN_SIMILARITY = 0.15inroleplay-summary-retrieval.tsfor auto-injected summaries, and the per-lorebook Score Threshold (default 0.3) that automatic activation applies inkeyword-scanner.ts:643-655. Treat these as precedents for picking a value, not as settings to wire through: #5955 deliberately let this tool reach past the per-turn activation threshold and result cap, and that per-lorebook setting is worded and documented as governing activation, so honouring it verbatim here would work against what the tool was built for. A low baseline-relative floor keeps the feature's reach while letting it say no. Sanity-check the threshold against a real embedding backend rather than assuming the activation default transfers.knowledge-router.ts:264-280calls the same floor-less shortlist; the fix should decide explicitly whether the floor applies there too (the consequence is milder, since an LLM then picks from the shortlist). A negative-case regression is cheap:scripts/regressions/game-tool-controls.regression.ts:300-306already builds this exact fixture and asserts only the positive direction.Context
This is how the semantic lore-search path shipped in PR #5982, which implemented issue #5955 (both merged after v2.4.4, so this is unreleased on staging). Neither the issue nor the PR mentions a relevance floor, and no tracker exists for it; related-but-separate floor bugs were handled in #2287 (memory recall) and #3627 (automatic activation). One reading is that a scored top-k list is simply the ordinary shape of a search tool and the model can discount a zero - against that: this is the one feature meant to stop the Game Master inventing lore, nothing in the tool's description tells the model what a similarity of 0 means, and a retrieval tool that never returns nothing teaches the model to treat every row as an answer. A sibling issue about the same function - the search answering only from the vectorized part of a partly-vectorized book - is filed separately; it is a different fix.
Found by an AI-assisted sweep of merged PR #5982 against issue #5955, then re-verified against staging
52799569con 2026-09-13. Please verify before fixing.Related issue from the same sweep: #6124 (the partly-vectorized book case in the same search function).
@SpicyMarinara commented on GitHub (Sep 13, 2026):
@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
@SpicyMarinara commented on GitHub (Sep 13, 2026):
Fixed in #6137, now merged to staging (
e044997a2). Semantic lore matches must meet a relevance floor calibrated against the real embedding model.