[GH-ISSUE #927] [Feature]: Use semantic lorebook candidates for Knowledge Router #452

Closed
opened 2026-10-20 17:29:01 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (May 16, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/927

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

The Knowledge Router currently depends heavily on the source lorebook candidate list and keyword activation behavior. For large lorebooks, this can make routing less precise and more expensive because the router may need to consider too many entries, while also missing entries that are relevant by meaning but not by exact trigger keys.

This is especially noticeable for lorebooks where entry names, descriptions, or content are semantically related to the current scene, but the conversation does not contain the exact configured key phrase.

Proposed solution

Add a semantic candidate-preparation layer for Knowledge Router lorebook entries.

The router should be able to:

  • Build embedding text from each lorebook entry's name, description, keys, secondary keys, and content.
  • Warm missing lorebook entry embeddings in small batches during generation.
  • Build a semantic query from recent messages, chat summary, and game state.
  • Rank entries with cosine similarity and use the top matches as router candidates.
  • Merge semantic matches with entries already activated by keyword scanning.
  • Respect existing enabled/disabled state, ephemeral overrides, character filters, tag filters, generation trigger filters, and game-state scan context.
  • Fall back to the existing filtered entry list when embeddings are unavailable, empty, or incompatible.

Alternatives considered

A keyword-only router path is simpler, but it can miss relevant lorebook entries unless users maintain very broad key lists.

Routing over every eligible lorebook entry preserves coverage, but it can produce oversized catalogs and make the router less reliable on large source lorebooks.

Additional context

This should integrate with the existing memory recall embedding source rather than introducing a separate embedding configuration path.

The implementation should include tests for embedding text construction, embedding warmup behavior, cosine similarity, semantic top-K ranking, fallback behavior, and router candidate merging.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (May 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/927 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? The Knowledge Router currently depends heavily on the source lorebook candidate list and keyword activation behavior. For large lorebooks, this can make routing less precise and more expensive because the router may need to consider too many entries, while also missing entries that are relevant by meaning but not by exact trigger keys. This is especially noticeable for lorebooks where entry names, descriptions, or content are semantically related to the current scene, but the conversation does not contain the exact configured key phrase. ## Proposed solution Add a semantic candidate-preparation layer for Knowledge Router lorebook entries. The router should be able to: - Build embedding text from each lorebook entry's name, description, keys, secondary keys, and content. - Warm missing lorebook entry embeddings in small batches during generation. - Build a semantic query from recent messages, chat summary, and game state. - Rank entries with cosine similarity and use the top matches as router candidates. - Merge semantic matches with entries already activated by keyword scanning. - Respect existing enabled/disabled state, ephemeral overrides, character filters, tag filters, generation trigger filters, and game-state scan context. - Fall back to the existing filtered entry list when embeddings are unavailable, empty, or incompatible. ## Alternatives considered A keyword-only router path is simpler, but it can miss relevant lorebook entries unless users maintain very broad key lists. Routing over every eligible lorebook entry preserves coverage, but it can produce oversized catalogs and make the router less reliable on large source lorebooks. ## Additional context This should integrate with the existing memory recall embedding source rather than introducing a separate embedding configuration path. The implementation should include tests for embedding text construction, embedding warmup behavior, cosine similarity, semantic top-K ranking, fallback behavior, and router candidate merging. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:01 +07:00
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#452
No description provided.