Ask what is needed: the top ten
Why it matters Specs describe the general case; callers use a small part of it. Building the general case is often the expensive part, and nobody asked for it.
Search results are ranked by a learned relevance model. The model is pairwise: it can only say which of two results is more relevant, and every comparison is a billed model call. Scores are never equal.
The ticket says: "rank(results) returns all results sorted best first." Here is the only code that calls it:
def homepage_widget(results):
return [r["id"] for r in rank(results)[:10]]The data
results = [{"id": "doc000001", "score": <Score>}, ...]
# a["score"] < b["score"] is one model call. So is >, ==, and so on.
# -s gives a Score that compares the other way round (no call).Write rank(results) for the widget above. results is a list of dicts with "id" and "score"; scores can only be compared with each other, and every comparison counts. The first ten items you return must be the ten highest scores, best first (fewer if there are fewer results); the widget never looks past them. Budget: 60,000 results may use at most 250,000 comparisons.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.