• Beyond ranking: picking options that are relevant and varied at the same time, learning from every choice and being able to explain every number
dpp: Good and Different Flights with a Determinantal Point Process
Table of Contents
- Context
- Relevance and diversity: the concept
- Practical example: two flights and a determinant
- How it’s built
- Explaining every number
- Limitations
- Reflection
- Sources and recommended reading
Something curious happens to me when I search for a flight: the first eight options are almost never eight options. They’re the same one with small variations: the same airline, the same time slot, ten euros up or down. Technically they’re well ranked. In practice, they don’t help me decide.
That small annoyance was the starting point of dpp, a flight search engine that tries to answer a specific question: how do you pick results that are good and, at the same time, different from each other?
1. Context
The classic way to rank results is simple: give each item a score, sort, and keep the top ones. It works well when each option is worth the same no matter what sits next to it. But flights aren’t like that. The value of an option depends on the ones around it: an eighth flight almost identical to the previous seven adds almost nothing.
In recommendation and search systems this is known as the diversity problem. Some solutions penalize similar results after sorting, like MMR (Carbonell and Goldstein, 1998). But there’s a more elegant way to frame it, in my view: the Determinantal Point Process (DPP), which comes from probability and physics and was popularized in machine learning by Kulesza and Taskar in 2012.
2. Relevance and diversity: the concept
A DPP needs two ingredients:
- the relevance of each flight,
q, which in dpp comes from a learned model, - and the similarity between each pair of flights,
S, from 0 (nothing alike) to 1 (identical).
With that you build a matrix, the kernel L, where each cell is L[i][j] = q[i] · S[i][j] · q[j]. And here comes the key idea: the DPP gives every set of flights a score proportional to the determinant of its submatrix.
The determinant has a very intuitive geometric reading: it’s the volume the vectors take up. If two vectors point in almost the same direction, the volume they enclose is almost zero. If you read the post on semantic proximity, the same idea comes back here: similar things barely take up space. And the more relevant the flights are, the longer those vectors are and the more volume they take up.
That’s why a single number balances both things at once: it grows with relevance and collapses when two flights are too alike.
3. Practical example: two flights and a determinant
With just two flights, the determinant boils down to a very simple expression: q1² · q2² · (1 − s²), where s is how alike they are. If they’re identical, s = 1 and the determinant is 0, however good they are.
Let’s say we already have flight A, the most relevant one (q = 1.0), and we’re torn between adding B or C:
- B is almost as good (
q = 0.9) but almost the same as A (s = 0.95), - C is worse (
q = 0.7) but quite different (s = 0.3).
package main
import "fmt"
func det2(qa, qb, s float64) float64 {
return qa * qa * qb * qb * (1 - s*s)
}
func main() {
fmt.Printf("A+B: %.3f\n", det2(1.0, 0.9, 0.95))
fmt.Printf("A+C: %.3f\n", det2(1.0, 0.7, 0.30))
}
A+B: 0.079
A+C: 0.446
C wins, even though it’s less relevant. That’s exactly what a person would do: if you already have a 12:40 flight with Air Europa, another one at 12:50 with Air Europa doesn’t help you; an afternoon flight with another airline does.
With more flights the problem gets harder, because finding the best subset is very expensive. dpp uses the greedy approximation by Chen, Zhang and Zhou (2018): in each round it adds the flight that grows the determinant the most, and it keeps a Cholesky decomposition so it doesn’t recompute everything from scratch.
4. How it’s built
The engine is written in Go. For each search it asks a provider for about forty flights (for now, a service that generates realistic flights), applies a travel policy that drops red-eye flights, flights with more than two stops and anything over twice the cheapest fare, and describes each candidate with four features relative to that search: how much more it costs than the cheapest, how many extra hours it takes, how many stops it has and whether it leaves in the early hours.
Those features go through a model that produces the relevance, they’re combined with the similarity, and the greedy algorithm picks the results.
What I really cared about was closing the loop. Every result page and every choice is published as an event to Kafka, and a set of Go jobs turns them into training data in layers: the raw log, consolidated sets with what was chosen in each search, and finally a table ready for training. A Python trainer fits a conditional logit model and publishes the new version to a model registry. The engine hot-reloads it and can split traffic between a champion and a challenger model, with the option to roll back instantly.
To know whether training works, I built a simulator of travelers with known preferences: they dislike paying more (−3), extra hours (−0.25), stops (−1.2) and leaving in the early hours (−1.5). After 1,687 searches, the model learned −2.80, −0.25 and −1.19 for the first three.
And the fourth? The model learned 0. At first I thought it was a bug, but it made perfect sense: the travel policy drops early-morning flights before they reach the ranking. The model never saw one, so it couldn’t learn anything about them.
A model can’t learn from what it never sees.
It all runs on my homelab: every push builds the images in GitHub Actions and a runner inside the cluster rolls them out. Since the demo is public, inputs are capped, each service has its own CPU and memory ceiling, and the metrics tell me whether anyone uses it.
5. Explaining every number
The part I’m happiest with isn’t the algorithm, it’s the explanation. Below the results, the page walks through the 18 steps of that search with the engine’s real numbers: what the provider returned, what the policy filtered out, each flight’s features, the model’s weights, the kernel, the determinant and every round of the algorithm. And every number can be clicked to see its formula, the values that were plugged in and the step it comes from.

The last step: what the DPP picked, why, and what a relevance-only ranking would have shown instead.
I built it for myself before anyone else. In The New Loom I wrote that delegating execution is one thing and delegating judgment is something else entirely. The same goes for a model: if I don’t understand why it picks what it picks, I’m delegating my judgment to it. And along the way, seeing the real numbers of every step brought to light bugs that metrics alone would have hidden.
6. Limitations
I don’t want to sell it as something it isn’t:
- the data is synthetic: both the provider and the travelers are simulated, and real behavior is much noisier,
- the model is deliberately simple, with only four features,
- similarity isn’t learned: I compute it from profiles I define myself, such as the airline, the departure slot, the stops and the price band,
- and the public demo doesn’t store events, on purpose, so it doesn’t learn from its visitors.
7. Reflection
dpp started as an experiment with an algorithm I found beautiful and ended up as a complete system: serving, events, data, training, a model registry and deployment.
I take away three ideas. First, that diversity is a modeling decision, not a filter: putting it in the kernel, instead of in an afterthought, keeps the result explainable. Second, that explaining pays off. And third, that it’s worth closing the loop as early as possible: having events, data and a model registry from day one is what turns a demo into a system that can improve.
8. Sources and recommended reading
- Kulesza, A. and Taskar, B. (2012). Determinantal Point Processes for Machine Learning. arxiv.org/abs/1207.6083
- Chen, L., Zhang, G. and Zhou, H. (2018). Fast Greedy MAP Inference for Determinantal Point Process to Improve Recommendation Diversity. NeurIPS. arxiv.org/abs/1709.05135
- Carbonell, J. and Goldstein, J. (1998). The Use of MMR, Diversity-Based Reranking for Reordering Documents and Producing Summaries. SIGIR.