Exact search and why it stops scaling
What it is
The simplest way to find the nearest vectors is to compare the query with every stored vector and keep the best.
- This is exact or brute-force search (also called a flat index).
- It always returns the true nearest neighbours.
Why it matters
Its cost grows in a straight line with the collection.
- Each comparison touches every number in the vector, so one query costs
chunks × dimensionsmultiplications. At 10,000 chunks that is instant. - At 10 million chunks of 768 numbers it is about 7.7 billion multiplications per query, which is too slow for a live system serving many users.
- Exact search is the right choice for small collections and the baseline that everything faster is measured against.
In the real world: A small firm's assistant over 3,000 internal documents runs exact search inside its application with a NumPy array, and has no vector database to operate at all.
import numpy as np
def exact_search(query, vectors, k=5):
"""vectors: (n, d), all normalised. Returns the indices of the k closest."""
scores = vectors @ query # n dot products
return np.argsort(-scores)[:k]Reaching for a vector database for 5,000 chunks. Below roughly a hundred thousand vectors, exact search in memory is fast, perfectly accurate and has nothing to tune. Adding infrastructure there only adds things that can break.