Skip to content

fix(eval): evaluate, benchmark and answers generate retrieve docs through DocTreatment - #997

Merged
napetrov merged 8 commits into
intel:mainfrom
vlad-perevezentsev:fix/pipeline-retrieval-doctreatment
Nov 22, 2026
Merged

napetrov merged 8 commits into
intel:mainfrom
vlad-perevezentsev:fix/pipeline-retrieval-doctreatment

Conversation

@vlad-perevezentsev

Copy link
Copy Markdown
Contributor

Summary

#228 step 3: Stack P (Answerer, used by evaluate, benchmark run and answers generate) now retrieves docs through treatments/arms.py DocTreatment, the path Stack A (ArmRunner) uses. Answerer._retrieve_docs was its own copy of that path. Refs #228.

  • One path. _retrieve_docs builds a DocTreatment with the Answerer's top_k, its reranker and keep=3, and returns the arm's injected docs. The reranker comes from DocTreatment._default_reranker (semantic, else lexical), so Answerer.__init__ no longer has its own copy of that choice.
  • What the shared request carries (the design point). max_results=top_k, plus max_tokens when the caller has a retrieval budget. DocTreatment gets an optional retrieval_tokens:
    -    library_id=lib_id, query=question_text, max_results=self.top_k
    +    library_id=lib_id, query=question_text, max_results=self.top_k, **budget
    budget is {"max_tokens": retrieval_tokens}, or empty when it is None. The arms commands leave it unset, so their request does not change and the client default (8000) applies. The Answerer passes its retrieval budget (--max-tokens in answers generate and benchmark run, default 4000; evaluate always sends 4000). So one config gives one request on both stacks. The default gap (P 4000, A 8000) remains, because the arms commands have no retrieval-budget flag. That is Answering stack: one implementation for evaluate/benchmark/answers and arms/subjects #228 D7, which step 5 / feat(cli): split --max-tokens and --budgets by meaning (F1b tokens) #954 moves.
  • Stack P's request is the one it sent before (max_results came with step 2, fix(answers,pipeline,judge,gate): Stack P fixes, step 2 of #228 #274; max_tokens stays 4000). So the Context7 cache key does not change, and the "first runs slower" risk in Answering stack: one implementation for evaluate/benchmark/answers and arms/subjects #228 does not apply to this step.
  • One case changes numbers: Answering stack: one implementation for evaluate/benchmark/answers and arms/subjects #228 D3. When the reranker raises, the context arm now answers from the first 3 raw docs, as DocTreatment does, instead of recording the [FALLBACK: No relevant documentation found] placeholder. Keeping P's old behaviour would need a mode flag on the shared path, so D3 goes with D1. ANSWERING_METHOD_VERSION becomes 3, and the Changed fragment names the runs that are not comparable. Unstamped (v1) and v2 answers files still read and keep their version.
  • --debug-retrieval metadata. raw_count, after_rerank, top_score and fallback_triggered stay. avg_score is gone: nothing in the repo reads it. The metadata now also has arm_kind, library_id and, when a step failed, error (retrieval_failed, rerank_failed).
  • Parity test (tests/test_answering_stack_parity.py):
    • The D1 rows are now shared: A's docs arm runs with P's budget of 4000 and sends ("max_results", "max_tokens"), 3, 4000, the same as P.
    • A new D7 row, retrieval.max_tokens.unset_on_a (4000 vs 8000), pins the default gap.
    • The D3 rows are now shared. The q-rerank judge context row is D5; the D2 judge calls (11/12) and the D9 pairs/deltas follow.
    • RESOLVED lists D1 and D3. The table check requires a row for every other difference and none for a resolved one.

Changed output

answers.v1 / eval.v1: method_version 3 (was 2). With --debug-retrieval, retrieval_metadata before → after:

-{"raw_count": 4, "after_rerank": 0, "top_score": null, "avg_score": null, "fallback_triggered": true}
+{"arm_kind": "docs", "library_id": "uxlfoundation/oneTBB", "raw_count": 4, "after_rerank": 0, "top_score": null, "fallback_triggered": true}

A question whose reranker raised now has a model answer in with_docs instead of the placeholder, and it gets judged. arms.v1 does not change.

Evidence

  • tests/test_answerer_retrieval.py (new) on main's code: 6 of 9 fail. On main, the test of the shared request and kept docs (two configs), the test of a rerank failure, the test of a retrieval failure and the test of the shared reranker choice fail, and so does the test of A's request with no budget, because DocTreatment takes no retrieval_tokens. The parity test fails on its D1/D3 rows. On the branch, all pass. The file checks that the Answerer and DocTreatment send identical get_library_docs arguments and keep the same docs for one config, and that both keep the raw docs when the reranker raises. It also checks the debug metadata flags (fallback_triggered with six docs and with one, but not with an empty source) and that the reranker choice is shared.

  • Mutations, each failing a new test and then reverted:

    • no budget passed from DocTreatment, or from the Answerer
    • keep=5
    • raw_count > 0 → >= 0, and > 1
    • the reranker failure falls back to []
    • the Answerer builds its own SimpleReranker

    CI's mutation step: 12 of 12 mutants killed.

  • make ci-local --offline: 0 failed, 25 passed, 20 skipped (network-only steps). Full suite: 23719 passed, 79 skipped.

  • python scripts/check_growth.py: clean.

  • Not run: a live answers generate / evaluate against a real model and doc source.

Not in this PR

Checklist

  • Tests added/updated and pytest passes: tests/test_answerer_retrieval.py new; the parity, step-2 and method-version tests updated; 23719 passed
  • ruff, mypy, and schema checks pass: make ci-local --offline static and typecheck rows pass, schema_compat passes
  • Docs updated (or N/A): N/A. docs/methodology.md:161 (debug metadata: counts, scores, fallback) still holds; knowledge-runs.md and evaluating-treatments.md say nothing about the retrieval request
  • Self-reviewed per "Before opening a PR" in AGENTS.md: mutations above, other call sites listed above
  • Each new raise/exit and test names the doc, contract or issue it traces to: no new raise; the tests cite Answering stack: one implementation for evaluate/benchmark/answers and arms/subjects #228 step 3 and D3
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header: the test file and the fragment

Answerer._retrieve_docs had its own copy of the arms stack's retrieval.
It now builds a DocTreatment with the Answerer's top_k, reranker and
keep of 3, and passes its retrieval budget as the new optional
DocTreatment retrieval_tokens (sent as max_tokens). The arms commands
leave it unset, so their request is unchanged; the pipeline's request is
unchanged too (max_results=top_k, max_tokens=4000).

One case changes numbers: when the reranker raises, the context arm now
answers from the first 3 raw docs, as arms runs do, instead of the
no-docs placeholder (intel#228 D3). ANSWERING_METHOD_VERSION becomes 3.

The --debug-retrieval metadata keeps raw_count, after_rerank, top_score
and fallback_triggered; avg_score is gone (no reader), and arm_kind,
library_id and error come from DocTreatment.

The parity test's D1 and D3 rows become shared; the arms default of
no retrieval budget stays visible as an "only" row.

Refs intel#228

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…t have --max-tokens

evaluate has no --max-tokens flag; the pipeline always sends 4000.

Refs intel#228

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
… feature

Both stacks send max_tokens; only the arms commands lack a flag to set
it, which is intel#228 D7 and moves with step 5.

Refs intel#228

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The q-rerank judge-context row is D5 now, and the D9 delta moved with
D3 in step 3.

Refs intel#228

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…efault

Answerer.__init__ had its own copy of the semantic-else-lexical choice.
It now calls DocTreatment._default_reranker, so a change to the arms
stack's reranker reaches the pipeline too. The DocTreatment itself stays
per call: its retrieval_tokens comes with each generate_answers call,
and the questions run on several threads.

Refs intel#228

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
@vlad-perevezentsev
vlad-perevezentsev requested a review from a team as a code owner November 19, 2026 12:50
@vlad-perevezentsev vlad-perevezentsev self-assigned this Nov 19, 2026
@exai-bot

exai-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 10 selected item(s).

CI at d9a54b3: 21 passing, 3 skipped.

Review details
  • Commit reviewed: d9a54b3 against merge base 5d4e205
  • Coverage: 10 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 159k tokens (92k from cache), 31s
  • Tool calls: 13 (9 file_read, 2 code_search, 1 ci_status, 1 local_check_results)
  • Pipeline retrieval document treatment and answering stack validation: 10 files

@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.92%. Comparing base (5d4e205) to head (d9a54b3).
⚠️ Report is 4 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #997      +/-   ##
==========================================
- Coverage   95.92%   95.92%   -0.01%     
==========================================
  Files         449      449              
  Lines       59444    59425      -19     
  Branches    10246    10244       -2     
==========================================
- Hits        57020    57001      -19     
+ Misses       1506     1503       -3     
- Partials      918      921       +3     
Files with missing lines Coverage Δ
dokimi/dokimi/defaults.py 100.00% <100.00%> (ø)
dokimi/dokimi/eval/answerer.py 98.89% <100.00%> (+3.35%) ⬆️
dokimi/dokimi/treatments/arms.py 98.21% <100.00%> (+0.02%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Changes needed: 1 must-fix · reviewed 94582e7

Next: @vlad-perevezentsev: fix the 1 must-fix finding; then push for a re-review.

Follow-ups, not blocking (1)
  • dokimi/dokimi/commands/answers.py:168 – answers generate --max-tokens takes any int (type=int, no positive check), so -5 reaches the doc source as max_tokens = -5 on main: _retrieve_docs with a budget of -5 sends max_tokens -5 (main has it too).

Verified on 94582e7: ✅ changed tests: 61 passed, fail on main · ✅ full suite with main merged in: 23943 passed · ✅ merges onto main · ✅ 3 broken variants of the changed code: 3 caught by the tests · 2 mutations tried · 3 edge inputs tried

8 checks behind it, each with its evidence
Area What holds How
Retrieval request The Answerer and DocTreatment send identical get_library_docs arguments and keep the same docs for one config: the changed tests pass on the head (61 passed) tests on the head
Main failures The changed tests fail on main (8 failed), including the shared-request, rerank-failure and retrieval-failure tests same tests on main
Full ci The full make ci-local run passes with main merged in full suite, main merged in
Merge The PR merges onto main with no conflict merge onto main
Numbers Answerer(top_k=0) sends max_results 0 with no error, and with no docs returns none with raw_count 0 ran it, edge input (numbers)
None budget DocTreatment(retrieval_tokens=None) sends no max_tokens, so the client default applies, and keeps the doc that passes the rerank ran it, edge input (none)
Budget mutation Sending max_tokens when no budget is set fails test_doc_treatment_without_a_budget_leaves_the_client_default, so the None branch is pinned broke the code, tests caught it, edge input (none)
Fallback flag Negating the fallback_triggered check fails the changed tests (3 failed), so the flag is pinned broke the code, tests caught it

Comment thread dokimi/dokimi/eval/answerer.py Resolved
antonwolfy
antonwolfy previously approved these changes Nov 20, 2026

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The Answerer now retrieves through DocTreatment with the same request and the same kept docs as the arms stack, and the one behaviour change (D3, raw docs kept when the reranker raises) is stamped as method_version 3 and named in the changelog fragment. No findings of my own.

I agree with @vchamarthi that top_score is 0 instead of None when the reranker raises. New evidence: an Answerer with two raw docs that carry no relevance_score and a reranker that raises returns top_score: 0, after_rerank: 2, error: rerank_failed. It only affects the --debug-retrieval metadata, so I do not count it as blocking.

What I ran, on a Linux review host at 94582e7:

  • make ci-local: 36 passed, 0 failed, 14 skipped (docker and network steps). 23,888 tests passed, 19 skipped. Changed-line coverage 100% (14 lines). Mutation of changed lines: 12 of 12 killed.
  • The parity and retrieval test files (11 tests) and the 214 tests that match answerer, answering or retrieval, all pass.
  • A reproduction of the rerank-failure case with the doc source and reranker mocked.

Checked, no issues

  • Request: DocTreatment.prepare sends max_tokens only when retrieval_tokens is set, so the arms commands send what they sent before and the Answerer sends max_results=top_k plus its budget.
  • Versioning: ANSWERING_METHOD_VERSION is 3, and the unstamped (v1) and v2 handling is unchanged. The commits are all signed off.
  • Changelog: the Changed fragment names the commands and the runs that are not comparable.

@antonwolfy
antonwolfy dismissed their stale review November 20, 2026 13:26

Dismissed: a Must fix comment from @vchamarthi (discussion_r4638717522) is still open, so this PR should not read as approved.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…cs carry no score

The rerank-failure path read a raw doc's missing relevance_score as 0,
so the --debug-retrieval metadata said top_score 0 where main said None
(and the arms docs arm said 0 too). Only scores that exist count now.

Refs intel#228

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
@vlad-perevezentsev

Copy link
Copy Markdown
Contributor Author

🔴 Changes needed: 1 must-fix · reviewed 94582e7 Next: @vlad-perevezentsev: fix the 1 must-fix fin…

@vchamarthi Thanks. On the follow-up: --max-tokens taking any int is on main and outside this PR's goal (one retrieval path); #954 rewrites that flag line as --retrieval-tokens, so the positive-int check fits there or in a small fix after it. I'll list it under "Not in this PR".

@vlad-perevezentsev

Copy link
Copy Markdown
Contributor Author

LGTM. The Answerer now retrieves through DocTreatment with the same request and the same kept docs as the arms stack, and the one behaviour change (D3, raw docs kept when the reranker raises) is sta…

@antonwolfy Thanks for the check and the reproduction. The top_score point is fixed in d9a54b3 (see the inline thread).

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: CONTRACT (head d9a54b3)

  • Contract: changed (count signal only, no file:line)
  • Responsibility: none
  • Dependency: candidate (count signal only, no file:line)
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

I found no additional blocker in the changed behavior. Checked the shared retrieval request, reranking failure and empty results. Focused tests on d9a54b372: 10 passed.

The method-version bump covers raw-document fallback when reranking raises. The debug metadata now leaves an unscored top result null and drops avg_score, as the PR description specifies.

@napetrov
napetrov merged commit 2eff57c into intel:main Nov 22, 2026
24 checks passed
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.

6 participants