[Bug]: Recursive search sends L2 (full content) abstracts to reranker, exceeding batch size limit
Bug Description
The hierarchical retriever's recursive search path sends L2 (detail/content) abstracts to the reranker. L2 abstracts store full file content with no size limit. When the total input (query + all documents) exceeds the reranker model's batch size, the rerank call fails and falls back to vector scores, degrading retrieval quality.
The first rerank call (_prepare_initial_candidates) correctly filters out L2 before reranking. The second rerank call (_recursive_search) does not.
Steps to Reproduce
Have memory files with content > ~200 chars Run a search query that triggers recursive search with mode=RetrieverMode.THINKING Check reranker logs for: input (X tokens) is too large to process. increase the physical batch size (current batch size: 512) Reranker falls back to vector scores
Expected Behavior
Reranker should only receive L0/L1 abstracts (which have size limits: 256/4000 chars). L2 content should be excluded from reranking, matching the behavior of the first rerank call.
Actual Behavior
Recursive search sends all levels (L0, L1, L2) to the reranker. L2 abstracts = full file content (observed 1,000–5,000+ chars). Total input exceeds batch size → rerank fails → falls back to vector scores.
Minimal Reproducible Example
# In hierarchical_retriever.py, line 479:
documents = [str(r.get("abstract", "")) for r in results] # Includes L2
# Should be:
documents = [str(r.get("abstract", "")) for r in results if r.get("level", 2) != 2]
Error Logs:
Error Logs
OpenAI API error: Error code: 500 - {'error': {'code': 500, 'message': 'input (7744 tokens) is too large to process. increase the physical batch size (current batch size: 512)', 'type': 'server_error'}}
Observed token ranges in failures: 515–7,744 tokens.
OpenViking Version
0.4.4
Python Version
3.12.0
Operating System
Linux
Model Backend
Other
Additional Context
Call 1 (_prepare_initial_candidates, line 312) — correctly filters L2:
Copy global_results = [r for r in global_results if r.get("level", 2) != 2] # ✅ Filters L2 docs = [str(r.get("abstract", "")) for r in global_results] Call 2 (_recursive_search, line 479) — does NOT filter L2:
Copy documents = [str(r.get("abstract", "")) for r in results] # ❌ Includes L2 Additionally, L2 abstracts have no size limit. In memory_updater.py:1072:
Copy abstract = LinkRenderer.strip_all_links(mf.content or "") # Full file content, no truncation The _enforce_size_limits() in semantic_processor.py only applies to directory-level abstracts (L0/L1), not file-level abstracts (L2).
After reviewing the intent of original design. It appears that L2 is indeed supposed to be reranked. Leaving L2 out might not be the best choice.
Maybe set a upper limit of L2 token sent to reranker.
For example, in QMD's reranking system, the length is controlled by an environmental variable QMD_RERANK_CONTEXT_SIZE = 4096 (default)
there are two benefits a). avoid exceeding buffer size of reranker model b). allows control the tokens sent to reranker model which helps to speed up local model esp. in auto-recall.
Thanks for reporting this.
Could you provide the concrete failure case details?
- The rerank provider/model you were using.
- The oversized L2 URI/path(s) that triggered the failure.
- If possible, the corresponding file(s), or a sanitized/minimal sample file that reproduces the issue.
If the files contain sensitive content, the URI/path and approximate size are enough.
local reranker model qwen3-reranker-0.6B run on lemonade server. set batch size 4096. since I use auto-recall, I need reliable and fast responses.
I am not a programmer, can't go through log myself. hence asked AI to do it, take it as it is
That's the data right there. 280 reranker failures since yesterday — all "input too large for batch size (current: 4096)". Here's the # of requests vs. token size distribution: Token Size Failed Requests 4000–4249 43 4250–4499 55 4500–4999 48 5000–5499 78 ← peak 5500–5999 16 6000–6499 10 6500+ 30 (up to 10,108 tokens!) Total 280 The largest request that got rejected was 10,108 tokens at 08:23 today (8881 was also from this session).
The 10,108 token one from yesterday searched these L2 paths: viking://user/claw/memories/events/2026/06/15 viking://resources viking://user/claw/memories viking://user/claw/peers/gary/memories Those are from the hierarchical retriever's recursive search — it collected abstracts from across all those trees and packed them into a single rerank request that blew past 4096.
The 8,881 token one from today (08:23) was from our own session — that was the memory_search calls I made earlier when looking up the reranking stats for you. It searched viking://resources, viking://user/claw/peers/sys/memories, viking://user/claw/memories/events, etc.
Search query: "statistic run size range requests reranking model" — this was one of the memory_search calls I made during our conversation.
Where it searched (from RecursiveSearch logs):
viking://resources viking://user/claw/peers/sys/memories viking://user/claw/peers/sys/resources viking://user/claw/resources viking://user/claw/skills viking://user/claw/memories viking://user/claw/memories/events viking://user/claw/memories/preferences The real problem: The L2 abstracts are massive. Let me show you the offenders:
Abstract Tokens URI 3,892 🔴 openviking.md 3,845 🔴 multimodal_embedding_options_research.md 3,592 🔴 copx_projection_saved.md 2,901 🔴 lemonade_server.md 2,879 memory_backend_comparison.md 2,803 nymo_accuracy_verification.md (×2 chunks) 2,297 ov_compaction_architecture_research.md 2,032 ov_llm_routing_investigation.md The L0 abstracts are supposed to be ~100 tokens but 16 out of 50 items have abstracts >1000 tokens, and 4 are >3000. Each of those giant abstracts is a full embedded document, not a summary.
So 10-15 of these abstract-heavy items in one search batch = instant 8881 token overflow past the 4096 batch size. Every time.
========================================================== The AI also looked through source code, and it says there is no limit on size of L2 generated.
Confirmed on current origin/main (5f8547a4): this is still open. _recursive_search() in openviking/retrieve/hierarchical_retriever.py still sends raw candidate abstracts into rerank, and L2 abstracts can be much larger than a reranker window.
I would not merge the old “drop all L2 from rerank” approach from #2741 as-is; it likely hurts L2 recall quality. Better direction: keep L2 eligible, but enforce a rerank input budget in the centralized rerank-document builder, trim/skip oversized entries, and preserve vector fallback for skipped docs so one bad doc does not fail the whole batch.
Marked needs:architecture because this is a retrieval-quality policy choice, not just a one-line bugfix.
Maybe borrow some idea from QMD I believe QMD divides intake document into chunks of fixed size at the stage of indexing. in search, it retrieves the matching chunks and only sends the matching chunks to reranker instead of sending the entire document to reranker. This way, no fidelity is lost. It is better than truncating document for reranking.
Current-main re-check shows that the bounded fix requested here landed in #3289 (merge commit 19ca274a).
- L2 candidates remain eligible for reranking.
rerank.max_input_tokensnow bounds each query-document pair when set to a positive value; oversized inputs retain both the head and tail.- The default remains
0(no implicit truncation), following maintainer review, so deployments with a 4096-token local reranker should set an appropriate positive budget. - English and Chinese configuration docs, plus oversized English and Chinese regression tests, landed with the fix.
This issue remained open because #3289 closed #3005 but did not link #2739. I recommend closing #2739 as resolved by #3289. If the failure remains after configuring a positive budget, please reopen or file a focused follow-up with the configured budget and provider/model evidence.