mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6708] [Issue]: Memory re-vectorization fails on long chats because all chunks go out in a single embedding request #3757
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#3757
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 @boricha417 on GitHub (Sep 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6708
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Re-vectorizing memories for a long chat fails every time because Marinara sends all memory chunks of the chat to the
/embeddingsendpoint in one request. NanoGPT (and OpenAI-compatible providers in general) cap a single embedding request at 300,000 tokens, so a chat estimated at ~543k tokens is rejected with HTTP 400 no matter how many times the rebuild is retried. Lorebook vectorization already batches its requests (BATCH_SIZE = 50inlorebooks.routes.ts, reduced to 10 for the sequential path in #5768), but memory recall does not.This is different from #3317: that issue was about a single input being longer than the model's context (fixed by splitting texts at 18,000 chars). Here every individual input is fine; it is the sum of all inputs in one request that exceeds the provider's batch limit.
Why this happens in normal use
This is not an exotic edge case; it is the normal outcome of an unbounded request size:
The request grows linearly with chat length, so every chat eventually crosses the limit. The 300k-token cap is not NanoGPT-specific: it is OpenAI's documented per-request limit for the embeddings API, and most OpenAI-compatible providers mirror it.
Rebuilding memories is a normal workflow, not a one-off. Marinara itself requires it when the embedding model changes ("Rebuild memories before mixing embedding models"). In my case the bundled local embedder (all-MiniLM-L6-v2) turned out not to understand Korean at all, so I switched to a Korean-capable remote model and had to re-vectorize every chat. That is exactly when the whole history of a long chat is embedded in one go.
Korean (and CJK text in general) tokenizes 2–3× heavier than English, so the limit is reached much sooner. Numbers from my Korean roleplay chats:
That is roughly 750–850 tokens per message, so the cap sits at around 350–400 messages for a Korean chat. Chats of that length are common in roleplay, and any chat that keeps growing will fail on its next rebuild.
Expected behavior
Re-vectorization should split the chunks into multiple embedding requests (for example 20–50 texts per request, or a token-estimated budget per request) so that a chat of any length can be vectorized. Ideally the batch size would be configurable or derived from the provider's error, and partial progress would be kept between batches.
Actual behavior
The rebuild fails with a 400 from the provider and no memory chunks are written. Retrying produces the exact same estimated token count and the same rejection. Once, the same request timed out with a 504 from the provider instead, which is likely the same oversized request hitting the provider's time limit.
Steps to reproduce
qwen/qwen3-embedding-8b(max input 32k tokens, max batch 300k tokens).Environment
ghcr.io/pasta-devs/marinara-engine:latest, pulled 2026-09-16)qwen/qwen3-embedding-8bLogs, screenshots, or video
Four identical failures within two minutes (retries on the 643-message chat), preceded by one 504, then the 809-message chat about twenty minutes later:
Stack (identical for every 400):
Additional context
Where the single request is built (main,
packages/server/src/services/memory-recall.ts,chunkAndEmbedMessagesUnlocked):embedMemoryRecallTextspasses the whole array toprovider.embed, andOpenAIProvider.embedinbase-provider.tsposts{ input: texts, model }as-is, so the request size grows linearly with chat length. The lorebook path inlorebooks.routes.tsalready loopsfor (let i = 0; i < texts.length; i += BATCH_SIZE); the same approach inchunkAndEmbedMessagesUnlocked(concatenating the per-batch vectors before the dimension check and insert) would fix this.Nice-to-have: when the configured embedding source fails, the current log line does not include the chat id, so it is hard to tell which chat failed from the server log alone.
@SirAdoni commented on GitHub (Sep 26, 2026):
I'm working on this in a clean sandbox based on current staging. I'll reproduce the oversized embedding request, add bounded batching with regression coverage, and keep this fix in a focused PR.