[PR #6701] [MERGED] feat(lorebooks): optionally search character context #7290

Closed
opened 2026-10-23 04:18:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6701
Author: @SpicyMarinara
Created: 9/26/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @SpicyMarinara

Base: staging ← Head: codex/lorebook-character-context-6670


📝 Commits (4)

  • 6da0010 feat(lorebooks): add opt-in character-context setting
  • 6ecc310 feat(lorebooks): score character context in the existing query batch
  • 1ef8ee2 test(lorebooks): cover calibration and missing character context
  • a933c20 Merge remote-tracking branch 'origin/staging' into codex/lorebook-character-context-6670

📊 Changes

22 files changed (+244 additions, -21 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
➕ e2e/lorebook-character-context.e2e.ts (+60 -0)
📝 packages/client/src/components/lorebooks/LorebookEditor.tsx (+20 -0)
📝 packages/client/src/lib/lorebook-duplicate.ts (+1 -0)
📝 packages/client/src/localization/locales/en.json (+3 -1)
📝 packages/server/src/db/schema/lorebooks.ts (+1 -0)
📝 packages/server/src/routes/backup.routes.ts (+1 -0)
📝 packages/server/src/routes/generate.routes.ts (+1 -1)
📝 packages/server/src/routes/lorebooks.routes.ts (+1 -1)
📝 packages/server/src/services/generation/agent-lorebook-triggers.ts (+1 -1)
📝 packages/server/src/services/import/marinara.importer.ts (+1 -0)
📝 packages/server/src/services/lorebook/embeddings.ts (+31 -7)
📝 packages/server/src/services/lorebook/index.ts (+1 -1)
📝 packages/server/src/services/lorebook/keyword-scanner.ts (+8 -6)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+13 -1)
📝 packages/server/src/services/prompt/assembler.ts (+1 -1)
📝 packages/server/src/services/prompt/marker-expander.ts (+1 -1)
📝 packages/server/src/services/storage/lorebooks.storage.ts (+4 -0)
📝 packages/shared/src/schemas/lorebook.schema.ts (+1 -0)
📝 packages/shared/src/types/lorebook.ts (+2 -0)

...and 2 more files

📄 Description

Linked issue

Closes #6670

Why this change

A character can introduce a scene detail that a short user reply does not repeat. User-only lorebook vectors miss those details. The opt-in Include character context setting scores recent character replies separately and retains the higher match, preserving the existing user query and user-only defaults.

What changed

  • Add a per-lorebook setting using the existing editor and storage paths, defaulting to off.
  • Batch separate character queries with the existing user/calibration queries, deduplicating identical character queries. Query Messages applies separately to each role.
  • Retain provenance/dimension checks, thresholds and existing activation gates.
  • Preserve the setting in duplication, native export/import, profile import and Professor Mari edits.

Validation

Passed pnpm check, the full pnpm regression:prompt command, the lorebook decision/round-trip regression, seven UI smoke cases and three save/reload/duplication cases across desktop Chromium, mobile Chromium and mobile WebKit. Inspected light desktop and dark mobile screenshots.

The regression proves the “Are you okay?” character-context example, unchanged default matching, preservation of user matches, separate role depth, compatible-vector selection and a single shared embedding call. No live paid embedding endpoint was used.

Local CodeRabbit completed with one request for additional regression coverage. Added explicit calibration-isolation and no-character-message fallback assertions, then reran the full prompt regression command. Rechecked the integrated branch with pnpm check after merging current staging. No findings were dismissed.

  • Manually verify a vector-only entry based on character narration, with the setting off and on, using your embedding model.
  • Manually inspect the new setting and help text in your preferred theme.

Docs and release impact

Unreleased changelog entry and in-app explanation included. No version bump or docs-tree changes.

Summary by CodeRabbit

  • New Features
    • Lorebook semantic search can optionally include recent character replies as a separate query. User-message search remains the default, and the stronger matching result is used.
    • The setting is saved with lorebooks and preserved when they’re duplicated or imported.
  • Bug Fixes
    • Semantic search can compare multiple query contexts while retaining compatible matches.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6701 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 9/26/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `codex/lorebook-character-context-6670` --- ### 📝 Commits (4) - [`6da0010`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6da001029b328e035e9e68c4a1713478904801e2) feat(lorebooks): add opt-in character-context setting - [`6ecc310`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6ecc3102885c8e0ce9145d599aa69a31d796abf6) feat(lorebooks): score character context in the existing query batch - [`1ef8ee2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1ef8ee25435554527dfab8117d9ac1bdcb83cdec) test(lorebooks): cover calibration and missing character context - [`a933c20`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a933c201b1445f035af74079d65063a7103279a2) Merge remote-tracking branch 'origin/staging' into codex/lorebook-character-context-6670 ### 📊 Changes **22 files changed** (+244 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) ➕ `e2e/lorebook-character-context.e2e.ts` (+60 -0) 📝 `packages/client/src/components/lorebooks/LorebookEditor.tsx` (+20 -0) 📝 `packages/client/src/lib/lorebook-duplicate.ts` (+1 -0) 📝 `packages/client/src/localization/locales/en.json` (+3 -1) 📝 `packages/server/src/db/schema/lorebooks.ts` (+1 -0) 📝 `packages/server/src/routes/backup.routes.ts` (+1 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+1 -1) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+1 -1) 📝 `packages/server/src/services/generation/agent-lorebook-triggers.ts` (+1 -1) 📝 `packages/server/src/services/import/marinara.importer.ts` (+1 -0) 📝 `packages/server/src/services/lorebook/embeddings.ts` (+31 -7) 📝 `packages/server/src/services/lorebook/index.ts` (+1 -1) 📝 `packages/server/src/services/lorebook/keyword-scanner.ts` (+8 -6) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+13 -1) 📝 `packages/server/src/services/prompt/assembler.ts` (+1 -1) 📝 `packages/server/src/services/prompt/marker-expander.ts` (+1 -1) 📝 `packages/server/src/services/storage/lorebooks.storage.ts` (+4 -0) 📝 `packages/shared/src/schemas/lorebook.schema.ts` (+1 -0) 📝 `packages/shared/src/types/lorebook.ts` (+2 -0) _...and 2 more files_ </details> ### 📄 Description ## Linked issue Closes #6670 ## Why this change A character can introduce a scene detail that a short user reply does not repeat. User-only lorebook vectors miss those details. The opt-in **Include character context** setting scores recent character replies separately and retains the higher match, preserving the existing user query and user-only defaults. ## What changed - Add a per-lorebook setting using the existing editor and storage paths, defaulting to off. - Batch separate character queries with the existing user/calibration queries, deduplicating identical character queries. Query Messages applies separately to each role. - Retain provenance/dimension checks, thresholds and existing activation gates. - Preserve the setting in duplication, native export/import, profile import and Professor Mari edits. ## Validation Passed `pnpm check`, the full `pnpm regression:prompt` command, the lorebook decision/round-trip regression, seven UI smoke cases and three save/reload/duplication cases across desktop Chromium, mobile Chromium and mobile WebKit. Inspected light desktop and dark mobile screenshots. The regression proves the “Are you okay?” character-context example, unchanged default matching, preservation of user matches, separate role depth, compatible-vector selection and a single shared embedding call. No live paid embedding endpoint was used. Local CodeRabbit completed with one request for additional regression coverage. Added explicit calibration-isolation and no-character-message fallback assertions, then reran the full prompt regression command. Rechecked the integrated branch with `pnpm check` after merging current staging. No findings were dismissed. - [ ] Manually verify a vector-only entry based on character narration, with the setting off and on, using your embedding model. - [ ] Manually inspect the new setting and help text in your preferred theme. ## Docs and release impact Unreleased changelog entry and in-app explanation included. No version bump or docs-tree changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Lorebook semantic search can optionally include recent character replies as a separate query. User-message search remains the default, and the stronger matching result is used. - The setting is saved with lorebooks and preserved when they’re duplicated or imported. - **Bug Fixes** - Semantic search can compare multiple query contexts while retaining compatible matches. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18:18 +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#7290
No description provided.