Skip to main content

Indexing techniques that make vector search scale

An approximate index is a way to decide where to look first and when to stop looking. Different indexes make that decision differently. An index can miss a nearby vector because it never inspects the list or graph region that contains it.

We'll compare two designs: divide the space into regions, or travel through a graph of nearby points. Your task is to choose which setting to change when a search is fast but misses relevant neighbours.

Search some regions

An inverted file index, often called IVF, groups vectors around representative centres. Those centres are usually learned by clustering a sample of the data. A vector is assigned to a centre, and its ID goes into that centre's list.

For a query, first find nearby centres. Then compare against vectors in their lists. Searching fewer lists avoids inspecting the whole collection.

Imagine centres at 0 and 10 on a line. The boundary between their regions is 5. A query at 4.9 belongs closer to the left centre, while a document at 5.1 belongs closer to the right.

Their distance is only 0.2. If we search only the left list, we miss that document despite its proximity.

This is a one-dimensional example; the vertical offsets only keep the two markers visible. The region boundary is a routing choice, not a wall between meanings. Nearby points can fall into different lists.

Choose a repair: should we search an additional nearby list, or round distances to more decimal places?

Search another list. The error was candidate selection. More accurate arithmetic inside the wrong list won't find the missing point.

Separate the build from the query

Two common IVF settings are the number of lists, often called nlist, and the number searched for each query, often called nprobe.

More lists can make each list smaller, but require more centres and change the routing problem. That is a build-time choice. Changing it generally means rebuilding the index.

Increasing nprobe spends more work per query examining lists. It tends to improve recall while increasing latency.

If you request k neighbours, recall is the fraction of the exact search's k nearest neighbours that the approximate search recovers for the same query.

Searching every list with full-vector scoring approaches exhaustive search, removing the reason to use IVF for that query.

The clustering sample matters. If it poorly represents the corpus, the regions may be uneven or unhelpful. Fresh data can also change the distribution. Watch search behaviour as the collection evolves.

Follow a graph instead

IVF starts by choosing lists. A graph index starts from stored points and follows links to other candidates.

HNSW, short for Hierarchical Navigable Small World, connects nearby vectors in a graph. A graph consists of points, called nodes, and links between them.

Its upper layers contain fewer points and provide longer-range movement. Search starts high, moves toward the query through the links, and descends into denser layers. The bottom layer refines the candidate set.

This is an analogy to navigation, not a guarantee that every move reaches the globally nearest point. Search explores a limited set of possibilities. If that exploration is too narrow, it can miss better neighbours.

The setting commonly named efSearch or ef_search controls the search candidate budget. Increasing it generally improves recall at the cost of more work. It is distinct from k, the number of results you return.

If the user asks for five results, the search may need to explore many more than five candidates to choose them well.

Links cost memory

HNSW also has build-time settings. M controls graph connectivity, and efConstruction controls construction-time exploration. More links consume more memory; more construction work can build a better graph but takes longer.

The exact meaning and bounds of each parameter depend on the implementation. Read the documentation for the database you use before copying values from another library.

Diagnose this situation: a finished HNSW index fits in memory and builds acceptably, but your benchmark misses neighbours. What is a reasonable first experiment?

Increase the query search budget and remeasure recall and latency. If that cannot meet both requirements, revisit build settings, index choice, or memory. Rebuilding everything is not the first action every failed query needs.

Compression is another axis

IVF and HNSW decide which candidates to inspect. Quantization decides how stored vectors are represented and sometimes how cheaply they can be scored.

They can be combined. An IVF-PQ index routes to lists, then uses product-quantized codes within those lists. It can lose neighbours through both limited list probing and approximate scoring.

To understand a regression, compare stages. First try fuller candidate exploration. Then test full-precision scoring where supported. Changing one factor at a time helps locate the source of error.

Keep a small tuning record

For each tested configuration, record recall against exact search, latency under realistic concurrency, index size, build time, and update behaviour. Include the filters the product needs.

Don't turn one benchmark winner into a universal default. A memory-constrained archive and a frequently updated catalogue can prefer different trade-offs even with the same embedding model.

Close your notes and explain the difference in one sentence: IVF chooses lists to scan; HNSW chooses graph paths and candidates to explore. If you can say what each might skip, you can make a deliberate tuning decision.

Lesson notes

Follow a nearby document across an IVF boundary, then compare how IVF and HNSW trade search effort for recall.

Key ideas

  • IVF: coarse clustering + probing
  • HNSW: skip-list-of-graphs intuition, greedy descent
  • Index params — the recall/latency/memory triangle

Further reading