[Feature]: Configurable rerank batch limits (max_docs + max_chars_per_doc) for latency-sensitive recall
Problem Statement
When auto-recall is used with reranker enabled, the hierarchical retriever sends all collected candidates to the reranker with no upper bound on document count or document size. In practice:
Recursive search can collect tens to hundreds of candidates L2 (full file content) abstracts can be 1,000–5,000+ chars each (even after the recent L2 exclusion fix in #2741, L0/L1 abstracts still vary widely) Total rerank input can easily exceed the model's batch size limit (e.g. 512 tokens), causing the entire rerank batch to fail and fall back to vector scores Even when it doesn't fail, reranking a large batch is slow — unacceptable for auto-recall where latency matters more than perfect ranking The current all-or-nothing approach means users must choose between:
Rerank off → fast but dramatically lower recall quality Rerank on → potentially slow or silently falling back to vector scores when batch limits are exceeded
Proposed Solution
Add two optional configuration parameters under the rerank section of ov.conf:
Copy { "rerank": { "provider": "vikingdb", "ak": "...", "sk": "...", "model_name": "doubao-seed-rerank", "threshold": 0.1, "max_docs": 20, // NEW: max documents sent to reranker per batch "max_chars_per_doc": 500 // NEW: truncate each document's abstract to N chars before reranking } } rerank.max_docs (default: 0 = unlimited, current behavior)
Caps the number of documents submitted to the reranker in a single rerank_batch call When the collected candidate count exceeds this limit, only the top-N by vector score are sent to the reranker The remaining candidates keep their vector fallback scores rerank.max_chars_per_doc (default: 0 = no truncation, current behavior)
Truncates each document's abstract text to N characters before sending to the reranker Prevents oversized L0/L1 abstracts from causing batch failures The truncated text is only used for reranking; the full abstract is still returned in results
Alternatives Considered
Relying on score_threshold alone — doesn't limit reranker input size, only filters output. A low threshold still sends everything. Using level=[0,1] on every API call — works but requires API-level changes and doesn't cap the total count. Also not configurable in ov.conf. Modifying GLOBAL_SEARCH_TOPK in source code — not configurable, requires fork, and only indirectly limits candidates. Client-side truncation — each integration (OpenClaw plugin, SDK users) would need to implement their own limiting, leading to inconsistent behavior.
Feature Area
Retrieval/Search
Use Case
Auto-recall in AI agents (e.g. OpenClaw): When an agent calls memory_recall or search() with reranker enabled, the response must be fast (sub-second) to maintain interactive feel. Perfect rerank accuracy is not needed — the top 10–20 candidates with rerank scoring is far better than pure vector scores, but sending 100+ documents to the reranker adds unacceptable latency. With max_docs: 20 and max_chars_per_doc: 500, the reranker processes a bounded, predictable payload every time, trading marginal accuracy for consistent low latency.
Example API (Optional)
# Config-driven: no code changes needed
config = {
"rerank": {
"provider": "vikingdb",
"ak": "...",
"sk": "...",
"max_docs": 20,
"max_chars_per_doc": 500
}
}
# In hierarchical_retriever.py, _rerank_scores would:
# 1. Truncate each document to max_chars_per_doc chars
# 2. If len(documents) > max_docs, take only top-N by vector score
# 3. Rerank the bounded batch
# 4. Scatter scores back to original indices (unranked docs keep vector scores)
Additional Context
This is related to the existing issue #2739 (L2 abstracts exceeding batch size) and its fix #2741. The proposed solution is more general — it addresses the root cause (unbounded rerank input) rather than just one specific case (L2 content). It also gives users a predictable latency budget for reranking in latency-sensitive paths like auto-recall.
Contribution
- [ ] I am willing to contribute to implementing this feature
This is a latency-accuracy trade-off control for reranking, and it addresses a real operational constraint. OpenViking's hierarchical retriever + reranker is powerful but currently all-or-nothing: rerank everything collected (slow, sometimes fails) or rerank nothing (fast but low recall quality). In latency-sensitive paths like auto-recall for agents, you need the middle ground: rerank a bounded batch (top-N by vector score) and accept that marginal candidates keep their vector fallback scores.
Why this matters for agent memory
Auto-recall in AI agents (like OpenClaw's memory_recall) must be sub-second to maintain interactive feel. Perfect rerank accuracy isn't needed — the top 10–20 candidates with rerank scoring is far better than pure vector scores, but sending 100+ documents to the reranker adds unacceptable latency. Worse, if recursive search collects hundreds of candidates and L0/L1 abstracts are large, the entire rerank batch can exceed the model's token limit (e.g., 512 tokens for some rerankers), causing silent fallback to vector scores — defeating the purpose of enabling reranker in the first place.
The current workaround — using score_threshold alone — doesn't limit reranker input size, only filters output. A low threshold still sends everything. Using level=[0,1] on every API call works but doesn't cap total count and isn't configurable in ov.conf. Modifying GLOBAL_SEARCH_TOPK in source code requires a fork and only indirectly limits candidates.
How SwarmAI handles this (T-MEM: Memory is the Moat)
Our memory recall pipeline uses a staged rerank budget:
- Vector retrieval pulls top-500 candidates (cheap, fast)
- Coarse rerank (embeddings-based semantic similarity) narrows to top-50 (still cheap)
- Fine rerank (LLM reranker) takes top-20 from coarse (expensive, high latency)
Each stage has a fixed budget (max_docs). The final output is 20 precisely-ranked candidates in <1s. Marginal candidates (rank 21–50) keep their coarse-rerank scores; we accept the accuracy loss in exchange for predictable latency.
The key insight: reranking everything is overkill. The top-N by vector score are already 90% of the relevant set — you're reranking to refine the order, not to discover new candidates. A bounded batch (e.g., max_docs: 20) gives you the refinement benefit without unbounded latency.
Proposed config (from issue)
{
"rerank": {
"provider": "vikingdb",
"max_docs": 20, // Max documents sent to reranker per batch
"max_chars_per_doc": 500 // Truncate each abstract before reranking
}
}
Implementation sketch:
- In
hierarchical_retriever.py, before calling_rerank_scores:- Truncate each document's abstract to
max_chars_per_docchars (rerank-only; full abstract still returned) - If
len(documents) > max_docs, take only top-N by vector score - Rerank the bounded batch
- Scatter scores back to original indices (unranked docs keep vector scores)
- Truncate each document's abstract to
Benefits
- Predictable latency — rerank batch size is capped, so latency is bounded
- No silent failures — small batches stay within model token limits
- Better than vector-only — top-N reranked is far better than no reranking
- Configurable trade-off — users tune
max_docsbased on their latency budget - Backward compatible — default
max_docs: 0= unlimited (current behavior)
Related work
This is the same principle as cascade reranking in production search systems (Google, Bing). Stage 1 (vector) retrieves 1000s, Stage 2 (lightweight rerank) narrows to 100s, Stage 3 (heavyweight LLM rerank) refines top-20. Each stage has a budget. It's not about accuracy — it's about latency discipline.
Staged rerank budgets are a T-MEM pattern from SwarmAI. Discussion: T-MEM: Memory is the Moat
currently OV sends L2 abstract which can be very long (no length limit, in practice can be 8k to 15k tokens) to reranker. In my system, using local reranker (qwen3-reranker-0.6B) in Ryzen 395, takes 1-2 minutes to finish if set reranker batch size to 8k (which means ignore doc > 8k). at larger batch size, the speed of reranker also takes a dive. currently, I limit the reranker batch size to 4k, auto-recall can still take 25-45 seconds to complete. additionally as of 2026.6.18 version of openclaw plugin, the auto-recall timeout is still hard-coded at 5 secs. which means reranker would always timeout. I patched the code to remove this limit.