From a19f2c96b1339cea5124498cdc19a5b016744946 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Mon, 31 Aug 2026 13:47:04 +0300 Subject: [PATCH] ARM ONLY, NEVER MERGE: sort the fused union by retrieval score Replaces the rank-interleaved fusion with a straight merge of the union sorted by each candidate's raw retrieval score, ties still falling to declaration order, cut at limit. This is the depth-quota candidate: within one database rank order and raw-score order coincide, so the whole difference from the tie-break fix is the cross-database interleaving. This branch exists to be measured and discarded. The rank-dominance tests in tests/multi_db/test_search.py pin the behaviour this deliberately inverts, so the root suite FAILS here by design. If the arm wins, the shipping implementation belongs to the session that owns client/search.py, with its own tests. Claude-Session: https://claude.ai/code/session_01WhudUtZm6qqiuv8Y1sbwSc --- haiku_rag_slim/haiku/rag/client/search.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/haiku_rag_slim/haiku/rag/client/search.py b/haiku_rag_slim/haiku/rag/client/search.py index 9c3441a6..4a5dcfe2 100644 --- a/haiku_rag_slim/haiku/rag/client/search.py +++ b/haiku_rag_slim/haiku/rag/client/search.py @@ -193,10 +193,13 @@ 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: merge the union and sort by the raw retrieval + # score, discarding the rank interleaving entirely. Measures whether the + # depth quota costs more than it buys. + scored.sort(key=lambda item: (item[1],), reverse=True) + return [(client, chunk, fused) for fused, _, client, chunk in scored[:limit]] # Reciprocal rank fusion's smoothing constant, the value the literature uses.