Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions experiments/35-full-rag-benchmark-2026-11-01/answers35.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ def measure(ctx: stages35.Ctx, rows: Sequence[Mapping[str, Any]]) -> dict[str, i


class _SplitLog:
"""The answer row file; a row's ``retrieval`` part goes to ``retrieval.jsonl`` first."""
"""The answer row file; a row's ``retrieval`` part goes to ``retrieval.jsonl`` first.

A question whose search worked but whose answer call failed keeps its search line in
``answer.searches.jsonl`` (one synced line, written before the error is recorded). A
closed-missing row has no ``retrieval`` part, so it takes that saved line instead
(section 12: a missing answer scores 0; section 15: only a failed search is incomplete).
"""

def __init__(self, log: outputs35.RowFile) -> None:
self._log = log
Expand All @@ -228,6 +234,14 @@ def __init__(self, log: outputs35.RowFile) -> None:
tmp.parent.mkdir(parents=True, exist_ok=True)
tmp.write_text("".join(json.dumps(r, ensure_ascii=False) + "\n" for r in keep), "utf-8")
tmp.replace(self._extra)
self._searches_path = self._extra.with_name("answer.searches.jsonl")
self._searches = {str(r["qid"]): r for r in read_lines(self._searches_path)}

def keep_search(self, line: Mapping[str, Any]) -> None:
"""Save the search *line* of a question whose answer failed, once, before the error."""
if line["qid"] not in self._searches:
append_line(self._searches_path, line)
self._searches[str(line["qid"])] = dict(line)

def done_ids(self, field: str) -> set[str]:
return self._log.done_ids(field)
Expand All @@ -238,6 +252,8 @@ def mark_done(self, payload: Mapping[str, Any]) -> None:
def append(self, row: Mapping[str, Any]) -> None:
body = dict(row)
extra = body.pop("retrieval", None)
if extra is None and body.get("missing"):
extra = self._searches.get(str(body["qid"]))
if extra is not None:
append_line(self._extra, extra)
self._log.append(body)
Expand Down Expand Up @@ -362,7 +378,8 @@ async def answer_stage(ctx: stages35.Ctx) -> int:
say(f"[answer] {ctx.dataset}/{ctx.setup}/run{ctx.run}: done earlier, skipped")
return 0
opened = stagekit35.open_checks(ctx)
kept = OrderedRows(_SplitLog(log), [q.qid for q in ctx.questions], trace=ctx.trace)
split = _SplitLog(log)
kept = OrderedRows(split, [q.qid for q in ctx.questions], trace=ctx.trace)
gate = HostedGate(
"answer", ctx.args.answer_concurrency, attempts=ctx.args.rate_limit_attempts
)
Expand All @@ -372,7 +389,7 @@ async def answer_stage(ctx: stages35.Ctx) -> int:

async def one(qid: str) -> None:
question = by_id[qid]
error, usage = None, None
error, usage, line = None, None, None
try:
async with searching:
found, line = await stagekit35.ranked(ctx, question.text)
Expand Down Expand Up @@ -401,6 +418,8 @@ async def one(qid: str) -> None:
except Exception as exc: # noqa: BLE001 - an error is not a result (section 12)
error = stages35._error(ctx, exc)
if error is not None:
if line is not None:
split.keep_search({"qid": qid, **line})
kept.fail(qid, error, _trace(ctx, qid, None, error), usage=usage)
say(f"[answer] {qid}: ERROR {error}")
return
Expand Down
10 changes: 7 additions & 3 deletions experiments/35-full-rag-benchmark-2026-11-01/claimstage35.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ def _items(run_dir: Path) -> dict[str, dict[str, Any]]:
class _KindsLog:
"""The stage's ``RowFile`` with rows in ``claim-kinds.jsonl``; a closed row keeps its claim."""

def __init__(self, log: outputs35.RowFile, items: Mapping[str, Mapping[str, Any]]) -> None:
def __init__(
self, log: outputs35.RowFile, items: Mapping[str, Mapping[str, Any]], version: str
) -> None:
self._log = log
self._items = items
self._version = version
self.stage = log.stage
self.path = log.path.with_name(ROWS_FILE)
if self.path.exists():
Expand All @@ -133,7 +136,8 @@ def done_ids(self, field: str) -> set[str]:
def append(self, row: Mapping[str, Any]) -> None:
if row.get("missing"):
item = self._items[row["item"]]
row = {**_row(row["item"], item), "kind": None, **row}
# The version keeps the closed row valid under a passed gate (section 12).
row = {**_row(row["item"], item), "kind": None, "version": self._version, **row}
with self.path.open("a", encoding="utf-8") as handle:
handle.write(json.dumps(dict(row), ensure_ascii=False) + "\n")
handle.flush()
Expand Down Expand Up @@ -219,7 +223,7 @@ async def claimkinds_stage(
say(f"[claimkinds] {ctx.run_dir}: done earlier, skipped")
return 0
items = _items(ctx.run_dir)
rows = OrderedRows(_KindsLog(log, items), list(items), id_field="item")
rows = OrderedRows(_KindsLog(log, items, version), list(items), id_field="item")
limit = int(ctx.args.classify_concurrency)
gate = HostedGate(ROLE, limit, attempts=int(ctx.args.rate_limit_attempts), sleep=sleep)
slots = asyncio.Semaphore(limit)
Expand Down
13 changes: 7 additions & 6 deletions experiments/35-full-rag-benchmark-2026-11-01/factorial35.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from experiments._lib import stats_cluster
from experiments._lib.stats_d6 import holm, paired_permutation
from outputs35 import write_json
from verdicts35 import verdicts
from verdicts35 import row_sign, verdicts

FB, FS, BQ = select35.CORE
LEGAL = "legal"
Expand Down Expand Up @@ -280,10 +280,10 @@ def _h8b_sensitivity(
}
fb, fs = out.get(FB, {}).get("estimates", {}), out.get(FS, {}).get("estimates", {})
# Protocol 0.14 item 65: each row must have that row's H8b sign on both datasets.
target = {}
for r in range(16, 20):
h8b = hypotheses["H8b"]["faithfulness" if r < 18 else "correctness"]
target[r] = h8b["sign"] if r in h8b["rows"] else 0
target = {
r: row_sign(hypotheses["H8b"]["faithfulness" if r < 18 else "correctness"], r)
for r in range(16, 20)
}
out["agrees"] = {
r: target[r] != 0 and _sign(fb.get(r, 0.0)) == _sign(fs.get(r, 0.0)) == target[r]
for r in range(16, 20)
Expand All @@ -296,8 +296,9 @@ def _claims(hypotheses: Mapping[str, Any], sensitivity: Mapping[str, Any]) -> di
claims: dict[str, str | None] = {}
for outcome in ("faithfulness", "correctness"):
h8a, h8b = hypotheses["H8a"][outcome], hypotheses["H8b"][outcome]
# Any holding row whose own H8b sign the sensitivity analysis repeats (section 7).
itself = any(
sensitivity["sign"][r] != 0 and sensitivity["sign"][r] == h8b["sign"]
sensitivity["sign"][r] != 0 and sensitivity["sign"][r] == row_sign(h8b, r)
for r in h8b["rows"]
)
# Protocol 0.14 item 26: the registered claim names the fixed pre-assembly budget.
Expand Down
6 changes: 5 additions & 1 deletion experiments/35-full-rag-benchmark-2026-11-01/joinscores35.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def answer_scores(
"faithfulness_glm_factual_uncited": sensitivity,
CORRECT: _correctness(answer, ragas.get(qid)),
"unjudged": unjudged,
"not_defined": [] if answer.get("missing") else _not_defined(ragas.get(qid)),
"not_defined": (
[]
if answer.get("missing") or not answer.get("answer")
else _not_defined(ragas.get(qid))
),
"unparseable_verdicts": unparseable,
"segments": segments,
"uncited_segments": uncited,
Expand Down
12 changes: 9 additions & 3 deletions experiments/35-full-rag-benchmark-2026-11-01/oracle35.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from experiments._lib.hosted_calls import HostedGate, RateLimitStop
from experiments._lib.ordered_rows import OrderedRows

from omrs.core.answer.stages import EMPTY_REPLY_ERROR

say = outputs35.say
#: Returns the text of one FinanceBench page: ``(document, page label) -> text``.
PageReader = Callable[[str, str], str | None]
Expand Down Expand Up @@ -169,7 +171,7 @@ async def oracle_stage(ctx: stages35.Ctx, pages: PageReader | None = None) -> in
async def one(qid: str) -> None:
rows, record = contexts[qid]
kept.dispatch(qid)
error = None
error, usage = None, None
started = stagekit35.clock()
try:
result = await gate.call(
Expand All @@ -182,14 +184,18 @@ async def one(qid: str) -> None:
)
)
)
if result.get("answer") is None:
if result.get("answer") is None and result.get("error") == EMPTY_REPLY_ERROR:
# Protocol 0.14 item 66: a returned empty answer, final and never resent.
result = {**result, "answer": ""}
elif result.get("answer") is None:
error = ctx.redact(str(result.get("error") or "no answer text"))[:500]
usage = answers35.failed_usage(result)
except RateLimitStop:
raise
except Exception as exc: # noqa: BLE001 - an error is not a result (section 12)
error = stages35._error(ctx, exc)
if error is not None:
kept.fail(qid, error, answers35._trace(ctx, qid, None, error))
kept.fail(qid, error, answers35._trace(ctx, qid, None, error), usage=usage)
return
seconds = round(stagekit35.clock() - started, 3)
row = answers35.answer_row(ctx, by_id[qid], result, seconds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ A non-significant result means no difference was detected at this sample size. T
## 10. Smallest effect of interest and precision

- **Smallest effect of interest (SESOI).** 0.02 nDCG@10, decided by the owner on 2026-11-14 (O2). The concept follows Lakens 2017. It changes no decision: every hypothesis is tested against zero, and each row's interval is read against plus and minus 0.02. No other endpoint has a SESOI; their intervals are reported without one.
- **Why 0.02.** No IR standard fixes this value; it is the authors' justified choice. (1) User terms: for a question with one gold unit, moving it from rank 2 to rank 1 raises nDCG@10 by 1 minus 1/log2(3), about 0.369. A mean gain of 0.02 is about one question in 18 with its gold unit moved from second to first place (0.02 / 0.369 = 0.054); 0.01 is about one in 37, and 0.05 about one in 7. Bringing a gold unit from outside the top 10 to rank 10 adds 1/log2(11), about 0.289, so 0.02 is about one question in 14. (2) Lower bound from the design: selection treats setups within 0.01 as tied (section 14.1) and the tolerance on another back end is 0.005 (section 15), so the SESOI must be above 0.01. (3) Cost: each factor step costs something real. A 4B to 8B model roughly doubles memory, a reranker scores 100 more pairs per query, and hybrid search adds an index. The authors judge that a gain which changes the top result for fewer than about one question in 20 does not pay for such a step for an OMRS user. (4) Published effects (Zhang et al. 2025; MTEB retrieval scores are nDCG@10 x 100): on MTEB(eng, v2) retrieval the 0.6B, 4B and 8B embedders score 61.83, 68.46 and 69.44 (steps about 0.066 and 0.010). On MTEB-R, from a 61.82 first stage, the 0.6B, 4B and 8B rerankers score 65.80, 69.76 and 69.02 (gains about 0.040, 0.079 and 0.072; size steps 0.040 and minus 0.007). These effects span about 0.01 to 0.08 in size, and 0.02 separates the two smallest steps from the rest. (5) Not set by power: the datasets are fixed, so the study chooses no sample size, and 0.02 was not chosen to match what the design can detect. The sensitivity power analysis below (A17) gives the smallest effect each test detects with power 0.80 (the MDE). On FreshStack and FinanceBench the MDE is about 0.04 to 0.08, so a true effect of 0.02 is not reliably detected there. On BioASQ it is about 0.02 to 0.03. A row whose interval cannot exclude 0.02 is reported as "cannot rule out a small effect". (6) Sensitivity: the report also reads every interval against 0.01 and 0.05.
- **Why 0.02.** No IR standard fixes this value; it is the authors' justified choice. (1) User terms: for a question with one gold unit, moving it from rank 2 to rank 1 raises nDCG@10 by 1 minus 1/log2(3), about 0.369. A mean gain of 0.02 is about one question in 18 with its gold unit moved from second to first place (0.02 / 0.369 = 0.054); 0.01 is about one in 37, and 0.05 about one in 7. Bringing a gold unit from outside the top 10 to rank 10 adds 1/log2(11), about 0.289, so 0.02 is about one question in 14. (2) Lower bound from the design: selection treats setups within 0.01 as tied (section 14.1) and the tolerance on another back end is 0.005 (section 15), so the SESOI must be above 0.01. (3) Cost: each factor step costs something real. A 4B to 8B model roughly doubles memory, a reranker scores 100 more pairs per query, and hybrid search adds an index. The authors judge that a gain which changes the top result for fewer than about one question in 20 does not pay for such a step for an OMRS user. (4) Published effects (Zhang et al. 2025; MTEB retrieval scores are nDCG@10 x 100): on MTEB(eng, v2) retrieval the 0.6B, 4B and 8B embedders score 61.83, 68.46 and 69.44 (steps about 0.066 and 0.010). On MTEB-R, from a 61.82 first stage, the 0.6B, 4B and 8B rerankers score 65.80, 69.76 and 69.02 (gains about 0.040, 0.079 and 0.072; size steps 0.040 and minus 0.007). These effects span about 0.01 to 0.08 in size, and 0.02 separates the two smallest steps from the rest. (5) Not set by power: the datasets are fixed, so the study chooses no sample size, and 0.02 was not chosen to match what the design can detect. The sensitivity power analysis below (A17) gives the smallest effect each test detects with power 0.80 (the MDE). On FreshStack and FinanceBench the MDE is about 0.04 to 0.08, so a true effect of 0.02 is not reliably detected there. On BioASQ it is about 0.02 to 0.03. A row whose interval cannot exclude 0.02 is read through cases 3 and 4 of A16 (next item). (6) Sensitivity: the report also reads every interval against 0.01 and 0.05.
- **Precision (owner decision, 2026-11-26).** This study has no a priori power analysis, no pilot and no observed power. It reports one sensitivity power analysis (A17, below). Precision is reported through each row's 95% confidence interval. Amended 2026-11-26 (pre-freeze, owner; `plan.json` amendment A16): each interval is read against the SESOI of 0.02 nDCG@10 in four cases:
1. The interval is fully inside -0.02 to +0.02: no meaningful difference.
2. The interval is fully above +0.02, or fully below -0.02: a meaningful difference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def _load_run(folder: Path, version: str) -> dict[str, RunAnswer]:
kinds_rows = read_rows(folder / "claim-kinds.jsonl")
if any(r.get("version") != version for r in kinds_rows):
raise ReportError(f"{folder}: a saved kind has another classifier version than {version}")
kinds = {r["claim_key"]: r["kind"] for r in kinds_rows}
# An uncited segment with the same text must not replace the cited claim's kind.
kinds = {r["claim_key"]: r["kind"] for r in kinds_rows if not r.get("uncited")}
judges = {c: {r["qid"]: r for r in read_rows(folder / f"judge-{c}.jsonl")} for c in CHECKERS}
where = "/".join(folder.parts[-4:])
out: dict[str, RunAnswer] = {}
Expand Down
24 changes: 18 additions & 6 deletions experiments/35-full-rag-benchmark-2026-11-01/reporttables35.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@

SESOI = 0.02
READ_AGAINST = (0.01, 0.02, 0.05)
SMALL_EFFECT = "cannot rule out a small effect"
#: Cases 3 and 4 of Amendment A16 (section 10), in its own words. Cases 1 and 2 read "within"
#: and "beyond" (plus the SESOI in the registered reading).
SMALL_REAL = "a real difference that can be too small to matter"
CANNOT_TELL = "the test cannot tell"
LENGTH_SOURCE = "distinct stored chunks in the saved top-100 search lists (pinned Qwen3 tokens)"
#: The one sensitivity table set of section 21 (A5: no any-page or page-rule table).
SENSITIVITY_TABLES = (
Expand Down Expand Up @@ -198,8 +201,15 @@ def h8b_token_totals(answer_records: Iterable[Mapping[str, Any]]) -> dict[str, A


def _reading(low: float, high: float, t: float) -> str:
"""Read a 95% interval against plus and minus ``t`` in the four cases of Amendment A16.

The interval is closed: an endpoint on 0.0 includes zero, and an endpoint on plus or minus
``t`` crosses ``t`` (so it is neither fully inside nor fully beyond). The four cases apply
to every ``t`` in ``READ_AGAINST``, because the rule only compares an interval with a
threshold. Section 10 registers the reading against 0.02, and (6) reads 0.01 and 0.05 alike.
"""
if low <= t <= high or low <= -t <= high:
return "cannot exclude"
return CANNOT_TELL if low <= 0 <= high else SMALL_REAL
return "within" if -t < low and high < t else "beyond"


Expand All @@ -209,8 +219,10 @@ def sesoi_lines(
"""Return per row the SESOI reading and its marks (sections 10 and 21).

Only nDCG@10 rows have a SESOI (0.02); their interval is read against plus
and minus 0.01, 0.02 and 0.05. An interval that cannot exclude 0.02 reads
"cannot rule out a small effect". Other rows get the marks only.
and minus 0.01, 0.02 and 0.05 in the four cases of Amendment A16: "within 0.02",
"beyond 0.02", "a real difference that can be too small to matter" (excludes zero,
crosses 0.02) and "the test cannot tell" (includes zero, crosses 0.02). The reading is
descriptive only. Other rows get the marks only.
"""
out: dict[str, list[dict[str, Any]]] = {}
for dataset, rows in rows_by_dataset.items():
Expand Down Expand Up @@ -238,8 +250,8 @@ def sesoi_lines(
line |= {
"sesoi": SESOI,
"readings": readings,
"sesoi_reading": SMALL_EFFECT
if main == "cannot exclude"
"sesoi_reading": main
if main in (SMALL_REAL, CANNOT_TELL)
else f"{main} {SESOI}",
}
out.setdefault(dataset, []).append(line)
Expand Down
9 changes: 9 additions & 0 deletions experiments/35-full-rag-benchmark-2026-11-01/verdicts35.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ def _both(counted: Mapping[str, Mapping[int, int]], rows: Sequence[int]) -> dict
"holds": bool(holding),
"rows": holding,
"sign": signs.pop() if len(signs) == 1 else 0,
"row_signs": {r: fb[r] for r in holding},
"dataset_dependent": [r for r in rows if fb.get(r, 0) * fs.get(r, 0) < 0],
}


def row_sign(held: Mapping[str, Any], row: int) -> int:
"""Return the sign of a row inside a ``_both`` verdict: its own sign, 0 if it does not hold.

A verdict without ``row_signs`` (the same-sign case, built by hand) falls back to ``sign``.
"""
return held.get("row_signs", {}).get(row, held["sign"]) if row in held["rows"] else 0


def verdicts(counted: Mapping[str, Mapping[int, int]]) -> dict[str, Any]:
"""Apply the per-hypothesis rules of section 7.

Expand Down
5 changes: 4 additions & 1 deletion tests/test_clean_base_tripwire.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,10 @@
# 9 in test_experiment35_hosted_usage, 2 in test_experiment35_run_arms, 1 in
# test_experiment35_claimstage and 1 in test_experiment35_parallel_answers.
# +1 (2026-11-28, freeze-check finding, by test-ID diff): 1 in test_experiment35_factorial.
_BASE_EXECUTED = 14512
# +39 (2026-11-28, Exp 35 audit defects 1 to 7, by test-ID diff against v3 ddd3663a): 23 in
# test_experiment35_report_tables, 7 in _factorial, 3 in _parallel_answers, 2 in
# _refusal_report, 2 in _closedbook_oracle, 1 in _claimstage, 1 in _join_scores. None removed.
_BASE_EXECUTED = 14551
# Re-baselined check-embedding-stamp-before-dimension (2026-10-18): 10 new cases
# (store stamp-first tests and graph embed-step tests). Measured in two clean
# venvs: 5741 with the web extra, 5091 without; the web extra still adds 650.
Expand Down
Loading
Loading