ARM ONLY, NEVER MERGE: retrieval score first, RRF rank second
Merge-and-sort discards rank, so where raw scores tie exactly it falls back to lancedb.databases declaration order. Rank and score are independent discriminators, not the same information at different resolution: a single-branch rank-0 candidate and a rank-2 candidate with two both-branch candidates above it can carry the same score. So keep score primary, which is what buys merge-and-sort its recall, and resolve score ties by within-database position instead of by YAML order. That prefers the candidate nothing in its own collection beat, which is signal. Measures whether merge-and-sort's order sensitivity at n=4 (1.49pp against the tie-break's 0.56pp) is reducible without moving to continuous scores. Claude-Session: https://claude.ai/code/session_01WhudUtZm6qqiuv8Y1sbwSc
This commit is contained in:
parent
33bd0be702
commit
5de04b0108
1 changed files with 9 additions and 4 deletions
|
|
@ -193,10 +193,15 @@ async def _fuse(
|
|||
|
||||
scored: list[tuple[float, HaikuRAG, Chunk]] = []
|
||||
for client, candidates in zip(clients, per_source, strict=True):
|
||||
for rank, (chunk, _) in enumerate(candidates):
|
||||
scored.append((1.0 / (_RRF_K + rank + 1), client, chunk))
|
||||
scored.sort(key=lambda item: item[0], reverse=True)
|
||||
return [(client, chunk, score) for score, client, chunk in scored[:limit]]
|
||||
for rank, (chunk, score) in enumerate(candidates):
|
||||
scored.append((1.0 / (_RRF_K + rank + 1), score, client, chunk))
|
||||
# ARM ONLY, NEVER MERGE: retrieval score primary, RRF rank secondary. Keeps
|
||||
# merge-and-sort's content-driven allocation while resolving score ties by
|
||||
# within-database position instead of declaration order. Rank and score are
|
||||
# independent discriminators: a single-branch rank-0 candidate and a rank-2
|
||||
# candidate with two both-branch candidates above it can carry the same score.
|
||||
scored.sort(key=lambda item: (item[1], item[0]), reverse=True)
|
||||
return [(client, chunk, fused) for fused, _, client, chunk in scored[:limit]]
|
||||
|
||||
|
||||
# Reciprocal rank fusion's smoothing constant, the value the literature uses.
|
||||
|
|
|
|||
Loading…
Reference in a new issue