[GH-ISSUE #5104] [Issue]: Vectorized lorebook entries can silently fail to activate #2824

Closed
opened 2026-10-21 05:56:17 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @SpicyMarinara on GitHub (Aug 15, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5104

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Vectorized lorebook entries can fail to activate even when the embedding endpoint is called successfully and the latest user message exactly matches the entry content. The failure is silent: no entry appears in Active Context or the assembled generation prompt, and the available logs do not explain why the match was rejected.

This appears to be an Engine-side embedding compatibility and provenance problem rather than simply poor embedding-model quality.

Expected behavior

An enabled, vectorized lorebook entry whose content exactly matches the current user message should be retrieved and injected into the roleplay context, even when the entry has no keyword triggers.

If stored vectors cannot be compared safely with the configured query embedding source, Marinara Engine should identify the mismatch and provide a useful warning instead of silently returning no matches.

Actual behavior

The embedding model is invoked, but no lorebook match is found:

  • The entry does not appear in Active Context.
  • The entry is absent from the assembled prompt shown by the prompt inspector.
  • The downstream LLM does not receive or use the entry.
  • Logs confirm an embedding request occurred but do not show the similarity score, threshold rejection, incompatible dimensions, or embedding-space mismatch.

Steps to reproduce

  1. Enable vectors for a lorebook.
  2. Add one enabled entry with no keywords and the content Rocks stones mountain ore.
  3. Vectorize the lorebook entry using Casual-Autopsy/snowflake-arctic-embed-l-v2.0-gguf:Q8_0.
  4. Attach the lorebook to a roleplay chat.
  5. Send the exact message Rocks stones mountain ore.
  6. Inspect Active Context and the assembled prompt.

Environment

  • Marinara Engine version: Not provided
  • Install type: Not provided
  • OS + version: Not provided
  • Browser or app shell: Not provided
  • Embedding model: Casual-Autopsy/snowflake-arctic-embed-l-v2.0-gguf:Q8_0

Logs, screenshots, or video

The embedding backend logs show that the embedding model is invoked, but Marinara Engine reports no semantic lorebook match. No Engine-side error is emitted.

Additional context

Code inspection found several independent Engine-side failure risks:

  1. selectLorebookVectorQueryText in packages/server/src/services/lorebook/embeddings.ts concatenates the last 10 messages by default. In a new roleplay, the character opening and other history can dilute a short exact user query.
  2. Manual vectorization in packages/server/src/routes/lorebooks.routes.ts stores only the numeric vector. It does not persist the connection, provider, model, base URL, query/document formatting, pooling mode, or another embedding-space identifier.
  3. Runtime matching independently resolves the chat embedding source in packages/server/src/services/memory-recall-embedding.ts. It can therefore compare stored vectors against a different model or configuration without detecting the mismatch when dimensions happen to agree.
  4. BaseLLMProvider.embed sends a generic OpenAI-compatible { input, model } request for both indexed documents and retrieval queries. Snowflake Arctic Embed v2.0 documents an asymmetric retrieval format: queries require a query: prefix while documents do not, and the model recommends CLS pooling. Marinara Engine currently has no way to express this distinction.
  5. The matching path in packages/server/src/services/lorebook/keyword-scanner.ts silently treats unequal vector dimensions as similarity 0 and does not expose rejected candidate scores or reasons.

Model documentation: https://huggingface.co/Snowflake/snowflake-arctic-embed-l-v2.0

Suggested acceptance criteria:

  • An exact-content, keyword-free vector entry activates using a supported embedding source and appears in both Active Context and the assembled generation prompt.
  • Stored lorebook vectors retain enough embedding-space provenance to detect when the runtime query source is incompatible.
  • Re-vectorizing with a different model or configuration cannot leave silently incompatible vectors behind.
  • Retrieval supports configurable or model-profile-based query/document formatting for asymmetric embedding models, including Snowflake Arctic's query prefix.
  • The current user message is not unintentionally overwhelmed by older chat history during semantic lookup.
  • Debug logging reports the selected embedding source/space, vector dimensions, raw and calibrated similarity, threshold, and rejection reason without logging secrets.
  • Regression coverage includes an exact-match entry with no keywords, a deliberately mismatched embedding space, and an asymmetric query-prefix model or provider mock.

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 @SpicyMarinara on GitHub (Aug 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5104 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Vectorized lorebook entries can fail to activate even when the embedding endpoint is called successfully and the latest user message exactly matches the entry content. The failure is silent: no entry appears in Active Context or the assembled generation prompt, and the available logs do not explain why the match was rejected. This appears to be an Engine-side embedding compatibility and provenance problem rather than simply poor embedding-model quality. ## Expected behavior An enabled, vectorized lorebook entry whose content exactly matches the current user message should be retrieved and injected into the roleplay context, even when the entry has no keyword triggers. If stored vectors cannot be compared safely with the configured query embedding source, Marinara Engine should identify the mismatch and provide a useful warning instead of silently returning no matches. ## Actual behavior The embedding model is invoked, but no lorebook match is found: - The entry does not appear in Active Context. - The entry is absent from the assembled prompt shown by the prompt inspector. - The downstream LLM does not receive or use the entry. - Logs confirm an embedding request occurred but do not show the similarity score, threshold rejection, incompatible dimensions, or embedding-space mismatch. ## Steps to reproduce 1. Enable vectors for a lorebook. 2. Add one enabled entry with no keywords and the content `Rocks stones mountain ore`. 3. Vectorize the lorebook entry using `Casual-Autopsy/snowflake-arctic-embed-l-v2.0-gguf:Q8_0`. 4. Attach the lorebook to a roleplay chat. 5. Send the exact message `Rocks stones mountain ore`. 6. Inspect Active Context and the assembled prompt. ## Environment - Marinara Engine version: Not provided - Install type: Not provided - OS + version: Not provided - Browser or app shell: Not provided - Embedding model: `Casual-Autopsy/snowflake-arctic-embed-l-v2.0-gguf:Q8_0` ## Logs, screenshots, or video The embedding backend logs show that the embedding model is invoked, but Marinara Engine reports no semantic lorebook match. No Engine-side error is emitted. ## Additional context Code inspection found several independent Engine-side failure risks: 1. `selectLorebookVectorQueryText` in `packages/server/src/services/lorebook/embeddings.ts` concatenates the last 10 messages by default. In a new roleplay, the character opening and other history can dilute a short exact user query. 2. Manual vectorization in `packages/server/src/routes/lorebooks.routes.ts` stores only the numeric vector. It does not persist the connection, provider, model, base URL, query/document formatting, pooling mode, or another embedding-space identifier. 3. Runtime matching independently resolves the chat embedding source in `packages/server/src/services/memory-recall-embedding.ts`. It can therefore compare stored vectors against a different model or configuration without detecting the mismatch when dimensions happen to agree. 4. `BaseLLMProvider.embed` sends a generic OpenAI-compatible `{ input, model }` request for both indexed documents and retrieval queries. Snowflake Arctic Embed v2.0 documents an asymmetric retrieval format: queries require a `query: ` prefix while documents do not, and the model recommends CLS pooling. Marinara Engine currently has no way to express this distinction. 5. The matching path in `packages/server/src/services/lorebook/keyword-scanner.ts` silently treats unequal vector dimensions as similarity `0` and does not expose rejected candidate scores or reasons. Model documentation: https://huggingface.co/Snowflake/snowflake-arctic-embed-l-v2.0 Suggested acceptance criteria: - An exact-content, keyword-free vector entry activates using a supported embedding source and appears in both Active Context and the assembled generation prompt. - Stored lorebook vectors retain enough embedding-space provenance to detect when the runtime query source is incompatible. - Re-vectorizing with a different model or configuration cannot leave silently incompatible vectors behind. - Retrieval supports configurable or model-profile-based query/document formatting for asymmetric embedding models, including Snowflake Arctic's query prefix. - The current user message is not unintentionally overwhelmed by older chat history during semantic lookup. - Debug logging reports the selected embedding source/space, vector dimensions, raw and calibrated similarity, threshold, and rejection reason without logging secrets. - Regression coverage includes an exact-match entry with no keywords, a deliberately mismatched embedding space, and an asymmetric query-prefix model or provider mock. ## 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-21 05:56:17 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 15, 2026):

SpicyMarinara is taking this in fix/5104-lorebook-vector-compat; a draft PR will be linked after the first compatibility slice is committed.

<!-- gh-comment-id:5304588063 --> @SpicyMarinara commented on GitHub (Aug 15, 2026): SpicyMarinara is taking this in `fix/5104-lorebook-vector-compat`; a draft PR will be linked after the first compatibility slice is committed.
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#2824
No description provided.