Skip to content

fix(eval): re-pin two stale answer-key quotes in technical_docs - #8755

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
c0mrade8:fix/rag-benchmark-stale-quotes
Nov 21, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
c0mrade8:fix/rag-benchmark-stale-quotes

Conversation

@c0mrade8

Copy link
Copy Markdown
Contributor

Summary

Two quotes in technical_docs.json stopped matching the text GAIA indexes from the PDFs, which is what killed the release RAG benchmark. This re-points them at the same answers. Questions, answers and pages are unchanged.

Why

The benchmark checks that every labelled quote can be found on its page, and it stops at the first one it can't. That's the LabelError on tech-012 in the issue.

I checked both against the PDFs: the Max Power row on page 25 of the CDNA 3 white paper, and the SR-IOV row on page 1 of the MI300X datasheet.

One thing I noticed but didn't touch: on the tech-012 page the extractor treats the FORM FACTOR row (SH5 Socket | OAM | OAM) as the header, so rows read FORM FACTOR: MAX POWER | SH5 Socket: .... The values still sit next to their labels, so I don't think it breaks retrieval, but it reads oddly. I can open a separate issue if you'd consider it a bug.

Linked issue

Refs #8407

The issue also asks for a fast, no-model check that runs on PRs, so a stale quote fails where it's edited. I'd like to do that in a second PR, but I'm happy to fold it into this one if you'd rather.

Changes

  • tech-012: the quote now matches the current table-row text: MAX POWER | SH5 Socket: 550W or 760W | OAM: 750W | OAM: 1000W
  • tech-023: the quote is now up to 8 partitions *The MI200 Series. It starts after the comma, so pypdf's spacing doesn't matter, and it still contains the answer. It runs on into the footnote under that row because the dataset test requires quotes of at least 20 characters, and up to 8 partitions alone is 18.

Test plan

  • Ran a script (below) that resolves every evidence quote against the extracted text: all 55 in technical_docs.json (including the table-tagged items from the bot's list) and the 8 PDF-backed labels in repo_docs.json (repo-001 and repo-007 among them). Before: 2 of 55 failed. After: 0 of 55 under pypdf 6.21.1 and 7.1.0, and 0 of 8 for repo_docs under 7.1.0. VLM off, pypdfium2 5.15.2. repo-028 is a .txt, which the PDF table rewrite doesn't touch, so I didn't scan it.
  • python -m pytest tests/unit/eval/test_retrieval_bench.py -q after the final edit: 77 passed, including the dataset well-formedness test
  • python -m pytest tests/unit/eval -q: 2096 passed, 34 skipped (run before the tech-023 quote changed)
  • python util/lint.py --all --fix: only two Pylint os.getuid errors, which are Windows-only and in files this PR doesn't touch. I didn't run the full tests/unit/ locally since this is a data-only change; CI covers it.
  • Not run: the full gaia eval retrieval --suite full benchmark. It needs Lemonade and the VLM, which my machine can't run. Could someone confirm it on the release runner? It would also help to know which pypdf version that runner uses.

Evidence

The script isn't a gaia subcommand: it's python scan_labels.py from the repo root, and the source is in the details block below.
Before, on main with pypdf 7.1.0:

2 of 55 evidence labels do not resolve

tech-012  doc=amd_cdna3_whitepaper  page=25  tags=['pdf', 'table', 'spec']
  quote : 'MAX POWER 550W or 760W 750W 1000W'
  page  : ...FORM FACTOR | SH5 Socket | OAM | OAM FORM FACTOR: THERMAL | SH5 Socket: Passive and Liquid | OAM: Passive and Liquid | OAM: Passive and Liquid FORM FACTOR: MAX POWER | SH5 Socket: 550W or 760W | OAM: 750W | OAM: 1000W ...

tech-023  doc=amd_mi300x_datasheet  page=1  tags=['pdf', 'table', 'spec', 'numeric']
  quote : 'SR-IOV , up to 8 partitions'
  page  : ...AND VIRTUALIZATION Decoders† JPEG/MJPEG CODEC Virtualization support 4 groups for HEVC/H.265, AVC/H.264, V1, or AV1 32 cores, 8 cores per group SR-IOV, up to 8 partitions *The MI200 Series does not support TF32, FP8, or sparsity* †Video codec acceleration (including at least the HEVC (H.265), H.264, VP9, and AV1 codecs...

After, under pypdf 6.21.1 and 7.1.0:

0 of 55 evidence labels do not resolve

Other surfaces: N/A, eval data change only.

scan_labels.py
"""Lists every answer-key quote that no longer matches the indexed PDF text.

Run from the root of a gaia checkout, after `gaia eval retrieval --fetch-only`:

    python scan_labels.py                          # technical_docs, all PDFs
    python scan_labels.py --doc amd_cdna3_whitepaper
    python scan_labels.py --dump scan_out          # also write extracted text per doc

Does not need Lemonade, an embedder or a VLM (it logs a health-check warning 
if Lemonade isn't running).. Text comes from the same RAGSDK._extract_text_from_pdf 
the benchmark indexes with, VLM off, so a quote that lives only in an image shows up 
here too; check those by hand.
"""

from __future__ import annotations

import argparse
import re
from pathlib import Path

from gaia.eval.retrieval import corpus, sources
from gaia.eval.retrieval.locate import DocText, Evidence, LabelError, norm, resolve_evidence


def window(doc: DocText, page, quote: str, radius: int = 160) -> str:
    """Text on the labelled page around the quote's longest word, to compare by eye."""
    try:
        text = doc.page_text(page) if page is not None else doc.text
    except LabelError as e:
        return f"(no such page: {e})"
    for word in sorted(set(re.findall(r"\w{4,}", quote)), key=len, reverse=True):
        at = text.find(word)
        if at >= 0:
            return text[max(at - radius, 0) : at + radius]
    return text[: 2 * radius]


def scan(dataset, texts: dict) -> list:
    """Resolve every evidence label; return one record per failure (never stops early)."""
    failures, total = [], 0
    for q in dataset.questions:
        for ev in q.evidence:
            doc = texts.get(ev["doc"])
            if doc is None:
                continue  # not a PDF, or filtered out
            total += 1
            page, quote = ev.get("page"), ev.get("quote")
            try:
                hint = 0
                if ev.get("near"):
                    hint = doc.text.find(norm(ev["near"]))
                    if hint < 0:
                        raise LabelError("'near' text is not in the document as indexed")
                resolve_evidence(Evidence(ev["doc"], page, quote), doc, hint)
            except LabelError as e:
                failures.append(
                    {"q": q.id, "tags": q.tags, "doc": ev["doc"], "page": page,
                     "quote": quote, "why": str(e), "window": window(doc, page, quote or "")}
                )
    return failures, total


def main() -> None:
    ap = argparse.ArgumentParser()
    ap.add_argument("--dataset", default="technical_docs")
    ap.add_argument("--doc", action="append", help="only this document id (repeatable)")
    ap.add_argument("--dump", help="directory to write each document's extracted text to")
    args = ap.parse_args()

    sources.set_repo_root(Path.cwd())
    dataset = corpus.load_labelled(args.dataset, offline=True)

    from gaia.rag.sdk import RAGConfig, RAGSDK  # imported late: heavy

    rag = RAGSDK(RAGConfig(use_vlm=False, show_stats=False))
    texts = {}
    for d in dataset.documents:
        if args.doc and d.id not in args.doc:
            continue
        if d.path.suffix.lower() != ".pdf":
            print(f"[skip] {d.id}: not a PDF ({d.path.suffix})")
            continue
        print(f"[extract] {d.id} ...", flush=True)
        full_text = rag._extract_text_from_pdf(str(d.path))[0]
        texts[d.id] = DocText.from_full_text(str(d.path), full_text)
        if args.dump:
            Path(args.dump).mkdir(parents=True, exist_ok=True)
            (Path(args.dump) / f"{d.id}.txt").write_text(full_text, encoding="utf-8")

    failures, total = scan(dataset, texts)
    print(f"\n{len(failures)} of {total} evidence labels do not resolve\n")
    for f in failures:
        print(f"{f['q']}  doc={f['doc']}  page={f['page']}  tags={f['tags']}")
        print(f"  quote : {(f['quote'] or '')[:140]!r}")
        print(f"  page  : ...{f['window']}...\n")


if __name__ == "__main__":
    main()

Checklist

  • I have linked a GitHub issue above (Closes #N / Fixes #N / Refs #N).
  • I have described why this change is being made, not just what changed.
  • I ran linting and tests locally (lint, tests/unit/eval; full tests/unit/ left to CI)
  • I have attached real-world evidence matched to the surface I changed (see Evidence above), or marked each surface N/A.
  • I have updated documentation if user-visible behavior changed (see CONTRIBUTING.md). N/A: eval data only

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

This fixes two answer-key quotes in the retrieval benchmark that no longer matched the text GAIA pulls out of the PDFs. That mismatch is what stopped the release RAG benchmark. The questions, answers and pages are unchanged, so both items still test the same facts, and the new quotes match the extracted text on both pypdf versions in play. One loose end: the full gaia eval retrieval --suite full run still needs someone with the release runner to confirm it, as the PR says.

Real-world evidence

N/A: this PR only changes eval data, and the evidence stage produced no bundle. The verdict rests on static review, plus the author's label-scan output in the PR body: 2 of 55 quotes failed before the change and 0 of 55 after, under pypdf 6.21.1 and 7.1.0. I did not re-run that scan here.

🔍 Technical details

Issues found

🟢 The tech-023 quote no longer contains the question's keyword (eval/retrieval/datasets/technical_docs.json:482). up to 8 partitions *The MI200 Series resolves and holds the answer. But a chunk can now count as a hit by covering only "8 partitions" plus the footnote, without "SR-IOV". chunk_hits asks for 50% coverage (MIN_QUOTE_COVERAGE), so a chunk boundary right after "partitions" would still score. This is low risk, since the page is pinned and the phrase is unique on page 1. If you'd like the label to point at the SR-IOV row itself, a quote that avoids the comma could work, e.g. Virtualization support + row text. Check it with your scan script before switching.

Checks run

  • norm() in locate.py only collapses whitespace, so the | and : separators in the tech-012 quote have to match the post-fix(rag): keep PDF table rows whole and send table math to run_python #8116 table-row text exactly. The "before" page window in the PR body shows that exact substring.
  • No docs, tests or other datasets hard-code either old quote (grepped 550W and 8 partitions).
  • The new tech-023 quote is 36 characters, above the dataset test's 20-character minimum.

Strengths

  • The root cause is bisected to a specific commit, and the pypdf version-dependent spacing is pulled apart from it rather than lumped together.
  • The fix stays minimal: answers and pages don't change, so baseline scores stay comparable.
  • The odd FORM FACTOR header row is flagged separately instead of being folded into this PR.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Keeping the tech-023 quote as it is. Any quote that names SR-IOV and also holds the answer has to cross that comma, and the comma is exactly what differs between pypdf versions. The page is pinned and the phrase appears once on it, so a chunk that covers it is on the right row.

🔍 Technical details

Re-checked independently against a fresh extraction (pypdf 7.1.1, which the release runner installs, VLM off): all 55 technical_docs labels resolve on this branch, and both new quotes are verbatim page text (CDNA 3 p25 MAX POWER row; MI300X data sheet p1).

@kovtcharov-amd
kovtcharov-amd merged commit 694af17 into amd:main Nov 21, 2026
45 of 49 checks passed
kovtcharov-amd added a commit that referenced this pull request Nov 21, 2026
…8745)

The release RAG retrieval benchmark has failed on every tag since
v0.26.0-rc26 because a single stale evidence label aborted the whole run
about eleven questions in, leaving most of the benchmark (technical
docs, XQuAD, the scale tiers, the hard cases) unmeasured. Now a bad
label is recorded against its own question while the run carries on, so
one stale quote can no longer hide everything after it, and the job
still fails at the end when any label error occurred. The two stale
quotes themselves are fixed in #8755.

<details>
<summary>🔍 Technical details</summary>

- A question with a label error is left out of the scores, listed in
`results.json` (`label_errors` per dataset and in `meta`) and under
**Label errors** in the report, and `gaia eval retrieval` exits 1. Any
other exception still aborts the run. Scale tiers get the same handling;
a tier where every label fails is reported instead of crashing on its
summary line.
- The report, the harness docstring and `docs/reference/eval.mdx` no
longer describe the agent path as a "keyword boost"; it has used rank
fusion since #8737.
</details>

## Test plan
- [x] `pytest tests/unit/rag/test_retrieval_bench_harness.py
tests/unit/eval/test_retrieval_bench.py` (new: a bad label mid-dataset,
every label bad, a label on a missing page, a non-label failure still
aborting, scale tiers with some/all bad labels, report section, CLI exit
code)
- [ ] After merge (with #8755): dispatch `eval_retrieval.yml` on main
and confirm it runs through every dataset
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

That stale quote had been quietly breaking the whole RAG benchmark for weeks. Thanks for tracking it down @c0mrade8!

@c0mrade8
c0mrade8 deleted the fix/rag-benchmark-stale-quotes branch November 23, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants