mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6124] Lore search stops seeing part of a lorebook as soon as one entry in it has embeddings #3399
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#3399
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/6124
Originally assigned to: @SpicyMarinara on GitHub.
When a character or GM uses the lore search tool on a lorebook where only some entries have embeddings, the search quietly answers from the embedded entries only. Entries that have not been vectorized yet - or that you deliberately marked "No Vector" - are skipped, the tool result says nothing about skipping them, and the reply is often about the wrong entry. A book with no embeddings at all actually searches better than the same book with one unrelated entry embedded.
How to reproduce (try it yourself)
Before you start you need a connection with an Embedding Model set, and a chat connection that supports tool calling. Vectorize the lorebook with the same embedding connection the chat will use, otherwise the stored vectors are ignored entirely and you will not see the bug.
Harbor, make it global (or attach it to the character you will chat with).Elena, ContentHarbor master, Keys empty.Smuggler tunnels, Contentwho runs the docks at night, Keys empty.Smuggler tunnelsand switch itsNo Vectortoggle ON. Save.Semantic Search (Embeddings)section, pick your embedding connection, clickVectorize 1 missing. The header reads1 / 1 entries vectorized. 1 excluded.- onlyElenahas a vector now.Let the GM search lore. (A Roleplay or Conversation chat withEnable Tool Useon shows the same thing, and there it is even quieter - see below.)Search the lorebook and tell me, word for word, what it says about who runs the docks.search_lorebooktool block in the reply.What you'll see: the result contains only
Elena/Harbor master, with"count": 1. TheSmuggler tunnelsentry, whose content is literally the thing being asked about, is absent, and nothing in the result says an entry was skipped. The model then answers about Elena or invents something about the docks.What should happen:
Smuggler tunnelsshould come back, or the result should at least say that part of the book was not searched.Worth doing, because it shows how backwards this is: click
Delete Stored Vectorsin that same section and ask again. With zero embeddings the search falls back to plain text matching and returns the correct entry. Deleting your embeddings makes the search better. (The text fallback is a literal substring match on the content, so this control only works when the model's query text appears in the entry - it picks its own wording, so if the control comes back empty, check thequeryfield in the tool block.)You can also get into this state by accident, without touching
No Vector: vectorize the whole book, then edit one character of any entry's name, content or keys and save. That entry's embedding is cleared on save, the editor shows1 still need embeddings., and the entry you just edited is the one the search can no longer find.Where it is
At staging
52799569c,packages/server/src/services/generation/tool-resolution-runtime.ts, insearchLorebookForTools(starts at :814):vectorizedout ofeligible, dropping anything withexcludeFromVectorizationor no embedding.if (vectorized.length) {- the branch is taken as soon as one entry anywhere has a vector.matches.map(...)unconditionally, so the plain-text pass overeligibleat :859-874 can never run for that call.requireVectorsas true only in Game mode, so Roleplay and Conversation have no error path at any point.packages/server/src/services/lorebook/embeddings.ts:270returns a non-null result whenever anything scored at all - there is no minimum relevance - so one unrelated entry is enough to suppress the fallback.packages/server/src/services/tools/tool-executor.ts:800-806shows the payload handed to the model is{query, category, results, count}, wherecountis the number returned; there is no skipped count and no note.What's happening
The lore search treats "this book has embeddings" as "this book is fully embedded." One vectorized entry flips the whole call into semantic-only mode, and the text-matching pass that would have found the rest of the book becomes unreachable. Since scoring never rejects a weak match, an entry with nothing to do with the question still counts as a hit and keeps the fallback from running. Nothing in the result tells the model or the user that entries were left out, so the model answers confidently from a partial view.
The partly-embedded state is normal, not exotic: editing any entry clears its embedding, the lorebook editor has a counter for it ("N still need embeddings."), and the per-entry
No Vectortoggle creates it on purpose. Nothing re-embeds automatically - the one warm-up path only covers entries the lorebook-keeper agent just wrote - so the state sticks until someone clicks Vectorize.Suggested fix
Run the text pass over the eligible-but-not-embedded entries and merge it with the semantic matches, deduplicated. This pattern already exists in the codebase:
packages/server/src/services/agents/knowledge-router.ts:280merges semantic matches with keyword-activated entries viamergeKnowledgeRouterCandidates, and the keyword scanner adds vector matches on top of keyword hits rather than replacing them. The lore-search tool is the one caller that treats semantic as a replacement instead of an addition.If semantic-only is deliberate, then at minimum make it honest: add a skipped count and a short note to the payload so the model can hedge and the user can see it in the tool block. Merging is clearly better for the
No Vectorcase, where the user made a deliberate choice that currently costs them all searchability rather than just semantic searchability.Either way this wants a regression case.
scripts/regressions/game-tool-controls.regression.ts:243-327is the only lane covering this code and it only tests the all-embedded and no-embedded ends; its fixture is nearly there already - add an entry left un-embedded whose content matches the query, and assert it comes back.Context
Introduced by PR #5982 (merged 2026-09-09), which closed issue #5955 and added semantic lore search. That PR's description covers the no-embeddings case ("other chat modes retain text fallback when semantic search is unavailable") but not the partly-embedded case, where the fallback it promises is unreachable. Unreleased on staging - latest release tag is v2.4.4. A separate smaller problem in the same function is filed on its own and worth cross-linking: the search has no minimum relevance score, so it never returns an empty result.
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: #6125 (the missing relevance floor 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). Lore search includes literal matches from entries with missing or incompatible embeddings.