Skip to content
BytePatterns

Approximate Neighbours

AI & ML: lesson 19 of 32

Walk a graph of vectors instead of comparing all of them.

Lesson 19 of 32 · 5 min

Approximate Neighbours

Step 1 of 9

Exact search compares the query with every stored vector. At a billion vectors that is the whole cost.

The Idea

Exact search compares the query with every stored vector. A graph index instead links each vector to a few neighbours, enters at one node, and repeatedly hops to whichever neighbour is closer. Layers of increasingly sparse long-range links let it cross the space in a handful of hops.

Real-World Example

Finding a house in a strange city by asking at each corner which way is closer, rather than knocking on every door. You arrive fast; occasionally you stop one street early.

The Tradeoff

You trade recall for speed, and the dial is explicit: a wider search keeps more candidates alive, finds more true neighbours, and costs more. Building the graph is slow and memory-hungry, deletes leave dangling links, and a freshly inserted vector is invisible until the index takes it.

Your turn

Put the steps in the right order.

  1. Hop to whichever linked neighbour is closer to the query
  2. Enter the top, sparsest layer at a fixed node
  3. Return the best candidates kept along the way
  4. Drop into the dense bottom layer once no neighbour improves

Mini quiz

1 / 3

An approximate index is called approximate because it:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.