Log inStart free
LESSON 22.10 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

HNSW

Watch a search drop through graph layers to find the 3 nearest points.


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.10 · INDEX BAYM 4 · 4 LAYERS · 200/50/13/3
01
Stage 1 of 6 · Random levels
HNSW gives each point a random top layer. About 1 in 4 rises to each next layer.
Explain it simply

You see the same 200 points in every panel. A teal dot means the point lives on that layer. Each point draws one random number, and only a few win a place higher up. So each layer holds about a quarter of the layer below it.

4 layers hold 200, 50, 13, 3 points, from layer 0 up.

points, querylinksentry pointsearch path, resultstrue 3 nearestmissed
layer 3 (top)3 pointslayer 213 pointslayer 150 pointslayer 0200 points200 → 50 → 13 → 3 points: about 1 in 4 risesm_L = 1/ln 4 = 0.72layer 3 (top)3 pointslayer 213 pointslayer 150 pointslayer 0200 points200 → 50 → 13 → 3 points: about 1 in 4 risesm_L = 1/ln 4 = 0.72
Toy: 200 2-D points and 5 queries, shared with 22.C2
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
ℓ=⌊−ln⁡u⋅mL⌋,mL=1/ln⁡M\sy{l}{param}{\ell} = \lfloor -\ln \sy{u}{ink}{u} \cdot \sy{ml}{param}{m_L} \rfloor,\quad \sy{ml}{param}{m_L} = 1/\ln \sy{m}{param}{M}
mL=1/ln⁡4=0.72; layers 200,50,13,3m_L = 1/\ln 4 = 0.72;\ \text{layers } 200, 50, 13, 3

A random draw sets each point's top layer.

Common mix-ups

MYTHHNSW always returns the exact nearest points.

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

Predict, then reveal
3 CHECKS · PRO
Q01With M at 4, if ef drops from 8 to 3, does q2 still find all 3 true nearest?

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.