fix: increase RERANK_CONTEXT_SIZE default 2048→4096, configurable via env var, fix template overhead underestimate#453
Merged
Conversation
…e via QMD_RERANK_CONTEXT_SIZE env var, fix RERANK_TEMPLATE_OVERHEAD underestimate 200→512 Default 2048 was too small for longer documents (session transcripts, CJK text, large markdown files). After truncation the Qwen3 reranker template adds more overhead than the original 200-token estimate, causing node-llama-cpp to throw 'input lengths exceed context size'. Fixes: tobi#91 tobi#290 tobi#291 tobi#314
jaylfc
added a commit
to jaylfc/qmd
that referenced
this pull request
Apr 5, 2026
fix: increase RERANK_CONTEXT_SIZE default 2048→4096, configurable via env var, fix template overhead underestimate
jaylfc
added a commit
to jaylfc/qmd
that referenced
this pull request
Apr 5, 2026
fix: increase RERANK_CONTEXT_SIZE default 2048→4096, configurable via env var, fix template overhead underestimate
tanarchytan
referenced
this pull request
in tanarchytan/lotl
Apr 8, 2026
fix: increase RERANK_CONTEXT_SIZE default 2048→4096, configurable via env var, fix template overhead underestimate
lucndm
pushed a commit
to lucndm/qmd
that referenced
this pull request
Jun 7, 2026
fix: increase RERANK_CONTEXT_SIZE default 2048→4096, configurable via env var, fix template overhead underestimate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
qmd querycrashes on longer documents (session transcripts, CJK text, large markdown files) with:This affects multiple reported issues: #91, #290, #291, #314
Root cause
Two compounding issues:
RERANK_CONTEXT_SIZE = 2048is too small for documents longer than ~1600 tokens. The Qwen3 reranker template overhead is higher than estimated, so even after truncation, some chunks still exceed the context window.RERANK_TEMPLATE_OVERHEAD = 200underestimates the actual Qwen3 chat template overhead. Measured at ~350 tokens on real queries; truncation budgets based on 200 allow documents through that still overflow the context.Fix
RERANK_CONTEXT_SIZEdefault from 2048 → 4096QMD_RERANK_CONTEXT_SIZEenv var for users with tighter memory budgets or very long documentsRERANK_TEMPLATE_OVERHEADfrom 200 → 512 so the truncation budget correctly accounts for actual template overheadThe 4096 default comfortably fits real-world long documents while staying well below the 40 960-token auto size.