Log inStart free
LESSON 22.C2 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

ANN indexes compared

Four ways to find the 3 nearest points, side by side on one toy.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 22.C2 · INDEX BAYQ2 · BRUTE FORCE 200 DISTANCES · 3 OF 3
01
Stage 1 of 6 · Brute force
brute-force search measures q2's distance to all 200 points. The 3 nearest are exact: p158, p123 and p50.
Explain it simply

Brute force is the honest way. A faint line runs from q2 to every one of the 200 points. It sorts all 200 distances and keeps the 3 shortest, filled in blue. Every index after it is checked against these 3.

Four panels show the same 200 points. In the brute-force panel, lines join q2 to every point. The 3 nearest are p158, p123 and p50.

points, querysearch, found, distancesindex data, memorytrue 3missed
Brute forceevery pointHNSW · 22.10M 4, ef 3IVF · 22.118 cells, 1 probePQ · 22.128 centroids, no rerankdistancesBrute forceHNSWIVFPQ200brute force: 200 distances; 3rd nearest d(q2, p50) = 12.48Brute forceevery pointHNSW · 22.10M 4, ef 3IVF · 22.118 cells, 1 probePQ · 22.128 centroids, no rerankdistancesBrute forceHNSWIVFPQ200brute force: 200 distances; 3rd nearest d(q2, p50) = 12.48
Toy: 200 2-D points, 5 queries, K = 3; 4 B per number or id; PQ codes in bits
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
d(q,p)=(qx−px)2+(qy−py)2\sy{d}{out}{d}(\sy{q}{data}{q}, \sy{p}{data}{p}) = \sqrt{(q_x - p_x)^2 + (q_y - p_y)^2}
d(q2,p50)=(26−38.41)2+(46−47.35)2=12.48d(\mathrm{q2}, \mathrm{p50}) = \sqrt{(26 - 38.41)^2 + (46 - 47.35)^2} = 12.48

The straight-line distance from the query to one point.

Common mix-ups

MYTHThe smallest index is also the fastest.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01At high effort, do all three indexes find q2's 3 nearest points? Do distances rise from low effort?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.