[GH-ISSUE #6134] The lorebook entry search endpoint only matches entry names, even though it says it searches content and keys too #3411

Closed
opened 2026-10-21 06:02:49 +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/6134

Originally assigned to: @SpicyMarinara on GitHub.

The server has a lorebook entry search endpoint that its own note describes as searching an entry's name, content, and keys. It only ever looks at the name. A search for a word that appears only in an entry's text, or only in one of its keys, comes back empty.

Nothing in the app calls this endpoint any more, so no one is losing search results today. It matters because the Pixelforge roadmap in the Marinara-Agents repo points future work at this endpoint as a ready-made search, and describes it as doing more than it does.

How to reproduce (try it yourself)

  1. Open Marinara Engine and go to Lorebooks, then New Lorebook. Name it ProbeBook and save.
  2. Open ProbeBook, click Add Entry, and fill it in exactly: Name ZebraName, Content the secret word is QUOKKAWORD here, and one Key ARMADILLOKEY. Save the entry.
  3. There is no button or search box that reaches the endpoint, so trigger it directly. In the same browser tab, press F12 to open DevTools, go to Console, and run these one at a time:
  • await (await fetch('/api/lorebooks/search/entries?q=ZebraName')).json()
  • await (await fetch('/api/lorebooks/search/entries?q=QUOKKAWORD')).json()
  • await (await fetch('/api/lorebooks/search/entries?q=ARMADILLOKEY')).json()

What you'll see: the first query returns a one-item list with the entry. The second returns [], even though QUOKKAWORD is in the entry's content. The third returns [], even though ARMADILLOKEY is one of its keys. (The name match is case-insensitive, so ?q=zebra also returns the entry - that confirms the endpoint is alive and it really is the name-only match producing the empty results.)

What should happen: all three return the entry, because the method's own note says it searches name, content, and keys.

Where it is

At staging 52799569c:

  • packages/server/src/services/storage/lorebooks.storage.ts:1359 - the note: /** Search entries by keyword match in name/content/keys. */
  • packages/server/src/services/storage/lorebooks.storage.ts:1365 - the entire matching condition in searchEntries(query): .where(like(lorebookEntries.name, pattern))
  • packages/server/src/routes/lorebooks.routes.ts:846-850 - app.get("/search/entries", ...) calling storage.searchEntries(query), registered under /api/lorebooks

What's happening

The database query has one condition and it only looks at the name column. Content and keys are never consulted. The note above it has said name/content/keys since the repository's first commit (8038e96c1), so this is not a behaviour that was narrowed later - the note described an intention that was never implemented.

The endpoint is also dead code. The client hook that used to call it, useSearchLorebookEntries, was removed from packages/client/src/hooks/use-lorebooks.ts in 232aae8af (2026-07-22, "Clean up unused code and dependencies") and nothing replaced it. At staging the only mentions of searchEntries or search/entries anywhere in the Engine are the route itself and the storage method. The lorebook search boxes people actually see search whole books through GET /api/lorebooks?search=, a different path. The GM's search_lorebook tool is also a different path (tool-executor.ts:330 goes to context.searchLorebook, which does match name, content, and keys), so no chat or GM session is missing results because of this.

Suggested fix

Make one decision and apply it in one pass. The cheaper option looks like the right one: delete the /search/entries route and the searchEntries storage method, since nothing has called them in almost two months, and fix the stale pointer in the other repo at the same time - packages/pixelforge/docs/ROADMAP.md:581 in Marinara-Agents tells a future implementer not to build search because it "already exists in the Engine" at this URL "with calibrated-cosine ranking behind it." Neither half is true of this endpoint: there is no ranking at all, it orders by the entry's order field. That line should point at the GM lorebook search path instead.

If the endpoint is kept instead, widen the condition to name OR content OR keys and leave the note as it is. Keys are stored as a serialized JSON array, so that needs a deliberate matching strategy rather than a plain text match over the raw JSON, or searches will start hitting brackets and quote characters.

Context

Issue #5955 named this exact file and line range as an "adjacent, smaller" item deliberately left out of scope; PR #5982 delivered that issue's actual ask (semantic GM lorebook search) and #5955 closed on 2026-09-09 with this part untouched and no open issue tracking it. The behaviour is not a recent regression and is present in the latest release v2.4.4 - it dates to the repository's initial import.

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.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6134 Originally assigned to: @SpicyMarinara on GitHub. The server has a lorebook entry search endpoint that its own note describes as searching an entry's name, content, and keys. It only ever looks at the name. A search for a word that appears only in an entry's text, or only in one of its keys, comes back empty. Nothing in the app calls this endpoint any more, so no one is losing search results today. It matters because the Pixelforge roadmap in the Marinara-Agents repo points future work at this endpoint as a ready-made search, and describes it as doing more than it does. ## How to reproduce (try it yourself) 1. Open Marinara Engine and go to Lorebooks, then New Lorebook. Name it `ProbeBook` and save. 2. Open `ProbeBook`, click Add Entry, and fill it in exactly: Name `ZebraName`, Content `the secret word is QUOKKAWORD here`, and one Key `ARMADILLOKEY`. Save the entry. 3. There is no button or search box that reaches the endpoint, so trigger it directly. In the same browser tab, press F12 to open DevTools, go to Console, and run these one at a time: - `await (await fetch('/api/lorebooks/search/entries?q=ZebraName')).json()` - `await (await fetch('/api/lorebooks/search/entries?q=QUOKKAWORD')).json()` - `await (await fetch('/api/lorebooks/search/entries?q=ARMADILLOKEY')).json()` **What you'll see:** the first query returns a one-item list with the entry. The second returns `[]`, even though QUOKKAWORD is in the entry's content. The third returns `[]`, even though ARMADILLOKEY is one of its keys. (The name match is case-insensitive, so `?q=zebra` also returns the entry - that confirms the endpoint is alive and it really is the name-only match producing the empty results.) **What should happen:** all three return the entry, because the method's own note says it searches name, content, and keys. ## Where it is At staging `52799569c`: - `packages/server/src/services/storage/lorebooks.storage.ts:1359` - the note: `/** Search entries by keyword match in name/content/keys. */` - `packages/server/src/services/storage/lorebooks.storage.ts:1365` - the entire matching condition in `searchEntries(query)`: `.where(like(lorebookEntries.name, pattern))` - `packages/server/src/routes/lorebooks.routes.ts:846-850` - `app.get("/search/entries", ...)` calling `storage.searchEntries(query)`, registered under `/api/lorebooks` ## What's happening The database query has one condition and it only looks at the name column. Content and keys are never consulted. The note above it has said name/content/keys since the repository's first commit (`8038e96c1`), so this is not a behaviour that was narrowed later - the note described an intention that was never implemented. The endpoint is also dead code. The client hook that used to call it, `useSearchLorebookEntries`, was removed from `packages/client/src/hooks/use-lorebooks.ts` in `232aae8af` (2026-07-22, "Clean up unused code and dependencies") and nothing replaced it. At staging the only mentions of `searchEntries` or `search/entries` anywhere in the Engine are the route itself and the storage method. The lorebook search boxes people actually see search whole books through `GET /api/lorebooks?search=`, a different path. The GM's `search_lorebook` tool is also a different path (`tool-executor.ts:330` goes to `context.searchLorebook`, which does match name, content, and keys), so no chat or GM session is missing results because of this. ## Suggested fix Make one decision and apply it in one pass. The cheaper option looks like the right one: delete the `/search/entries` route and the `searchEntries` storage method, since nothing has called them in almost two months, and fix the stale pointer in the other repo at the same time - `packages/pixelforge/docs/ROADMAP.md:581` in Marinara-Agents tells a future implementer not to build search because it "already exists in the Engine" at this URL "with calibrated-cosine ranking behind it." Neither half is true of this endpoint: there is no ranking at all, it orders by the entry's `order` field. That line should point at the GM lorebook search path instead. If the endpoint is kept instead, widen the condition to name OR content OR keys and leave the note as it is. Keys are stored as a serialized JSON array, so that needs a deliberate matching strategy rather than a plain text match over the raw JSON, or searches will start hitting brackets and quote characters. ## Context Issue #5955 named this exact file and line range as an "adjacent, smaller" item deliberately left out of scope; PR #5982 delivered that issue's actual ask (semantic GM lorebook search) and #5955 closed on 2026-09-09 with this part untouched and no open issue tracking it. The behaviour is not a recent regression and is present in the latest release v2.4.4 - it dates to the repository's initial import. 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.
bsakaguchi 2026-10-21 06:02:49 +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:5651924426 --> @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). The lore entry search endpoint matches names, content, and parsed keys literally and case-insensitively.

<!-- gh-comment-id:5652785724 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). The lore entry search endpoint matches names, content, and parsed keys literally and case-insensitively.
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#3411
No description provided.