feat(consume): BM25 ranking by passage and title, a large concept delivered as its passage
C1. `okf consume` and MCP's `okf_ask` now rank with BM25 (`bm25.py`) instead
of the three-signal fusion. Two signals, fused by reciprocal rank:
- passage: every body cut into 500-character windows every 250, a concept
scored by its BEST window -- a narrow question is answered in one place;
- field: title three times, the id path and source name twice, then the body
-- a broad question is answered by what a section is called.
The document prior and the rarity weight are gone from the default: the first
favoured big documents full of common words, the second gave its largest
weight to a word the collection does not hold. Under BM25 such a word weighs
exactly zero. A signal that scores a concept zero adds nothing to it, and ties
share a rank, so alphabetical order lifts nothing either.
Three rules carried over from the fusion, each with its own test, because the
suite showed what BM25 alone lost:
- a directory every concept shares is not read (K3-20's defect, one signal on);
- a number a section is known by (`4.2`, `10.2-2`) is kept as one token, or
a question naming a section by its number matches nothing in it;
- a question word the collection does NOT hold is read as the collection's
words it shares a leading word with (`consume.tokens_match`) -- Norwegian
inflection and compounding -- at that word's idf, never at its own.
The lookup and title-covered partitions are shared with the fusion
(`_partitioned`). `ranking="fusion"` / `--ranking fusion` keeps the old order
reachable; `--cost-vocabulary` and `--rarity-weight` widen only the fusion and
are refused with the default (`ranking_flag_conflict`) rather than ignored.
C3. A concept longer than `PASSAGE_CHARS` (4 000) is delivered as the span
around its best window, snapped to whole lines, under the nearest heading
above it, with `[...]` where text was left out. `passage: {start, end, of}`
says so, `text_sha256` covers what was delivered, and `sha256` stays the
file's, so the whole can be fetched by `concept_id`. 4 000 because eight
excerpts of it stay far under a tool response's limit even with several
sub-questions merged, while a 500-character window keeps 3 500 characters of
surroundings. The budget pays for the passage, not the file.
Tests moved with the default, each stated rather than silenced:
- fusion-mechanism tests (cost vocabulary, rarity weight, reservation, shared
rank, the reference-bundle pins) ask for `ranking="fusion"`, the order they
were measured on; the BM25 reading of the reference bundle is a separate
measurement, kept in local state;
- the retrieval gate still measures the shipped default. Row 1 holds. Four of
its premises were built against the fusion (a concept forced below k that
BM25 now delivers, a quota that no longer decides, mutants patching fusion
code) and are `xfail(strict=True)` until the fixtures are re-measured;
- the shipped example payload is regenerated; the shipped skill is unchanged.
README's Consume section and CLAUDE.md state the new default and that the
flags described after it belong to the fusion.
The search gate's table for this commit is kept in local state: the question
sets belong to a consumer whose content does not go on a public mirror.
Suite on a clean tree after `git add`: 2390 passed, 2 skipped, 4 xfailed.
ruff, ruff format, mypy --strict clean.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
cf21449ddb
commit
735468f600
11 changed files with 988 additions and 118 deletions
|
|
@ -1,5 +1,10 @@
|
|||
"""The bundle the DEFAULT build produces, pinned where a regression goes red.
|
||||
|
||||
READ WITH THE FUSION RANKING since v1.1: these ranks were measured on the
|
||||
three-signal fusion, which `okf consume` no longer uses by default. The
|
||||
default BM25 reading of these bytes is a separate measurement and is not
|
||||
pinned here.
|
||||
|
||||
`tests/test_okf_consume.py` pinned hit@8 against the Arm B bundle alone -- the
|
||||
configuration `okf build` stopped emitting on 2026-09-08. A published number
|
||||
measured on a bundle nobody produces is a number that cannot regress, so the
|
||||
|
|
@ -120,7 +125,9 @@ def test_hit_at_eight_holds_rank_one_on_every_row_it_held() -> None:
|
|||
assert len(questions) == len(EXPECTED_RANKS), "the gold set changed shape"
|
||||
ranks = []
|
||||
for entry in questions:
|
||||
payload = okf_consume.build_payload(DEFAULT_BUNDLE, question=entry["question"])
|
||||
payload = okf_consume.build_payload(
|
||||
DEFAULT_BUNDLE, question=entry["question"], ranking="fusion"
|
||||
)
|
||||
excerpts = payload["excerpts"]
|
||||
assert isinstance(excerpts, list)
|
||||
ranks.append(okf_consume_measure.hit_rank(excerpts, entry["gold_document"]))
|
||||
|
|
@ -153,7 +160,7 @@ def test_the_reading_default_is_what_holds_row_one_on_these_bytes() -> None:
|
|||
ranks = []
|
||||
for entry in questions:
|
||||
payload = okf_consume.build_payload(
|
||||
DEFAULT_BUNDLE, question=entry["question"], tie_shared_rank=False
|
||||
DEFAULT_BUNDLE, question=entry["question"], ranking="fusion", tie_shared_rank=False
|
||||
)
|
||||
excerpts = payload["excerpts"]
|
||||
assert isinstance(excerpts, list)
|
||||
|
|
@ -185,7 +192,9 @@ def test_the_stem_rule_holds_every_rank_on_the_shipped_bytes() -> None:
|
|||
questions = json.loads(GOLD_SET.read_text(encoding="utf-8"))["questions"]
|
||||
ranks = []
|
||||
for entry in questions:
|
||||
payload = okf_consume.build_payload(DEFAULT_BUNDLE, question=entry["question"])
|
||||
payload = okf_consume.build_payload(
|
||||
DEFAULT_BUNDLE, question=entry["question"], ranking="fusion"
|
||||
)
|
||||
excerpts = payload["excerpts"]
|
||||
assert isinstance(excerpts, list)
|
||||
ranks.append(okf_consume_measure.hit_rank(excerpts, entry["gold_document"]))
|
||||
|
|
@ -209,7 +218,7 @@ def test_the_document_quota_is_what_reaches_row_six_on_these_bytes() -> None:
|
|||
ranks = []
|
||||
for entry in questions:
|
||||
payload = okf_consume.build_payload(
|
||||
DEFAULT_BUNDLE, question=entry["question"], source_quota=None
|
||||
DEFAULT_BUNDLE, question=entry["question"], ranking="fusion", source_quota=None
|
||||
)
|
||||
excerpts = payload["excerpts"]
|
||||
assert isinstance(excerpts, list)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue