[PR #2071] [MERGED] Fix lorebook semantic embedding source #5417

Closed
opened 2026-10-22 04:16:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2071
Author: @cha1latte
Created: 6/3/2026
Status: ✅ Merged
Merged: 6/3/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/issue-2054-lorebook-embedding-model


📝 Commits (3)

  • 67b9d93 Fix lorebook semantic embedding source
  • ac486dd Guard mixed lorebook embedding provenance
  • 67c7568 Preserve embedding override memoization

📊 Changes

5 files changed (+80 additions, -10 deletions)

View changed files

📝 src/engine/contracts/schemas/lorebook.schema.ts (+9 -0)
📝 src/engine/contracts/types/lorebook.ts (+6 -0)
📝 src/engine/generation/active-lorebook-scanner.ts (+46 -2)
📝 src/engine/generation/prompt-assembly.ts (+9 -4)
📝 src/engine/generation/start-generation.ts (+10 -4)

📄 Description

Linked issue

Closes #2054

Why this change

  • Lorebook vectorization stored the embedding connection/model on each entry, but runtime semantic scan normalized those fields away and embedded the query through the active generation connection without a saved embedding target. A lorebook vectorized with a separate embedding connection could then fall back to non-semantic matching during generation.

What changed

  • Preserved embeddingModel, embeddingConnectionId, and embeddingUpdatedAt on normalized lorebook entries.
  • Let runtime lorebook semantic scan pass one unambiguous saved embedding connection/model into the query embedding call.
  • Kept the existing active connection/default behavior when stored vectors have no metadata or mixed embedding targets.

Refactor impact

Primary owner:

  • engine generation

Impact areas reviewed:

  • Lorebook entry contracts and schemas.
  • Runtime active lorebook scanning.
  • Prompt assembly embedding source typing.
  • Generation LLM embedding source.
  • Tauri embedding command path.

Boundary notes:

  • Engine remains React-free and does not import feature/runtime adapters.
  • Frontend API wrappers and Rust command registration were not changed.
  • No dependency, storage migration, or provider declaration changes.

Pressure points touched:

  • Prompt assembly and runtime generation embedding source only.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • Focused scratch proof: pnpm exec vitest run --config scratch/vitest.issue-2054.config.ts passed. It proves runtime semantic scan sends { connectionId: "embedding-connection", model: "text-embedding-test" } from saved vector metadata and activates a semantic-only lorebook entry. It also proves mixed embedding provenance skips semantic comparison instead of falling back to the chat connection and comparing incompatible vector spaces, and that prompt assembly memoization preserves the saved embedding request.
  • pnpm typecheck passed.
  • pnpm check:architecture passed.
  • cargo check --manifest-path src-tauri/Cargo.toml passed.
  • Full pnpm check passed.
  • Not run: live llama.cpp embedding server regression with the reporter's exact local ports/models.
  • Proof-gate helper was unavailable at C:/Users/celia/.codex/tools/marinara-proof-gate.mjs.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Bugfix only; no new discoverable feature or workflow.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

N/A; this is runtime semantic matching behavior, not a visible UI layout change.


🔄 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/2071 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-2054-lorebook-embedding-model` --- ### 📝 Commits (3) - [`67b9d93`](https://github.com/Pasta-Devs/Marinara-Engine/commit/67b9d932887a3033e43b680f1c227ec3c52a92b1) Fix lorebook semantic embedding source - [`ac486dd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ac486dd87eb77c382ff730998839ea0457db8b1c) Guard mixed lorebook embedding provenance - [`67c7568`](https://github.com/Pasta-Devs/Marinara-Engine/commit/67c756828bfa773206e10f8eaf182f82c59f4621) Preserve embedding override memoization ### 📊 Changes **5 files changed** (+80 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/contracts/schemas/lorebook.schema.ts` (+9 -0) 📝 `src/engine/contracts/types/lorebook.ts` (+6 -0) 📝 `src/engine/generation/active-lorebook-scanner.ts` (+46 -2) 📝 `src/engine/generation/prompt-assembly.ts` (+9 -4) 📝 `src/engine/generation/start-generation.ts` (+10 -4) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #2054 ## Why this change - Lorebook vectorization stored the embedding connection/model on each entry, but runtime semantic scan normalized those fields away and embedded the query through the active generation connection without a saved embedding target. A lorebook vectorized with a separate embedding connection could then fall back to non-semantic matching during generation. ## What changed - Preserved `embeddingModel`, `embeddingConnectionId`, and `embeddingUpdatedAt` on normalized lorebook entries. - Let runtime lorebook semantic scan pass one unambiguous saved embedding connection/model into the query embedding call. - Kept the existing active connection/default behavior when stored vectors have no metadata or mixed embedding targets. ## Refactor impact Primary owner: - engine generation Impact areas reviewed: - Lorebook entry contracts and schemas. - Runtime active lorebook scanning. - Prompt assembly embedding source typing. - Generation LLM embedding source. - Tauri embedding command path. Boundary notes: - Engine remains React-free and does not import feature/runtime adapters. - Frontend API wrappers and Rust command registration were not changed. - No dependency, storage migration, or provider declaration changes. Pressure points touched: - Prompt assembly and runtime generation embedding source only. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> <!-- Do not submit *.test.ts or *.test.tsx files as PR proof; cite existing checks, command output, app/browser/Tauri verification, or manual notes instead. --> - [ ] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Focused scratch proof: `pnpm exec vitest run --config scratch/vitest.issue-2054.config.ts` passed. It proves runtime semantic scan sends `{ connectionId: "embedding-connection", model: "text-embedding-test" }` from saved vector metadata and activates a semantic-only lorebook entry. It also proves mixed embedding provenance skips semantic comparison instead of falling back to the chat connection and comparing incompatible vector spaces, and that prompt assembly memoization preserves the saved embedding request. - `pnpm typecheck` passed. - `pnpm check:architecture` passed. - `cargo check --manifest-path src-tauri/Cargo.toml` passed. - Full `pnpm check` passed. - Not run: live llama.cpp embedding server regression with the reporter's exact local ports/models. - Proof-gate helper was unavailable at `C:/Users/celia/.codex/tools/marinara-proof-gate.mjs`. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [ ] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Bugfix only; no new discoverable feature or workflow. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence N/A; this is runtime semantic matching behavior, not a visible UI layout change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:08 +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#5417
No description provided.