mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6670] [Feature]: Optionally include character context in Lorebook semantic search #3733
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#3733
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 @minikkeuen on GitHub (Sep 25, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6670
Originally assigned to: @SpicyMarinara on GitHub.
What problem does this solve?
Lorebook semantic search currently builds its vector query from user messages only.
This appears to be intentional: keeping long assistant/character prose out of the query prevents it from overwhelming a short and specific user message. However, in roleplay chats, assistant messages often contain the actual current scene context rather than just a response to the user.
For example:
Assistant:
User:
If there is a vector-only Lorebook entry about Alex's sensitivity to bright light, the relevant context exists in the conversation, but it is only present in the assistant message. The user's short reply does not provide enough semantic information to retrieve that entry.
Increasing "Query Messages" does not solve this, because it only adds more user messages to the vector query.
This makes semantic Lorebook retrieval much less useful for roleplay styles where the character/assistant writes most of the scene narration.
Proposed solution
Keep the current user-only behavior as the default, but add an optional Lorebook semantic-search setting to also consider recent assistant/character context.
Ideally, assistant context could be evaluated separately from the existing user query rather than simply concatenated with it.
For example:
This would preserve the current design goal: long character prose would not dilute or overwhelm a short user query.
At the same time, users who enable the option could retrieve vectorized Lorebook entries based on events, characters, locations, or other context introduced in the character's recent response.
The existing user-only behavior could remain the default, so this would not change retrieval behavior for existing users.
Alternatives considered
One alternative would be to simply include both user and assistant messages in the same query.
However, this could reintroduce the problem the current user-only implementation appears designed to avoid: long assistant prose may dominate the embedding and reduce the relevance of a short, specific user query.
Another option would be to use only the immediately preceding assistant message together with the current user message. This may work well for roleplay, but separate queries seem preferable because they preserve the user's semantic signal instead of mixing the two contexts.
Additional context
In Engine 2.4.6,
selectLorebookVectorQueryText()filters messages to theuserrole before applying the configured query depth.This behavior is not obvious from the "Query Messages" setting, so it can look like vector retrieval is failing when the relevant information is present in the recent conversation but only in character/assistant messages.
Other roleplay-related semantic retrieval features already consider both user and assistant context. For example, Roleplay Summary retrieval builds its query from the most recent user and assistant messages.
This request is not intended to replace the existing user-focused behavior. The goal is to provide an opt-in retrieval mode for roleplay use cases where assistant-generated scene context is important.
Template check
@SpicyMarinara commented on GitHub (Sep 26, 2026):
SpicyMarinara (Codex) is implementing this as an opt-in lorebook setting. The existing user query will stay unchanged; enabled lorebooks will also score a separate character-context query in the same embedding batch and use the higher match score.