feat(consume): fuse concept signals by RRF with declared tie-breaks
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
0550870ae2
commit
f4b1f4ef0b
2 changed files with 120 additions and 0 deletions
|
|
@ -380,3 +380,61 @@ def test_document_scores_are_identical_across_two_calls() -> None:
|
|||
assert okf_consume.document_scores(FIXTURE, question) == okf_consume.document_scores(
|
||||
FIXTURE, question
|
||||
)
|
||||
|
||||
|
||||
# --- Step 6: stage-two concept ranking, fused by RRF --------------------------
|
||||
|
||||
|
||||
def _fixture_concepts() -> list[okf_consume.Concept]:
|
||||
return [
|
||||
okf_consume.read_concept(
|
||||
FIXTURE / f"{concept_id}.md",
|
||||
bundle_root=FIXTURE,
|
||||
root_bundle_id="consume-fixture",
|
||||
)
|
||||
for concept_id in okf_consume.enumerate_concepts(FIXTURE)
|
||||
]
|
||||
|
||||
|
||||
def test_concepts_tying_on_every_signal_come_back_in_concept_id_order() -> None:
|
||||
concepts = _fixture_concepts()
|
||||
# A question matching nothing makes every signal identical, so the ONLY
|
||||
# thing left deciding the order is the declared tie-break.
|
||||
ranked = okf_consume.concept_scores(concepts, "zzzz qqqq", {})
|
||||
ids = [concept.concept_id for concept, _ in ranked]
|
||||
assert ids == sorted(ids)
|
||||
|
||||
|
||||
def test_reversing_the_input_order_does_not_change_the_output_order() -> None:
|
||||
concepts = _fixture_concepts()
|
||||
forward = [c.concept_id for c, _ in okf_consume.concept_scores(concepts, "zzzz qqqq", {})]
|
||||
backward = [
|
||||
c.concept_id
|
||||
for c, _ in okf_consume.concept_scores(list(reversed(concepts)), "zzzz qqqq", {})
|
||||
]
|
||||
assert forward == backward
|
||||
|
||||
|
||||
def test_a_concept_in_a_high_scoring_document_outranks_an_equally_lexical_one() -> None:
|
||||
concepts = _fixture_concepts()
|
||||
question = "Hvordan skal prisene fylles ut?"
|
||||
lifted = okf_consume.concept_scores(concepts, question, {"krav": 10.0, "dyp": 0.0})
|
||||
dropped = okf_consume.concept_scores(concepts, question, {"krav": 0.0, "dyp": 10.0})
|
||||
krav_first = [c.concept_id for c, _ in lifted].index("krav/prissammenstilling")
|
||||
krav_later = [c.concept_id for c, _ in dropped].index("krav/prissammenstilling")
|
||||
assert krav_first < krav_later
|
||||
|
||||
|
||||
def test_the_ranked_order_is_identical_across_two_calls() -> None:
|
||||
concepts = _fixture_concepts()
|
||||
scores = okf_consume.document_scores(FIXTURE, "Hvordan skal prisene fylles ut?")
|
||||
first = okf_consume.concept_scores(concepts, "Hvordan skal prisene fylles ut?", scores)
|
||||
second = okf_consume.concept_scores(concepts, "Hvordan skal prisene fylles ut?", scores)
|
||||
assert [c.concept_id for c, _ in first] == [c.concept_id for c, _ in second]
|
||||
|
||||
|
||||
def test_the_price_concept_leads_on_the_price_question_in_the_fixture() -> None:
|
||||
concepts = _fixture_concepts()
|
||||
scores = okf_consume.document_scores(FIXTURE, "Hvordan skal prisene fylles ut?")
|
||||
ranked = okf_consume.concept_scores(concepts, "Hvordan skal prisene fylles ut?", scores)
|
||||
assert ranked[0][0].concept_id == "krav/prissammenstilling"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue