Glossary

Approximate nearest neighbor

A family of search algorithms that find vectors close to a query without comparing it against every stored vector, trading a little accuracy for large gains in speed.

Approximate nearest neighbor (ANN) search is a family of algorithms that find vectors close to a query vector without comparing the query against every stored vector. It accepts a small chance of missing some of the true nearest neighbours in return for answers that are hundreds or thousands of times faster than an exhaustive scan. ANN is what makes vector search practical over millions or billions of embeddings, and it sits underneath almost every vector database. Well-tuned ANN indexes typically return 95% to 99% of the results an exact search would, in a few milliseconds.

The problem ANN solves

Exact nearest-neighbour search, also called k-nearest neighbors or brute-force search, compares the query with every stored vector and keeps the closest k. The cost grows with the number of vectors times the number of dimensions. For ten million embeddings of 768 dimensions, one query means about 7.7 billion multiply-and-add operations. A GPU can do that quickly, but at hundreds of queries per second, or with a billion vectors, exhaustive search becomes too slow and too expensive for interactive vector search, whether it powers semantic search for users or dense retrieval inside a RAG pipeline.

Classic data structures for nearest-neighbour search, such as k-d trees, work well in two or three dimensions and degrade towards brute force in high-dimensional spaces, a pattern often called the curse of dimensionality. ANN methods give up the guarantee of an exact answer and use structure in the data to look at only a small fraction of the vectors. The resulting structure is a vector index, usually managed by a vector database.

How ANN algorithms work

ANN indexes are built for one distance measure, usually cosine similarity, dot product or Euclidean distance, and they answer the same question as exact search with less work. There are four broad families, and production systems often combine them.

Family

Main idea

Examples

Strengths and costs

Graph-based

Link each vector to its near neighbours and walk the graph towards the query

HNSW, DiskANN

Very high recall at low latency; large memory footprint; deletes are awkward

Partition-based

Cluster vectors and only search the clusters nearest the query

IVF indexes

Lower memory, fast to build; recall depends on how many clusters are probed

Quantization

Compress vectors so comparisons are cheaper and more fit in memory

Product quantization, binary quantization

Large memory savings; some accuracy loss, often recovered by rescoring

Hashing and trees

Hash or split the space so similar vectors fall in the same bucket

Locality-sensitive hashing, Annoy

Simple and fast to build; usually lower recall at the same speed

Graph indexes are the most widely used today. HNSW builds a layered graph: upper layers hold a sparse sample of vectors with long-range links, lower layers hold everything with short-range links. A search starts at the top, greedily moves towards the query, and drops a layer each time it can get no closer, finishing with a local search on the bottom layer. Only a few hundred or thousand vectors are visited out of millions.

Partition methods such as IVF run k-means over the vectors to create, for example, 4,096 clusters. At query time the system finds the nearest few clusters (the nprobe setting) and compares the query only with vectors in those clusters. If the answer sits in a cluster that was not probed, it is missed, which is where the approximation comes from.

Quantization is mostly about memory. Vector quantization replaces each vector with a compact code. Product quantization splits a vector into sub-vectors and stores a short code for each, cutting memory by 10 to 30 times. Binary quantization keeps one bit per dimension. A common pattern is IVF plus product quantization for the coarse search, followed by rescoring the best few hundred candidates with full-precision vectors. Libraries such as FAISS implement most of these methods and let them be combined.

The recall, speed and memory trade-off

Every ANN index has settings that move along one curve: higher recall costs more time or memory. In HNSW, the M parameter controls how many links each node keeps (more links, more memory, better recall), efConstruction controls how carefully the graph is built, and efSearch controls how many candidates are examined per query. In IVF, nlist sets the number of clusters and nprobe sets how many are searched.

Recall here has a specific meaning. It is the share of the true top-k neighbours, as found by an exact search, that the ANN index returns. An index with 98% recall at k=10 returns, on average, 9.8 of the true ten nearest vectors. It says nothing about whether those vectors are relevant to the user, which is a separate question measured with recall at k against human judgements.

Public benchmarks such as ann-benchmarks plot recall against queries per second for many algorithms on standard datasets. They are useful for comparing libraries, but the best settings for a given workload depend on its vector size, data distribution, filtering needs and update rate, so teams usually tune on a sample of their own data.

Filtering, tenants and updates

Real queries rarely ask only for the nearest vectors. They ask for the nearest vectors belonging to this customer, created after this date, tagged as policy documents. Metadata filtering interacts badly with ANN. Filtering after the search can leave too few results when the filter is selective. Filtering before the search can break the graph or cluster structure and slow everything down. Vector databases use various hybrid strategies, and filtered search performance is one of the main ways they differ.

Multi-tenant applications are an extreme version of the same problem. If thousands of customers share one index and every query filters by tenant, the index does a lot of work on vectors the query can never return. Options include vector namespaces, a per-tenant index, or sharding by tenant. Each has costs in memory, operations and isolation, discussed under multi-tenancy and in the best vector database for multi-tenant roundup. A filter is also a weaker isolation guarantee than a separate index, since one missing filter returns another customer’s data; see tenant isolation.

Updates are the third complication. Graph indexes handle inserts reasonably well but deletes poorly: deleted nodes are usually marked as tombstones and skipped, and the graph slowly degrades until it is rebuilt. IVF indexes drift as new data shifts the cluster centres away from the original k-means fit. Systems with heavy write traffic schedule periodic rebuilds, which is a form of re-indexing, or use incremental indexing strategies designed for frequent change.

How much does the approximation matter?

For most retrieval applications, ANN error is small next to other sources of error. Losing 2% of the true nearest neighbours rarely changes the answer a user sees, because the nearest neighbours by vector distance are themselves an imperfect proxy for relevance. A passage on the right topic that lacks the needed fact will be returned by exact and approximate search alike.

The gap between “nearest in embedding space” and “answers the question” is usually much larger than the gap between approximate and exact search. That is why hybrid search, reranking and better passage selection tend to improve answer quality far more than pushing ANN recall from 97% to 99.5%. At very large scale, vector search also suffers from semantic collapse, where many candidates sit at similar distances; the blog post on why vector search breaks at scale covers this in detail.

ANN recall matters more in some cases: deduplication and near-duplicate detection, where the goal is to find every close match; recommendation systems that need diversity in the long tail; and evaluation pipelines where results are compared against an exact baseline.

A worked example

A document platform stores 20 million passage embeddings of 1,024 dimensions. In 32-bit floats, the raw vectors take about 82 GB. An HNSW index with M=16 adds roughly another 2.5 GB of links and returns results in 3 to 5 milliseconds at 98% recall. Memory is the constraint: the team would need machines with well over 100 GB of RAM per replica.

Switching to IVF with 16,384 clusters and product quantization cuts memory to under 10 GB. With nprobe=32, recall falls to about 85%. Rescoring the top 200 candidates with full vectors stored on disk brings recall back to 96% at around 15 milliseconds. Adding a tenant filter shows the next problem: for small tenants, post-filtering leaves fewer than ten results, so the team moves its largest tenants to their own indexes. The final design is a set of trade-offs between memory, latency, recall and isolation, all of which have to be revisited as the corpus grows.

Where Exabase fits

Exabase is built so that teams do not choose, tune or rebuild ANN indexes. Content stored through the Resources API is indexed when it is written, and Deep Search handles retrieval with hybrid semantic and keyword matching, returning sub-document results with page numbers and timestamps. There are no index parameters, no vector store to size, and no rebuild schedule. The precision parameter (0 to 1, default 0.3) is the one control most teams need, and is expressed as how strict the match should be. The searching resources guide has the details, and the post on search at scale in Fabric explains where the infrastructure comes from.

The tenant filtering problem is handled by structure. Each Base is an isolated environment with its own storage, memory and search index, and isolation is enforced at the infrastructure level, so a query scoped to one Base cannot return another tenant’s content whatever the query says. Creating a Base is one API call, and paid plans support up to 10,000 Bases. The multi-tenant solution, the multi-tenant SaaS use case and the about Bases guide explain the model.

Teams already running a vector database can compare approaches in Exabase vs Milvus and the best vector databases roundup.

Frequently asked questions

What is the difference between ANN and kNN?

kNN (k-nearest neighbors) search finds the exact k closest vectors by comparing the query with every stored vector. ANN finds most of them by searching only part of the data, which is far faster at scale but may miss a few true neighbours.

What is a good recall for an ANN index?

Most production vector search runs at 95% to 99% recall at k=10 against an exact baseline. Higher recall costs more latency or memory. Measure it on your own data, since the right target depends on how the results are used.

Is HNSW the best ANN algorithm?

HNSW is the most widely used because it gives high recall at low latency, but it uses a lot of memory and handles deletes poorly. IVF with quantization is often chosen when memory is the constraint, and disk-based graph indexes suit very large datasets.

Does ANN reduce search quality?

Slightly, by missing a small share of the exact nearest neighbours. In most retrieval systems this loss is much smaller than the gap between vector similarity and true relevance, so better ranking usually matters more than higher ANN recall.

Why are filtered vector searches slow?

Filters cut across the structure the ANN index relies on. Filtering after the search can return too few results, and filtering before it can force the index to examine far more vectors. Separate indexes per tenant or partition avoid the problem for the most selective filters.

Do I need to tune ANN parameters to use Exabase?

No. Exabase indexes content when it is stored and handles retrieval in Deep Search, so there are no index types or parameters to choose. Each Base has its own isolated index.

Related pages: HNSW, K-nearest neighbors, Vector index, Vector database, Product quantization, Cosine similarity, Pinecone vs Qdrant, Exabase vs Pinecone, Deep Search

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.