Skip to main content

rerank_topk

Function rerank_topk 

Source
pub fn rerank_topk(
    scores: &[(usize, f32)],
    chunks: &[CodeChunk],
    top_k: usize,
    penalise_paths: bool,
) -> Vec<(usize, f32)>
Expand description

Select the top-k results with optional path penalties and file-saturation decay.

Mirrors rerank_topk from penalties.py:81. The greedy pass uses the early-exit optimisation: once selected.len() >= top_k and the remaining candidate’s penalised score cannot beat the current k-th best, the loop terminates.

  • penalise_paths == true — apply file_path_penalty before sorting and selection. This matches semble’s behaviour for hybrid and BM25-led queries.
  • penalise_paths == false — bypass path priors (pure-semantic queries where the priors don’t apply).

Returns (chunk_index, effective_score) pairs, highest first, with length capped at top_k.