mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5955] Let the GM search the lorebook for what a scene needs (and make that search semantic) #3297
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#3297
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 8, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5955
Originally assigned to: @SpicyMarinara on GitHub.
Ask: the GM should be able to look things up in the lorebook — semantically, the way Professor Mari's
[fetch:]does — before it writes narration, so it can pull in the entries the scene actually needs. Behind a toggle.Reframe from recon: the tool already exists and already runs in Game Mode.
search_lorebookis a shipped built-in, in no mode-restriction list, default-on whenever "Enable Tool Use" is on. Two things are genuinely missing.1. It isn't semantic — it's substring matching.
searchLorebookForTools(services/generation/tool-resolution-runtime.ts:807-833) lowercases and calls.includes()on name, content and keys, capped at 20 results. A GM asking for "the vampire guy" or "who runs the docks" gets nothing back unless those literal characters appear in an entry. Meanwhile the calibrated-cosine ranker already exists and is used elsewhere —semanticShortlistLorebookEntries(services/lorebook/embeddings.ts:222-271), which subtracts a measured baseline so thresholds mean something across embedding backends. Routing the tool through it is the small, self-contained half of this issue, and it's worth doing on its own merits: the substring behavior is a live shortcoming in every mode, today, not just Game.(Adjacent, smaller:
GET /search/entriesis documented as searching "name/content/keys" but its implementation islike(name, …)only —services/storage/lorebooks.storage.ts:1359-1367.)Prerequisite worth stating: semantic search over a book does nothing until that book has been vectorized (
POST /lorebooks/:id/vectorize). Nothing vectorizes automatically.2. Getting it today means arming everything. "Enable Tool Use" turns on the whole default-on tool set. #5924 added exactly the channel this needs —
GAME_MODE_AUTO_ATTACH_TOOL_NAMESwith its gate atgenerate.routes.ts:4953— sosearch_lorebookcould ride along on GM turns behind its own switch, following thegameUseMusicDjmetadata-flag precedent (generate.routes.ts:1519-1524).On "can it ride the thinking process?" — no, and not because of our plumbing. On both providers the model reasons, emits the call, and that ends the message; the result comes back in the next request. Anthropic puts thinking and
tool_usein the same assistant message and takes the result as atool_resultin a fresh request (anthropic.provider.ts:594-612,:258-272); interleaved thinking isn't enabled here. Gemini carries reasoning state forward via thought signatures (google.provider.ts:793-801,:866-872) but still only into the next request — and Gemini with thinking on doesn't stream at all (:592,:853), so a lookup there means two buffered calls with no token flow. The honest framing is: the GM reasons, decides it needs lore, calls, and the result informs a second pass — which is where the narration gets written.What this adds over what already runs, stated honestly. A keyword and semantic lorebook scan already happens automatically every turn (
keyword-scanner.ts:607-690). But it embeds recent player messages (embeddings.ts:28-42), so the GM cannot make it search for something the player didn't mention. The tool adds: a query the GM authors, the ability to ask again with a better query, and reach past the per-turn threshold and result cap. That's the real gain — not "semantic search in Game Mode," which exists.Costs to put in front of the user at the toggle: one extra full model round per call (the whole prompt is re-sent, so input tokens are paid again); Gemini-with-thinking loses streaming; and Claude/Grok subscription connections ignore tools entirely (
grok-subscription.provider.ts:336; the Claude subscription provider implements nochatComplete), so it must degrade silently rather than appear broken for those users.One alternative worth weighing before building the tool.
knowledge-router(services/agents/knowledge-router.ts) already does exactly this shape as a pre-generation pass — it seeds candidates from the same semantic ranker, lets a model pick which entries are relevant, and injects them verbatim, with no mid-turn round trip. It's blocked in Game Mode by two allowlists (chat-mode-agent-policy.ts:17, plusknowledge-retrieval's own roleplay-only manifest), and unblocking is a small edit. Trade-off: the router is cheaper and doesn't interrupt the turn, but the GM can't ask a follow-up question mid-narration. The tool is iterative but costs a round each time.Suggested order regardless of which shape wins: make
search_lorebooksemantic first (small, useful everywhere), then decide tool-vs-router for the Game Mode surfacing.@SpicyMarinara commented on GitHub (Sep 9, 2026):
@SpicyMarinara owns this sweep implementation in draft #5982. I am reusing the calibrated semantic lorebook shortlist and existing Game tool attachment path, with a separate opt-in and no automatic vectorization.