Learning-to-Rank, In Full Depth
Search, recommendation ranking, and ad ranking are not classification problems and not regression problems — the thing that actually matters is the order of a list, and optimizing accuracy or MSE on individual item scores doesn't directly optimize for that at all. Learning-to-Rank (LTR) is the family of methods built to close that gap.
Why Ranking Isn't Classification or Regression
Predicting "will the user click this" per item (see Recommender Systems — CTR Prediction) is a reasonable input to ranking, but training a classifier to predict clicks and then sorting by predicted probability isn't the same as directly optimizing ranking quality:
- A classifier trained on pointwise log-loss treats every item's prediction error equally — but a ranking error at position 1 (showing the wrong top result) matters far more to a user than an error at position 47.
- Classification/regression metrics (accuracy, AUC, MSE) don't directly measure "is the list in the right order" — two models with identical AUC can produce meaningfully different orderings of the top- results, which is the only part of the list most users ever see.
Three Formulations
Three different ways to turn "rank this list well" into something a model can actually be trained on — each one exists because the previous one gets something importantly wrong.
Pointwise
What is it? The simplest option: forget ranking is even happening, and just predict a relevance score for each item on its own.
How does it work? Train an ordinary regressor or classifier — exactly like supervised learning anywhere else — to predict a relevance score (or click probability) per item, independent of every other item in the list. Sort the final list by that predicted score.
Why is it useful? It's simple, and reuses standard ML machinery directly — no special ranking infrastructure needed, just a regressor or classifier you already know how to train.
Limitation: The model never sees the list as a list. A pointwise loss treats every item's prediction error equally, but a ranking error at position 1 (showing the wrong top result) matters far more to a user than an error at position 47 — the training objective simply doesn't know that.
Pointwise optimizes independent scores, but ranking quality is fundamentally about relative order — which is exactly what pairwise training targets directly.
Pairwise
What is it? Reframe ranking as classification over pairs of items, instead of scoring each one alone.
How does it work? For two items and where is known to be more relevant, train the model to predict . RankNet is the canonical method: it turns the score difference between a pair into a probability via a sigmoid, and trains with cross-entropy on whether the "more relevant" item actually scored higher.
Why is it useful? This directly optimizes for getting relative order right, which is much closer to what ranking quality actually means than an independent per-item score ever was.
Limitation: Pairwise training still doesn't see the whole list at once — it optimizes a huge number of independent pairwise comparisons, with no direct connection to how a real ranking-quality metric like NDCG (below) scores the final, complete ordering.
Pairwise gets relative order right pair by pair, but the metric that's actually reported (NDCG) is computed over the whole list — listwise training closes that last gap by optimizing for it directly.
Listwise
What is it? Optimize a ranking-quality metric directly over the entire list at once, rather than decomposing into independent pairs.
How does it work? LambdaMART (gradient-boosted trees, see Boosting) is the most widely deployed listwise-style method in production search/ranking systems: it trains with "lambda gradients" that weight each pairwise comparison by how much swapping that pair would actually change the list's NDCG — so a swap that would meaningfully improve the top of the list matters more to training than one buried at position 40.
Why is it useful? It captures listwise ranking quality — the thing actually being reported and optimized for in production — while still training with the well-understood, efficient machinery of gradient boosting, not a fundamentally different modeling approach.
In code, via LightGBM's LGBMRanker, the standard implementation of LambdaMART:
Limitation: Listwise methods are more complex to train and reason about than pointwise or pairwise, and LambdaMART's lambda gradients are a well-tested heuristic approximation to directly optimizing NDCG, not a mathematically exact gradient of it.
Ranking Evaluation Metrics
These are worth knowing precisely, since "which metric" materially changes what a ranking model is optimized toward:
- Precision@k / Recall@k: of the top results, what fraction are relevant (Precision@k); of all relevant items, what fraction appear in the top (Recall@k) — same definitions as Model Evaluation & Metrics, applied to a ranked list's top slice.
- MRR (Mean Reciprocal Rank): for each query, take , then average across queries. Rewards getting a relevant result high up quickly — a good fit for queries with one clear right answer (a navigational search query, "find the answer").
- NDCG (Normalized Discounted Cumulative Gain): the most complete standard ranking metric, and the one most listwise methods (including LambdaMART) directly target:
- DCG: — sums each result's relevance (which can be graded, not just relevant/irrelevant — a 0-4 relevance scale, say), discounted logarithmically by position, so a highly relevant result buried at position 20 contributes far less than the same result at position 1.
- NDCG: DCG divided by the ideal DCG (the DCG of the best-possible ordering of the same result set) — normalizing to so NDCG is comparable across queries with different numbers of relevant results, where raw DCG wouldn't be. Real DCG/NDCG, recomputed live as you reorder the list:
In code, via sklearn.metrics.ndcg_score — takes graded relevance labels and predicted scores, handles the discounting and ideal-DCG normalization described above internally:
- Choosing between them: MRR when there's typically one right answer near the top; NDCG when relevance is graded and the quality of the entire top- ordering matters, not just whether one good result appeared somewhere in it — NDCG is the default in most modern search/ranking evaluation for exactly this completeness.
Feature Engineering for Ranking
LTR models are almost always gradient-boosted trees (LambdaMART) or a deep ranking network fed a rich, heavily engineered feature set per query-item pair — the modeling technique matters less than getting these features right:
- Query-item features: text match score (BM25, see RAG), embedding similarity, category match.
- Item features: popularity, recency, price, historical CTR.
- User features: personalization signals — past behavior, stated preferences, session context.
- Context features: time of day, device, location — relevance is often genuinely contextual, not a fixed property of the item.
Where This Shows Up
- Search engines: ranking documents/pages by relevance to a query — the original LTR use case.
- Recommendation ranking: the ranking stage of the retrieval→rank→re-rank pipeline in Recommender Systems.
- Ad ranking: ordering ads by a combination of predicted CTR and bid price.
- RAG reranking: re-ordering retrieved chunks by relevance before feeding them to an LLM — see RAG — Re-ranking with Cross-Encoders, the same pairwise/listwise ranking principles applied to retrieved text chunks instead of search results.
Back to Supervised Learning for the full overview, or Model Evaluation & Metrics to continue the Machine Learning roadmap.