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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ corpus:
retrieval: corpus
uv run python -m mobium_rag.evaluate

.PHONY: experiments
experiments:
uv run python -m mobium_rag.experiments > /dev/null && echo "data/retrieval-experiments.md"

.PHONY: generation
generation: corpus
uv run python -m mobium_rag.generate
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ and ROADMAP), outranked by sections that name a device — under every
reranker tried, a larger one and rank fusion included
(`data/retrieval-report.md`, "Rerankers").

**Experiments to raise retrieval, 2026-11-27**
([data/retrieval-experiments.md](data/retrieval-experiments.md)). Each change
was chosen on half of golden set v2 and confirmed on the other half, with the
82 above run last. None held: no interval on held-out questions excluded zero,
so the gate's retriever and its floors are unchanged. The best stack — the bge
reranker on a hybrid BM25 + dense pool of 50, with heading paths, five distinct
sections — reached recall@5 0.870 and MRR 0.779 on the 82, ahead of 0.815 and
0.767 but within the interval, at about 2.6 s a question on a Mac against
70 ms. Hybrid retrieval raises the share of questions with their gold among
the candidates to 0.96–0.97; the reranker is where most of the loss is. Three
of the "runs on X" misses are answered by a ROADMAP section their labels leave
out, which is for the v2 review to decide.

## Running it

Requirements: [uv](https://docs.astral.sh/uv/), a checkout of Mobium's
Expand All @@ -221,6 +234,7 @@ make test # unit tests: metrics, corpus, answers, judge plumbing
make corpus # cut the pinned docs into data/corpus.jsonl
make retrieval # corpus, then the retrieval report (data/retrieval-report.md)
make ci # tests, corpus, and the retrieval gate: what CI runs
make experiments # retrieval changes on golden set v2 (data/retrieval-experiments.md)
make generation # answer the golden set with Ollama (data/answers.jsonl)
make judge # score stored answers with each judge, behind its controls

Expand Down Expand Up @@ -255,6 +269,7 @@ deliberate corpus change and is reviewed like code.
| `src/mobium_rag/answer.py` | the prompt, the Ollama call, citations and refusals |
| `src/mobium_rag/metrics.py` | recall@k, MRR, nDCG against gold sections |
| `src/mobium_rag/evaluate.py` | phases 3–4: retrieval with controls, intervals and the gate |
| `src/mobium_rag/experiments.py` | retrieval changes chosen on half of v2, confirmed on the other half and the gate |
| `src/mobium_rag/generate.py` | phase 5: answers, refusals and citations |
| `src/mobium_rag/metajudge.py` | phase 6: judges, controls, repeat, judge vs judge and vs person |
| `src/mobium_rag/claudecli.py` | a Claude model as a judge through `claude -p` |
Expand Down
10 changes: 7 additions & 3 deletions REVIEWING.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,14 @@ The choice and its reasons go in PLAN.md, phase 6.

## Golden set v2 (from 2026-10-24)

100 questions drafted from nothing against Mobium `f232d54`, to
100 questions drafted from nothing against Mobium `f232d54` and carried
to `767cd14` on 2026-11-26, to
`review/GOLDEN-V2.md`: `data/golden-v2-proposed.jsonl`, checked by
`review/check_golden_v2.py`, on their own page built by
`review/build_review_v2.py` (`review/golden-review-v2.html`). Key facts
show their anchors after them in ⟦ ⟧: alternatives split by " / ",
anchors by " ; ". The 82 in `data/golden.jsonl` keep the gate until v2 is
decided and applied.
anchors by " ; ". The maintainer exports the page's `reviews` collection
to `review/decisions-v2/` and runs `review/apply_v2.py`, which writes
`data/golden-v2.jsonl` and refuses a reviewed question that breaks the
specification's rules. The 82 in `data/golden.jsonl` keep the gate until
v2 is adopted.
24 changes: 12 additions & 12 deletions data/golden-v2-proposed.jsonl

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions data/retrieval-experiments.md

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions review/GOLDEN-V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ questions, grew by additions to 82, and leans on what it was drafted from:
three quarters of its gold is CHALLENGES entries, one question is
unanswerable, and nothing in it covers what Mobium gained after
`7b590a4`. Version 2 is written from nothing, against Mobium's public
`main` at **`f232d54`**, to this specification. The 82 stay in
`data/golden.jsonl` and keep the gate until v2 is reviewed and adopted.
`main` at `f232d54`, to this specification, and carried to **`767cd14`**
on 2026-11-26, before any of it was reviewed (`review/repin_v2.py` says
what changed and why). The 82 stay in `data/golden.jsonl` and keep the
gate until v2 is reviewed and adopted.

A golden set is a test suite. Each question is a test case: it has one
right answer, the answer is in the corpus, and a reader can say whether an
Expand Down Expand Up @@ -102,7 +104,8 @@ One JSON object per line, in `data/golden-v2-proposed.jsonl`:
```

`check` is the drafter's reading, shown on the review page as Claude's —
the person decides; `review/apply.py` applies what they decided.
the person decides; `review/apply_v2.py` applies what they decided, into
`data/golden-v2.jsonl`.

## Checked by code before review

Expand Down
124 changes: 124 additions & 0 deletions review/apply_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""Apply the golden v2 review's decisions to data/golden-v2.jsonl.

The decisions are the v2 review page's `reviews` collection, exported with
ArtifactData: either a directory of one JSON file per question
(`review/decisions-v2/reviews/g001.json`, what `out_dir` writes) or one
JSON object keyed by id (`review/decisions-v2.json`). Each holds
`decision` (approve, edit, reject or null), `question` (the edited
wording), `also` (gold sections ticked), `facts` (the fact lines as the
reviewer left them, anchors in ⟦ ⟧) and `note`.

A note's instructions ("DROP …", "ADD …", "kind fact") are copied by hand
into the tables below, so every change is read here rather than parsed out
of prose; every note is printed on each run so none is missed.

The 82 in data/golden.jsonl keep the gate: this writes the reviewed v2 set
beside them, and adopting it is a separate decision (PLAN.md, Phase 6b).
An undecided question stays out and is counted. Every applied question is
held to the specification's rules for one question (check_golden_v2.py);
the set's quotas are reported, not enforced, since a rejection lowers them.

uv run python review/apply_v2.py [decisions] [--commit 767cd14]
"""

import json
import sys
from pathlib import Path

from build_review_v2 import parse_fact_line
from check_golden_v2 import PIN, problems

ROOT = Path(__file__).resolve().parent.parent
PROPOSED = ROOT / "data" / "golden-v2-proposed.jsonl"
GOLDEN = ROOT / "data" / "golden-v2.jsonl"
DECISIONS = [ROOT / "review" / "decisions-v2" / "reviews", ROOT / "review" / "decisions-v2.json"]

# From the notes, word for word in effect.
DROP: dict[str, list[str]] = {} # gold sections the reviewer dropped
KIND: dict[str, str] = {} # a kind the reviewer changed
FOUND: dict[str, list[str]] = {} # defects in Mobium a question's review found: "CHALLENGES 362", "mobium#275"

KEEP = ("id", "question", "kind", "category", "persona", "gold", "facts", "nearest", "new_since_pin")


def load_decisions(src: Path) -> dict[str, dict]:
if src.is_dir():
return {p.stem: json.loads(p.read_text()) for p in sorted(src.glob("*.json"))}
return json.loads(src.read_text())


def apply(proposed: list[dict], decisions: dict[str, dict]) -> tuple[list[dict], dict]:
"""The reviewed set, and what happened to every question."""
rows, report = [], {"approve": [], "edit": [], "reject": [], "undecided": [], "notes": {}}
for p in proposed:
d = decisions.get(p["id"]) or {}
verdict = d.get("decision")
if (d.get("note") or "").strip():
report["notes"][p["id"]] = d["note"].strip()
if verdict is None:
report["undecided"].append(p["id"])
continue
if verdict not in ("approve", "edit", "reject"):
raise SystemExit(f"{p['id']}: decision {verdict!r} is not approve, edit or reject")
report[verdict].append(p["id"])
if verdict == "reject":
continue
r = {k: p[k] for k in KEEP if k in p}
if verdict == "edit" and (d.get("question") or "").strip():
r["question"] = d["question"].strip()
r["kind"] = KIND.get(p["id"], r["kind"])
gold = [g for g in r["gold"] if g not in DROP.get(p["id"], [])]
r["gold"] = gold + [g for g in d.get("also") or [] if g not in gold]
if d.get("facts"):
r["facts"] = [parse_fact_line(line) for line in d["facts"] if line.strip()]
if r["kind"] == "unanswerable" and (r["gold"] or r["facts"]):
raise SystemExit(f"{p['id']}: unanswerable with gold {r['gold']} — change its kind in KIND or drop the gold")
r["verified_in"] = p.get("verified_in", [])
if p["id"] in FOUND:
r["found"] = FOUND[p["id"]]
r["status"] = "reviewed"
rows.append(r)
return rows, report


def main(argv: list[str]) -> int:
import check_golden_v2
from mobium_rag import corpus
from mobium_rag.checks import rarity

commit = PIN
if "--commit" in argv:
k = argv.index("--commit")
commit, argv = argv[k + 1], argv[:k] + argv[k + 2:]
src = Path(argv[0]) if argv else next((s for s in DECISIONS if s.exists()), None)
if src is None:
raise SystemExit("no decisions: export the page's `reviews` collection to review/decisions-v2/ first")
proposed = [json.loads(line) for line in PROPOSED.read_text().splitlines() if line.strip()]
rows, report = apply(proposed, load_decisions(src))

check_golden_v2.PIN = commit
passages = corpus.build(commit)
sections: dict[str, str] = {}
for p in passages:
sid = corpus.section_of(p.id)
sections[sid] = sections.get(sid, "") + "\n" + p.text
found = problems(rows, sections, rarity([p.text for p in passages]))
ids = {r["id"] for r in rows}
own = [f for f in found if f.split(":")[0] in ids]
if own:
print("\n".join(own))
print(f"{len(own)} problems in reviewed questions: fix them in the review, or in the tables here")
return 1
GOLDEN.write_text("".join(json.dumps(r, ensure_ascii=False) + "\n" for r in rows))

print(f"{len(rows)} reviewed into {GOLDEN.relative_to(ROOT)} at {commit}: {len(report['approve'])} approved, "
f"{len(report['edit'])} edited, {len(report['reject'])} rejected, {len(report['undecided'])} undecided")
for line in (f for f in found if f.split(":")[0] not in ids):
print(f" quota: {line}")
for i, note in report["notes"].items():
print(f" note {i}: {note}")
return 0


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
8 changes: 4 additions & 4 deletions review/build_review_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
the 82's, built from the same page with its questions taken out.

For each drafted question: its gold sections with an excerpt, what the
two-stage retriever returns for it from the corpus at f232d54 with the gold
two-stage retriever returns for it from the corpus at 767cd14 with the gold
marked, its key facts with their anchors, and Claude's check of it. The
corpus.pin and the 82's index are not touched: the retrieval here is its
own index, keyed by the commit.
Expand All @@ -11,7 +11,7 @@
separated by " / ", anchors by " ; ". The reviewer edits the line; the
apply step reads it back the same way (`fact_line`, `parse_fact_line`).

uv run python review/build_review_v2.py [questions.jsonl] [--commit f232d54]
uv run python review/build_review_v2.py [questions.jsonl] [--commit 767cd14]
"""

import json
Expand Down Expand Up @@ -72,7 +72,7 @@ def entry(q: dict, index: Index, by_section: dict) -> dict:


def main(argv: list[str]) -> None:
commit = "f232d54"
commit = "767cd14"
if "--commit" in argv:
k = argv.index("--commit")
commit, argv = argv[k + 1], argv[:k] + argv[k + 2:]
Expand All @@ -92,7 +92,7 @@ def main(argv: list[str]) -> None:
page = page.replace("<h1>Golden Set Review</h1>", "<h1>Golden Set v2 Review</h1>")
page = page.replace("<title>Golden Set Review</title>", "<title>Golden Set v2 Review</title>", 1)
page = re.sub(r"\d+ questions · corpus", f"{len(qs)} questions · corpus", page, count=1)
page = page.replace("key facts drafted 2026-10-12", "drafted 2026-10-24 to review/GOLDEN-V2.md; "
page = page.replace("key facts drafted 2026-10-12", "drafted 2026-10-24 to review/GOLDEN-V2.md, re-pinned 2026-11-26; "
"anchors follow each fact in ⟦ ⟧, alternatives split by / and anchors by ;")
# Category, persona and whether it is new show beside the kind.
page = page.replace('q.missed ? el("span",{class:"tag miss",text:"Missed by retrieval"}) : null,',
Expand Down
4 changes: 2 additions & 2 deletions review/check_golden_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Prints each problem and exits 1 if there is any. Run from the repository
root:

uv run python review/check_golden_v2.py [questions.jsonl] [--commit f232d54]
uv run python review/check_golden_v2.py [questions.jsonl] [--commit 767cd14]
"""

import json
Expand All @@ -21,7 +21,7 @@
from mobium_rag.checks import normalize, present, rarity

ROOT = corpus.ROOT
PIN = "f232d54"
PIN = "767cd14"
KINDS = {"fact": 70, "multi": 20, "unanswerable": 10}
CATEGORIES = {"how-to": 35, "behavior": 25, "troubleshooting": 15, "support": 8, "rationale": 7}
PERSONAS = {"new-user", "test-author", "ci-engineer", "agent-builder", "driver-author", "contributor"}
Expand Down
4 changes: 2 additions & 2 deletions review/golden-review-v2.html

Large diffs are not rendered by default.

Loading