Heuristic:24kchengYe MemoMind Cross Encoder Candidate Limit
| Knowledge Sources | |
|---|---|
| Domains | Retrieval, Performance |
| Last Updated | 2026-10-28 14:45 GMT |
Overview
Cap the number of candidates fed to the cross-encoder reranker at 300 (default) to bound inference latency and prevent CPU thrashing.
Description
After RRF merges the 4-way retrieval results, the merged candidate list can be large (hundreds to thousands of items). Cross-encoder inference is O(n) model forward passes — feeding too many candidates causes high latency and CPU thrashing. The `HINDSIGHT_API_RERANKER_MAX_CANDIDATES` setting (default: 300) truncates the RRF-merged list to the top-N before reranking. Candidates beyond this limit are pre-filtered by RRF score. After reranking, results are further truncated to `thinking_budget * 2` for token filtering.
Usage
Use this heuristic when optimizing recall latency — if reranking is too slow (especially with local CPU models), reduce `RERANKER_MAX_CANDIDATES`. If too many relevant results are being cut before reranking, increase it (at the cost of latency).
The Insight (Rule of Thumb)
- Action: Set `HINDSIGHT_API_RERANKER_MAX_CANDIDATES=300` to cap reranker input size.
- Value: 300 candidates (default). Pre-filtered by RRF score before reranking.
- Trade-off: Lower = faster reranking but may miss relevant results that ranked low in RRF. Higher = better recall but linearly slower reranking (ms-marco-MiniLM-L-6-v2: ~80ms/100 pairs on CPU → ~240ms for 300 candidates).
- Compatibility: Also limited by `RERANKER_LOCAL_MAX_CONCURRENT=4` (prevents CPU thrashing from parallel rerank calls).
Reasoning
Cross-encoder inference time scales linearly with candidate count. With the default local model (ms-marco-MiniLM-L-6-v2), each query-document pair takes ~0.8ms on CPU, so 300 candidates ≈ 240ms. RRF already provides a strong pre-ranking — candidates beyond rank 300 are very unlikely to be relevant. The subsequent `thinking_budget * 2` truncation (default: 300 * 2 = 600, but typically 300 after reranking) further reduces the set for token budget filtering. This two-stage truncation (RRF → max_candidates → rerank → thinking_budget*2 → token budget) keeps the pipeline fast without sacrificing recall.
Code Evidence
Default candidate limit from `config.py:394`:
DEFAULT_RERANKER_MAX_CANDIDATES = 300
Candidate pre-filtering from `memory_engine.py:2931-2936`:
reranker_max_candidates = get_config().reranker_max_candidates
if len(merged_candidates) > reranker_max_candidates:
pre_filtered_count = len(merged_candidates) - reranker_max_candidates
merged_candidates = merged_candidates[:reranker_max_candidates]
Post-rerank truncation from `memory_engine.py:2973-2975`:
# Step 5: Truncate to thinking_budget * 2 for token filtering
rerank_limit = thinking_budget * 2
top_scored = scored_results[:rerank_limit]