← Back to Pull requests

[metric] Evaluate ndcg, map and pre without a cutoff over the whole list #12794

Closed
unknown closed this pull request without merging on Nov 05, 2026 12:55 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 18:27 UTC
Author

With eval_metric="ndcg", "map" or "pre", the score only covers the top 32 documents of each query. The name has no @n, and the docs describe @n as the way to cut off the list. EvalRank sets a pair method only when @n is given. Otherwise it keeps the topk default (since #8984), and TopK() falls back to DefaultK(), which is 32. Lists of up to 32 documents are not affected.

The same name also means the whole list elsewhere: with lambdarank_pair_method="mean", the objective reports its default metric as ndcg and passes that pair method along, so TopK() is unbounded.

import numpy as np, xgboost as xgb

rng = np.random.default_rng(0)
X = rng.normal(size=(100, 4))
y = rng.integers(0, 4, size=100)
d = xgb.DMatrix(X, y, qid=np.zeros(100, dtype=np.int32))

history = {}
xgb.train(
    {"objective": "rank:ndcg", "eval_metric": ["ndcg", "ndcg@32", "ndcg@100"]},
    d, 5, evals=[(d, "train")], evals_result=history, verbose_eval=False,
)
print({k: round(v[-1], 6) for k, v in history["train"].items()})

| | ndcg | ndcg@32 | ndcg@100 |
|---|---|---|---|
| master | 0.83272 | 0.83272 | 0.945334 |
| this PR | 0.945334 | 0.83272 | 0.945334 |

This PR uses the mean pair method for these metrics when no cutoff is given, which makes TopK() unbounded. Only the metric's own parameter changes, so training is not affected. The default metric of the topk objectives is still ndcg@32.

This does change the reported value of plain ndcg, map and pre on queries with more than 32 documents, which also affects early stopping on them. Anyone who wants the old value can ask for @32.

The cutoff regression is folded into the existing shared C++ precision, NDCG and MAP checks using fixed predictions for a 64-document query. The existing NDCG JSON test checks objective default metric configuration. All seven selected local/distributed CPU cases fail without the fix and pass with it; applicable pre-commit hooks pass. The shared helpers also run in CUDA builds, but GPU execution was not run locally.

Previously reported macOS CPU validation: test_ranking.py, test_eval_metrics.py, test_early_stopping.py, test_callback.py, the ranker tests in test_with_sklearn.py and the metric, ranking and learner gtests pass on macOS CPU. I did not run the GPU path.

Diff: 290 lines (+217 / -73) across 3 files Reviewer: RAMitchell Review duration: 1107m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 290 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.339
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12794"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.9% (MEDIUM) · Higher = larger blast radius
39.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.7% · Safe to merge
15.7%
Repository