Repository navigation
Description
Split from #3902.
Problem: the project has no end-to-end retrieval eval for embedding and reranking changes. The only saved quality numbers use synthetic path-and-symbol queries. The 2026-11-11 study built a 62-query set from 24 issue fixes, 18 census questions and 20 exact identifiers, with 119 relevant files at corpus commit 9208717. The current path scores nDCG@10 0.386; dense search only scores 0.468 (p 0.036). Each retrieval change of #4961 needs the same measurement. The set is docs-heavy: 69% docs chunks against about 51% in production, and one third of its queries are identifiers. Why deferred: this part needs the library of #1928 and a separate eval index. It is too large for the knowledge-base gold set pull request. The original gold set and stale-aware scorer stay in #3902. Acceptance criteria: the 62-query set is checked in as evalset.json beside the knowledge-base gold set, pinned to its corpus commit; each query names its kind and its relevant files with a grade. The B0 and B2 run files of the study are checked in as fixtures; the scorer gives B0 nDCG@10 0.386 and B2 0.567 within 0.001. One scorer computes file-level recall@5, recall@10, MRR@10 and nDCG@10 for all queries, for each kind, and for the natural-language queries (issue_fix and census); it uses pytrec_eval. A paired comparison of two run files gives +0.181 for B2 against B0, with a 95% interval that excludes 0; the interval uses scipy.stats.bootstrap with 10,000 paired samples and a fixed seed, and the p value uses scipy.stats.permutation_test with permutation_type=samples. A run file holds the top 100 chunk ids for each query. The eval index is built from the pinned corpus into a temporary Qdrant collection and deleted after the run; the embedding cache makes a second run cheap. The arms run through the production seams (EmbeddingsEngine, the Qdrant query and the rerank call), not through study scripts. At least 15 natural-language questions about code behaviour are added as their own kind. A CI test scores a recorded run with no network. The report gives the score of the code-behaviour kind apart from the other kinds. git grep finds no hand-written nDCG or MRR function.
Proposed design
Problem statement
The project has no end-to-end retrieval eval for embedding and reranking changes; the only saved quality numbers use synthetic path-and-symbol queries. The 2026-11-11 study built a 62-query set over 119 relevant files at corpus commit 9208717, but the set and its B0/B2 runs are not checked in and no scorer compares two runs with an interval. This change checks in the set, adds at least 15 code-behaviour questions, checks in the B0/B2 runs, adds a pytrec_eval file-level scorer and a scipy paired comparison, and runs each arm through the production embedding, Qdrant and rerank seams against a temporary eval index.
Acceptance criteria
Requirement: Eval set file and pin
The repository SHALL check in tests/fixtures/kb_gold_set/evalset.json with the 62-query study set pinned to corpus commit 92087179.
Scenario: Eval set file and pin
- WHEN A test loads
tests/fixtures/kb_gold_set/evalset.jsonthrough the eval-set loader. - THEN It asserts the loader returns 62 queries of the study kinds,
corpus_commit92087179, a kind for every query, and an integer grade for every relevant file.
Requirement: Study set composition
The 62-query study set SHALL keep its composition of 24 issue_fix, 18 census and 20 identifier queries.
Scenario: Study set composition
- WHEN A test counts the loaded queries of kinds
issue_fix,censusandidentifier. - THEN It asserts 24
issue_fix, 18censusand 20identifierqueries.
Requirement: Code-behaviour questions
The eval set SHALL add at least 15 natural-language questions about code behaviour as their own code_behaviour kind.
Scenario: Code-behaviour count
- WHEN A test counts the loaded queries with kind
code_behaviour. - THEN It asserts the count is at least 15.
Requirement: Query fields
The eval-set loader SHALL reject a query that names no kind or no relevant file with an integer grade.
Scenario: Query fields
- WHEN A test loads a query with no kind and a query whose relevant file has no integer grade.
- THEN It asserts the loader raises a validation error that names the query and the missing field.
Requirement: B0 and B2 fixtures
The repository SHALL check in the B0 and B2 run files of the study as tests/fixtures/kb_gold_set/b0.json and tests/fixtures/kb_gold_set/b2.json.
Scenario: B0 and B2 fixtures
- WHEN A test loads the B0 and B2 fixtures through the run-file loader.
- THEN It asserts both files exist and each query holds at most 100 chunk ids.
Requirement: Fixture nDCG values
The scorer SHALL give B0 nDCG@10 0.386 and B2 nDCG@10 0.567 within 0.001 on the checked-in run files.
Scenario: Fixture nDCG values
- WHEN A test runs the scorer on the B0 and B2 fixtures.
- THEN It asserts B0 nDCG
@10is 0.386 and B2 nDCG@10is 0.567 within 0.001.
Requirement: Scorer metric groups
The scorer SHALL compute file-level recall@5, recall@10, MRR@10 and nDCG@10 with pytrec_eval for all queries, each kind, and the natural-language group of issue_fix and census queries.
Scenario: Scorer metric groups
- WHEN A test scores a recorded run file.
- THEN It asserts each of the four metric keys exists for
all, each kind, andnatural_language.
Requirement: Paired delta and interval
The paired comparison SHALL give +0.181 for B2 against B0 with a 95% interval that excludes 0.
Scenario: Paired delta and interval
- WHEN A test runs the paired comparison on the B0 and B2 fixtures.
- THEN It asserts the B2-minus-B0 delta is 0.181 within 0.001 and the interval lower bound is above 0.
Requirement: Bootstrap settings
The paired interval SHALL use scipy.stats.bootstrap with n_resamples=10000, paired=True and rng=42.
Scenario: Bootstrap settings
- WHEN A test patches
scipy.stats.bootstrapand runs the paired comparison. - THEN It asserts the call passes
n_resamples=10000,paired=Trueandrng=42.
Requirement: Permutation p value
The p value SHALL use scipy.stats.permutation_test with permutation_type='samples', n_resamples=10000 and rng=42.
Scenario: Permutation p value
- WHEN A test patches
scipy.stats.permutation_testand runs the paired comparison. - THEN It asserts the call passes
permutation_type='samples',n_resamples=10000andrng=42.
Requirement: Run file schema
A run file SHALL hold at most 100 chunk ids for each query and a chunks map from each chunk id to its file path.
Scenario: Run file schema
- WHEN A test loads a checked-in run file through the run-file loader.
- THEN It asserts each query holds at most 100 chunk ids and each chunk id maps to a file path.
Requirement: Temporary eval index
The eval runner SHALL build the eval index from corpus commit 92087179 into a temporary Qdrant collection and delete the collection in a finally block.
Scenario: Temporary eval index
- WHEN A test runs the eval runner against the installed
FakeQdrantClient. - THEN It asserts the runner creates a temporary collection, upserts the pinned corpus, and deletes the collection after the run.
Requirement: Production seams
Each arm SHALL run through EmbeddingsEngine, the Qdrant query and the rerank call, not through study scripts.
Scenario: Production seams
- WHEN A test runs one arm with
EmbeddingsEngine, the Qdrant query and the rerank call patched at their production seams. - THEN It asserts each of the three seams is called.
Requirement: Offline CI scoring
A CI test SHALL score a recorded run with no network.
Scenario: Offline CI scoring
- WHEN The CI test scores the checked-in B0 fixture with
socket.socketpatched to raise on any connection. - THEN It asserts the scorer returns the four metrics from the recorded run.
Requirement: Code-behaviour report
The report SHALL give the score of the code_behaviour kind apart from the other kinds.
Scenario: Code-behaviour report
- WHEN A test renders the report for a scored run.
- THEN It asserts a
code_behavioursection and a separate section for each other kind.
Requirement: No hand-written metrics
The scorer MUST define no hand-written nDCG or MRR function.
Scenario: No hand-written metrics
- WHEN
git grep -nE 'def .*(ndcg|mrr)'runs oversrc/. - THEN It returns no match.
Requirement: Embedding cache reuse
A second eval run SHALL reuse the embedding cache.
Scenario: Embedding cache reuse
- WHEN A test runs the eval runner twice with the same corpus and a fake embedding cache.
- THEN It asserts the second run makes no embedding request.
Requirement: File-level scoring
The scorer SHALL count a file once at the best rank of its chunks in the file-level run.
Scenario: Two chunks of one file
- WHEN A test scores a run whose top two chunk ids map to the same file.
- THEN It asserts the file appears once at rank 1, and the next distinct file is rank 2.
Requirement: Statistics dependency
The project SHALL declare scipy as a direct dependency in pyproject.toml and resolve it in uv.lock.
Scenario: Dependency check
- WHEN
uv run deptry srcruns after the change. - THEN It reports no missing or unused dependency for
scipy.
Existing Tool Considered
No alternatives check has run. pytrec_eval from pytrec-eval-terrier (MIT, terrierteam) computes recall, MRR and nDCG from one qrels and one run. scipy.stats.bootstrap(paired=True) and scipy.stats.permutation_test(permutation_type='samples') compute the paired 95% interval and p value. Neither library supplies the 62-query set, the code-behaviour questions, the B0/B2 fixtures, the chunk-to-file map, the temporary Qdrant index, the production-seam runner or the report. The project builds those for about 60k tokens and 2 days.
Key questions
- Which library computes the file-level retrieval metrics?: Use pytrec_eval from pytrec-eval-terrier. It computes recall, MRR and nDCG from one qrels and one run. The scorer maps chunk ids to file paths before it calls the library. The project already declares pytrec-eval-terrier and numpy. (best practice) [sources: pyproject.toml, tests/ai/benchmark/test_retrieval_metrics.py]
- Chosen: pytrec_eval. It computes trec_eval measures from one qrels and one run, and the project already declares it.
- Rejected: Hand-written metrics. The issue forbids hand-written nDCG and MRR functions, and the project would keep and test that code.
- Rejected: scikit-learn metrics. It has no TREC qrels and run interface for graded file-level relevance.
- Which library computes the paired bootstrap interval and permutation p value?: Use scipy.stats.bootstrap with paired=True, n_resamples=10000 and rng=42 for the 95% interval. Use scipy.stats.permutation_test with permutation_type='samples', n_resamples=10000 and rng=42 for the p value. SciPy 1.18.1 is locked through statsmodels. (best practice) [sources: uv.lock, pyproject.toml]
- Chosen: scipy.stats. It provides bootstrap(paired=True) and permutation_test(permutation_type='samples'), and scipy is already locked.
- Rejected: NumPy manual resampling. It needs custom resampling code that the project must keep and test.
- Rejected: statsmodels. It has no permutation_test API with permutation_type='samples'.
- Which seed parameter do the SciPy calls use in the locked version?: Use
rng=42. The locked SciPy 1.18.1 takes therngparameter;random_stateis the old name. [sources: uv.lock] - Which fixed seed should the paired bootstrap and permutation test use?: Use 42 as one module constant shared by both calls. It matches the random_seed=42 default of the benchmark's evaluation-task sampler. (best practice) [sources: src/devops_cli/ai/benchmark/document_chunker.py:319]
- Chosen: 42. It matches the random_seed=42 default of the benchmark's evaluation-task sampler.
- Rejected: 20261111. It records the study date but no project convention, and it is a magic number.
- Rejected: 0. It looks like an unset default.
- How does the offline scorer map chunk ids to files?: The run file includes a
chunksmap from each chunk id to its file path. The scorer maps each chunk to its file and keeps the file at the best rank of its chunks. The qrels take the grade of each relevant file from the eval set. It then scores both with pytrec_eval. (best practice) [sources: src/devops_cli/ai/rag/indexer.py, src/devops_cli/ai/rag/embeddings.py:441]- Chosen: Embed the chunk map in the run file. One fixture is self-contained; the CI test needs no network or chunk-id parsing.
- Rejected: Parse the file path from the chunk id. The chunk id format is not a contract; a format change would break scoring.
- Rejected: Use a separate chunk map file. It adds a second fixture and a test that the two files agree.
- How does the eval runner isolate the eval index?: Build a temporary Qdrant collection from corpus commit 9208717 through the production indexer, and delete it in a
finallyblock. The tests use the installedFakeQdrantClient. (best practice) [sources: src/devops_cli/ai/rag/indexer.py, tests/support/fakes/qdrant.py, docs/TESTING.md:275]- Chosen: Temporary Qdrant collection. It isolates the eval corpus; production collections stay unchanged, and the fake client holds the contract.
- Rejected: Permanent eval collection. It needs cleanup and can hold stale data.
- Rejected: In-memory fake only. It does not exercise the production Qdrant query seam.
- Which run file format should the fixtures use?: Use JSON. The
queriesobject maps each query id to at most 100 chunk ids. Thechunksobject maps each chunk id to its file path. pytrec_eval accepts dicts, so the loader builds its run and qrels from the JSON. (best practice) [sources: pyproject.toml, src/devops_cli/ai/rag/indexer.py]- Chosen: JSON. It is easy to check in and parse offline; pytrec_eval accepts dicts.
- Rejected: TREC run text. It holds scores, not the chunk-to-file map the fixture needs.
- Rejected: CSV. Nested per-query lists are awkward and less explicit.
- Where do evalset.json and the B0/B2 run fixtures live?: Use
tests/fixtures/kb_gold_set/evalset.json, beside the knowledge-base gold set, withcorpus_commit92087179. The B0 and B2 runs aretests/fixtures/kb_gold_set/b0.jsonandb2.json. (best practice) [sources: tests/support/paths.py:22]- Chosen: Beside the gold set. The issue says beside the knowledge-base gold set, and
tests/support/paths.pysetsFIXTUREStotests/fixtures. - Rejected: Separate eval fixture directory. It splits the two retrieval fixtures and departs from the issue.
- Rejected: Inside the benchmark package. The tests read fixtures from
tests/fixtures, not fromsrc/.
- Chosen: Beside the gold set. The issue says beside the knowledge-base gold set, and
- Which production seams should each arm use?: Use
EmbeddingsEngine, the Qdrant query and the rerank call. The eval runner calls these production seams, not study scripts. (best practice) [sources: src/devops_cli/ai/rag/embeddings.py:442, src/devops_cli/ai/rag/qdrant.py, src/devops_cli/ai/rag/indexer.py]- Chosen: Production seams. The issue requires the arms to run through the same seams as production, so the eval measures the shipped path.
- Rejected: Study scripts. They would measure a copy and drift from production.
- How does the project declare the statistics dependency?: Add
scipyto[project].dependenciesinpyproject.tomland resolve it inuv.lock.uv run deptry srcthen reports no missing or unused dependency forscipy. (best practice) [sources: pyproject.toml, uv.lock]- Chosen: Direct dependency. The scorer imports scipy, so deptry needs a direct declaration.
- Rejected: Transitive dependency through statsmodels. deptry reports a missing dependency for an import that only a transitive package supplies.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
devops-cli-service commentedon Nov 13, 2026
Both cover retrieval evaluation, but #3902 keeps the knowledge-base gold set and the stale-aware scorer, and the candidate adds the 62-query project set.devops-cli-service commentedon Nov 18, 2026
Refine cannot set this item to Ready at dfae9b5 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
devops-cli-service commentedon Nov 19, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.