The exact answer, and what it costs
A brute-force scan computes the distance to every stored vector and keeps the smallest, which is exact by construction.
With a million vectors of 768 dimensions that is about 1.5 billion multiply-adds per query, or a few hundred milliseconds on a CPU core.
Adding the selection of the top changes nothing important. The scan dominates, and it grows linearly with the corpus forever.
A flat index is therefore the right answer up to roughly a hundred thousand vectors, and the wrong one above a few million.
Why the classical structures fail here
Space-partitioning trees work by pruning branches that cannot contain a closer point, and pruning depends on distances being well separated.
In high dimensions they are not, so almost no branch can be excluded and the tree degrades to a full scan with overhead on top.
Embeddings live in hundreds of dimensions, which is exactly the regime where exact indexing stops being possible.
Approximate search, and the trade it makes
An approximate index gives up exactness and reports how much: recall of 0.95 means 19 of the true top 20 were found.
That is the bargain. Two orders of magnitude faster for one missed result in twenty, and for retrieval the twentieth result rarely changes the answer.
The three families divide by what they give up. Trees and graphs restrict what is visited, hashing restricts what is compared, and quantisation shrinks what is stored.
One search, in order
- Normalise the query the same way the stored vectors were normalised.
- Use the index to select a small candidate set, orders of magnitude smaller than .
- Compute exact distances on those candidates only.
- Keep the top by that exact score.
- Optionally rescore the survivors with a stronger model.
Step three is why quantised indexes still work.
The compressed vectors choose the candidates and the full vectors decide the order, so the compression error affects recall rather than ranking.
Choosing an index
Below vectors, a flat exact index needs no tuning.
From to , HNSW is the fastest and the most memory-hungry.
Above , IVF with product quantisation suits data on disk.
Those thresholds move with hardware and with how much memory you are willing to buy, and the ordering between them does not.
The first question to ask of any vector database is which of these it is running underneath, because every tuning parameter it exposes belongs to one of them.