[Bug] _recursive_search sends L2 file abstracts to reranker instead of filtering to L0/L1 only
Bug Description
In hierarchical_retriever.py, the _merge_starting_points method correctly filters out L2 content before reranking (line 312: global_results = [r for r in global_results if r.get("level", 2) != 2]). However, the _recursive_search method at line 480-482 does not apply the same filter:
# line 480-482 in _recursive_search
documents = [str(r.get("abstract", "")) for r in results]
query_scores = self._rerank_scores(query, documents, query_scores)
This means L2 file abstracts (full file summaries) are sent directly to the reranker alongside L0/L1 abstracts, bypassing the level filter that exists in _merge_starting_points.
Impact
L2 file abstracts can be very large. The abstract scalar field for L2 files is truncated at 50,000 bytes (_ABSTRACT_MAX_BYTES in embedding_utils.py), while L0 .abstract.md is capped at 256 chars (abstract_max_chars in config). This means L2 abstracts sent to the reranker can be 200x larger than the L0/L1 abstracts the reranker was designed for.
When using a local reranker (e.g., jina-reranker-v3 via llama-server with ctx-size=2560), these oversized L2 abstracts:
- Get silently skipped by the reranker wrapper (exceed context limit)
- Cause the reranker to return fewer results than requested
- Trigger
Invalid rerank result, fallback to vector scoreswarnings - Degrade retrieval quality as the reranker falls back to raw vector scores
In a production deployment with ~1,365 memory files, we observed:
- 924 warnings per day from
Invalid rerank result, fallback to vector scores - 440
Unexpected rerank result lengthwarnings per day - ~40% of search queries degraded to vector-score-only retrieval
Steps to Reproduce
- Deploy OpenViking with a local reranker (e.g., jina-reranker-v3 with ctx-size=2560)
- Have memory files with large summaries (>2560 tokens per file abstract)
- Trigger a search that hits
_recursive_search - Observe reranker warnings in logs and result count mismatches
Expected Behavior
_recursive_search should filter L2 content before sending to the reranker, consistent with the existing filter in _merge_starting_points. This could be as simple as:
# Only rerank L0/L1 candidates
rerank_candidates = [(i, str(r.get("abstract", ""))) for i, r in enumerate(results) if r.get("level", 2) != 2]
if rerank_candidates:
indices, documents = zip(*rerank_candidates)
rerank_scores = self._rerank_scores(query, list(documents), ...)
# map scores back to original positions
Actual Behavior
All results (including L2) are sent to the reranker without filtering.
Environment
- OpenViking: latest from PyPI (installed 2026-07-02)
- Reranker: jina-reranker-v3 Q6_K GGUF via llama-server, ctx-size=2560
- Embedding: Qwen3-Embedding-4B Q6_K GGUF, local
- Storage: Local VikingFS
- Memory files: ~1,365 (mix of experiences, trajectories, events, skills)
Thanks for reporting this and for providing the detailed production observations.
L2 results still need to be reranked. The purpose of reranking is precisely to compensate for vector scores not fully representing the semantic relevance between the query and the content. Keeping all L2 results on vector scores would weaken the ranking quality of terminal file results in thinking mode.
The L2 filtering in _merge_starting_points only prevents files from being used as recursive entry points; it does not mean that L2 results should be excluded from reranking.
Oversized inputs or inconsistent result counts should be handled at the reranker boundary rather than by disabling reranking for L2 results. Therefore, we will not adopt the proposed behavior and are closing this issue. Thanks again for the detailed report.