[GH-ISSUE #6124] Lore search stops seeing part of a lorebook as soon as one entry in it has embeddings #3399

Closed
opened 2026-10-21 06:02:42 +07:00 by bsakaguchi · 2 comments
Owner

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.

  1. Sidebar -> Lorebooks -> New Lorebook, name it Harbor, make it global (or attach it to the character you will chat with).
  2. Add entry 1: Name Elena, Content Harbor master, Keys empty.
  3. Add entry 2: Name Smuggler tunnels, Content who runs the docks at night, Keys empty.
  4. Expand Smuggler tunnels and switch its No Vector toggle ON. Save.
  5. Open the Semantic Search (Embeddings) section, pick your embedding connection, click Vectorize 1 missing. The header reads 1 / 1 entries vectorized. 1 excluded. - only Elena has a vector now.
  6. Open a Game-mode chat with that lorebook active. Chat Settings -> Function Calling -> turn ON Let the GM search lore. (A Roleplay or Conversation chat with Enable Tool Use on shows the same thing, and there it is even quieter - see below.)
  7. Send: Search the lorebook and tell me, word for word, what it says about who runs the docks.
  8. Expand the search_lorebook tool block in the reply.

What you'll see: the result contains only Elena / Harbor master, with "count": 1. The Smuggler tunnels entry, 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 tunnels should 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 Vectors in 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 the query field 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 shows 1 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, in searchLorebookForTools (starts at :814):

  • :829-831 builds vectorized out of eligible, dropping anything with excludeFromVectorization or no embedding.
  • :832 if (vectorized.length) { - the branch is taken as soon as one entry anywhere has a vector.
  • :834-843 returns matches.map(...) unconditionally, so the plain-text pass over eligible at :859-874 can never run for that call.
  • :937 passes requireVectors as true only in Game mode, so Roleplay and Conversation have no error path at any point.

packages/server/src/services/lorebook/embeddings.ts:270 returns 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-806 shows the payload handed to the model is {query, category, results, count}, where count is 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 Vector toggle 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:280 merges semantic matches with keyword-activated entries via mergeKnowledgeRouterCandidates, 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 Vector case, 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-327 is 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 52799569c on 2026-09-13. Please verify before fixing.

Related issue from the same sweep: #6125 (the missing relevance floor in the same search function).

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. 1. Sidebar -> Lorebooks -> New Lorebook, name it `Harbor`, make it global (or attach it to the character you will chat with). 2. Add entry 1: Name `Elena`, Content `Harbor master`, Keys empty. 3. Add entry 2: Name `Smuggler tunnels`, Content `who runs the docks at night`, Keys empty. 4. Expand `Smuggler tunnels` and switch its `No Vector` toggle ON. Save. 5. Open the `Semantic Search (Embeddings)` section, pick your embedding connection, click `Vectorize 1 missing`. The header reads `1 / 1 entries vectorized. 1 excluded.` - only `Elena` has a vector now. 6. Open a Game-mode chat with that lorebook active. Chat Settings -> Function Calling -> turn ON `Let the GM search lore`. (A Roleplay or Conversation chat with `Enable Tool Use` on shows the same thing, and there it is even quieter - see below.) 7. Send: `Search the lorebook and tell me, word for word, what it says about who runs the docks.` 8. Expand the `search_lorebook` tool block in the reply. **What you'll see:** the result contains only `Elena` / `Harbor master`, with `"count": 1`. The `Smuggler tunnels` entry, 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 tunnels` should 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 Vectors` in 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 the `query` field 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 shows `1 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`, in `searchLorebookForTools` (starts at :814): - :829-831 builds `vectorized` out of `eligible`, dropping anything with `excludeFromVectorization` or no embedding. - :832 `if (vectorized.length) {` - the branch is taken as soon as *one* entry anywhere has a vector. - :834-843 returns `matches.map(...)` unconditionally, so the plain-text pass over `eligible` at :859-874 can never run for that call. - :937 passes `requireVectors` as true only in Game mode, so Roleplay and Conversation have no error path at any point. `packages/server/src/services/lorebook/embeddings.ts:270` returns 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-806` shows the payload handed to the model is `{query, category, results, count}`, where `count` is 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 Vector` toggle 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:280` merges semantic matches with keyword-activated entries via `mergeKnowledgeRouterCandidates`, 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 Vector` case, 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-327` is 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 52799569c on 2026-09-13. Please verify before fixing. Related issue from the same sweep: #6125 (the missing relevance floor in the same search function).
bsakaguchi 2026-10-21 06:02:42 +07:00
Author
Owner

@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.

<!-- gh-comment-id:5651923421 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:5652783592 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3399
No description provided.