ContentsThe library

Finding Things by Meaning

You Cannot Compare the Question Against Everything

Last timeExact Words and Rough Meaning

Comparing a question against every piece is simple, correct and impossible at scale. The structures that avoid it have build times, memory costs and rules about changing them.

A question has become a list of numbers. There are ten million pieces in the

index, each with its own list. The obvious thing to do is compare the question

against all ten million and keep the best ten.

This works. It is also the only method that is exactly correct, and for a

collection of fifty thousand pieces it is the right choice: a few lines of code

with no index to build, no parameters and no failure modes.

At ten million it costs a few billion multiplications per question. That is a

substantial fraction of a second of a machine's full attention, on every single

question, before anything else has happened.

FIG 1Comparisons per question when the space is divided up
pieces in the collection
partitions the collection was divided into in advance
partitions actually opened for this question
comparisons done: the members of the opened partitions, plus one per representative to decide which to open
With ten million pieces in four thousand partitions, opening eight of them costs twenty thousand comparisons plus four thousand to choose, against ten million. The saving is a factor of four hundred, and the cost is every question whose answer sat in a partition that was not opened.

Two ways to avoid it

Notice what has been given up. The exact method returns the true nearest pieces

by construction. A partition index returns the nearest pieces among those it

happened to look at, and there is no way to know from the result whether

something better was sitting in an unopened partition. The answer is no longer

correct, only usually correct, and the word usually is now a parameter you set.

The second family does not divide the space at all. It joins each piece to a few

dozen of its neighbours, forming a graph, and searches by walking.

FIG 2A graph walk for one question
stephops taken so fardistance from the questionneighbours checked so farwhat happened
101.420Start at an arbitrary entry point. The distance is roughly what you would expect between two unrelated pieces.
230.8196Three hops in, already in a broadly relevant region of the space.
370.44224Seven hops. Close now, and the improvements per hop are getting small.
4110.39352No neighbour of the current piece is nearer than the current piece. The walk stops here, having compared against three hundred and fifty two pieces rather than ten million.
4 steps
Eleven hops for ten million pieces. Doubling the collection adds roughly one hop, which is why this family scales well. The last row is also the failure mode: stopping because no neighbour improves is not the same as having arrived at the best piece.

Memory, not time

Having fixed the time problem, a second one becomes visible, and on real

deployments it binds first.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Step That Decides Everything After It
  2. 02The Decision Made Before Anything Is Searchedopening only
  3. 03Neither Side of the Comparison Is Textopening only
  4. 04The Two Methods Fail on Opposite Questionsopening only
  5. 05You Cannot Compare the Question Against Everythingyou are here
  6. 06One Knob, and What It Is Really Selling Youopening only
  7. 07The Stage That Can Afford to Be Slowopening only
  8. 08A Hundred Questions You Wrote Yourselfopening only

Read alongside