From 387faf21e345fe969b635a12d10afcc2e39d8999 Mon Sep 17 00:00:00 2001 From: Alan Scherger Date: Mon, 19 Oct 2026 09:05:50 -0500 Subject: [PATCH] feat: Strengthen the same-file saturation decay Each extra chunk from an already-listed file was scaled by 0.5, so a strong second chunk of the top file still pushed other files out of the top 10. That hurts queries whose answer spans several files. Lower _FILE_SATURATION_DECAY to 0.25. --- src/semble/ranking/penalties.py | 2 +- tests/test_ranking.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/semble/ranking/penalties.py b/src/semble/ranking/penalties.py index c26c63fe..d9add8c5 100644 --- a/src/semble/ranking/penalties.py +++ b/src/semble/ranking/penalties.py @@ -76,7 +76,7 @@ _FILE_SATURATION_THRESHOLD = 1 # Multiplicative penalty per extra chunk from the same file beyond the threshold. -_FILE_SATURATION_DECAY = 0.5 +_FILE_SATURATION_DECAY = 0.25 def rerank_topk( diff --git a/tests/test_ranking.py b/tests/test_ranking.py index 8407a355..02ad0b4a 100644 --- a/tests/test_ranking.py +++ b/tests/test_ranking.py @@ -20,6 +20,15 @@ def test_rerank_topk() -> None: assert scores == sorted(scores, reverse=True) +def test_rerank_topk_prefers_another_file_over_a_second_chunk() -> None: + """A strong second chunk from an already-listed file ranks below a weaker chunk from a new file.""" + first = make_chunk("def parse(): ...", "src/parser.py") + second = make_chunk("def parse_all(): ...", "src/parser.py") + other = make_chunk("def load(): ...", "src/loader.py") + ranked = rerank_topk({first: 1.0, second: 0.9, other: 0.4}, top_k=3) + assert [chunk for chunk, _ in ranked] == [first, other, second] + + @pytest.mark.parametrize( "penalised_path", [