Skip to main content

prune_top_k

Function prune_top_k 

Source
pub fn prune_top_k(v: &SparseVector, k: usize) -> SparseVector
Expand description

Keep only the k terms with the largest absolute weight, preserving the ascending-index invariant. This is the universal query-side latency lever for learned-sparse retrieval — high-DF / low-weight query terms dominate the posting-scan cost, so dropping them trades a little recall for large speedups.

Returns the input unchanged when k >= len. Ties are broken by keeping the lower term id (deterministic).