retrieval.consolidation¶
Merges per-retriever SearchHit rankings into a single deduplicated,
explainable ranking — a starting ranking a following conversation/agent
verifies and explores from. Confidence and score reflect cross-retriever
agreement on query-text match, not currency or authority — a "high" hit can
still point at legacy or deprecated code, and consumers must verify each
span against the live source before relying on it.
Consolidate per-retriever SearchHit rankings into a single, deduplicated,
explainable ranking — a starting ranking a following conversation/agent
verifies and explores from.
Pure stdlib. Given {retriever_name: [SearchHit, ...]} (one ranked list per
retriever already run against the same query), consolidate merges hits
whose spans overlap (or are line-adjacent) into a single canonical
ConsolidatedHit, fuses each group's per-retriever ranks with a (optionally
weighted) Reciprocal Rank Fusion, and returns the fused list sorted best
first — with provenance (which retrievers found it), agreement (how many),
and a confidence label baked in so the handoff is self-explanatory without
re-deriving any of this from the raw per-retriever output. Confidence and
score reflect cross-retriever agreement on query-text match, not currency or
authority — a "high" hit can still point at legacy or deprecated code, and
consumers must verify each span against the live source before relying on it.
ConsolidatedHit
dataclass
¶
One deduplicated, ranked, explainable result in the consolidated list.
Source code in engine/retrieval/consolidation.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
consolidate(per_retriever_hits, *, k=60, weights=None, merge_adjacent=True)
¶
Merge, fuse, and rank per-retriever SearchHit lists into a single
deduplicated, explainable ConsolidatedHit list.
Parameters¶
per_retriever_hits :
{retriever_name: [SearchHit, ...]}, one ranked list per retriever
already run against the same query. Retrievers may be a subset of
the six strategies (graceful skip) and may be supplied in any dict
order — iteration is always in fixed canonical order internally, so
the result is reproducible regardless of input dict order.
k :
RRF damping constant, forwarded to reciprocal_rank_fusion.
weights :
Optional {retriever_name: weight}; retrievers absent from this
mapping default to weight 1.0.
merge_adjacent :
When True (default), same-path spans whose end/start lines are
exactly adjacent (end + 1 == start) are merged into one group in
addition to spans that overlap.
Returns¶
ConsolidatedHit list sorted by fused score descending (ties broken by
source_path, start_line, end_line, docid), with rank
assigned 1-based over that final order.
Source code in engine/retrieval/consolidation.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |