Özer Cem KELAHMETKELAHMET
Articles · Vector databases

Vector databases explained: HNSW, IVF and product quantisation measured with FAISS

A vector database finds the nearest embeddings to a query without comparing against every vector. This guide explains HNSW, IVF and product quantisation, measures their recall and speed with FAISS, and maps the settings onto pgvector, Qdrant, Weaviate, Milvus and Pinecone.

Download Markdown
At a glance
Reading time
13 min
Sections
7
Code examples
2
Tables
3
Sources
9
Published
24 Nov 2026
In 30 seconds
What changed
FAISS 1.16.0 adds the PiPNN graph index and HNSW search-sink fix
Why it matters
For most RAG systems below a few tens of millions of chunks, HNSW with default parameters is the right first choice, and the main tuning knob is ef_search.
What to do
Benchmark on your own vectors

Once every chunk of your documents is an embedding, retrieval becomes a geometry problem: find the vectors closest to the query vector. With ten thousand vectors you can compare against all of them. With ten million, at hundreds of queries per second, you cannot. Vector databases solve this with approximate nearest neighbour (ANN) indexes that check a small fraction of the vectors and still find most of the true neighbours.

The algorithms inside these systems are few and well understood: graphs such as HNSW, clustering such as IVF, and compression such as product quantisation. The products differ in how they store, filter, update and scale them. This month FAISS, the reference library for these algorithms, shipped a release with a new graph index and an HNSW change, and pgvector continued its maintenance releases ahead of a larger version. This article explains the three core techniques, measures them, and shows how the same knobs appear in each database.

An analogy: exact search is reading every name in a phone book. HNSW is asking a chain of well-connected friends who point you closer each time. IVF is going straight to the right neighbourhood and knocking on doors there. Product quantisation is carrying a shorthand description of each person instead of their full file.

What happened

FAISS 1.16.0 adds the PiPNN graph index and HNSW search-sink fix (9 November 2026)

The FAISS changelog dates version 1.16.0 to 9 November 2026; the faiss-cpu wheel reached PyPI on 10 November. The release adds IndexPiPNN, a graph index with beam search, with serialisation, cloning and index_factory support. It also adds HNSW level-0 links from a sample "to remove search sinks", a binary flat index with GPU Hamming search on Apple's Metal backend, remove_ids for sharded and replicated indexes, and a large set of e-means clustering features, including distributed training and reduced-precision assignment. For most users the HNSW change is the one to test: search sinks are regions of a graph where greedy search gets stuck, which lowers recall.

pgvector 0.8.7 fixes an IVFFlat build overflow (1 October 2026)

The pgvector changelog lists 0.8.7 on 1 October 2026, fixing a buffer overflow during IVFFlat index builds and an error in the avg aggregate when no rows match. Earlier 2026 releases fixed possible HNSW index corruption during vacuuming (0.8.3, 17 June) and lowered IVFFlat build memory. The changelog's unreleased 0.9.0 section lists asynchronous I/O for indexes, vacuuming progress reporting, faster IVFFlat scans, and drops support for Postgres 13 and 14. If you run vectors inside Postgres, the 0.8.x patch releases are worth applying now.

The three core techniques

HNSW: a navigable graph

Hierarchical Navigable Small World (HNSW), introduced by Malkov and Yashunin, builds a layered graph. Every vector is a node in the bottom layer, linked to its nearest neighbours. A random, exponentially shrinking subset also appears in higher layers, which have longer links. A search starts at the top, greedily moves to the neighbour closest to the query, drops a layer, and repeats. In the bottom layer it keeps a candidate list of size ef_search and returns the best k.

Three parameters matter:

Table 1. HNSW: a navigable graph
Parameter What it controls Effect of raising it
M (pgvector m) Links per node Higher recall, more memory, slower build
ef_construction Candidate list size while building Better graph, slower build
ef_search Candidate list size while searching Higher recall, slower queries

pgvector's defaults are m = 16, ef_construction = 64 and hnsw.ef_search = 40. HNSW memory is the vectors plus links: roughly 2 × M neighbour IDs per node in the bottom layer. At M = 16 and 4-byte IDs that is about 128 bytes per vector, small next to a 768-dimension float32 vector of 3,072 bytes. The site's HNSW simulation animates the layered search.

IVF: cluster first, then search a few clusters

An inverted file (IVF) index runs k-means on the vectors to find nlist centroids, then files each vector under its nearest centroid. A query is compared to the centroids, and only the nprobe closest lists are searched. pgvector's README suggests starting with lists = rows / 1000 up to one million rows and sqrt(rows) above that, and probes = sqrt(lists). IVF builds faster and uses less memory than HNSW, but needs training data and degrades when the data distribution drifts away from the centroids.

Product quantisation: compress the vectors

Product quantisation (PQ), from Jégou, Douze and Schmid, splits each vector into m sub-vectors and replaces each with the ID of its nearest entry in a small codebook, usually 256 entries (8 bits). A 128-dimension float32 vector of 512 bytes becomes m bytes: 16 bytes at m = 16, a 32-times reduction. Distances are computed from precomputed tables, which is fast. The price is accuracy, which is why PQ is usually combined with IVF (IVF-PQ) and followed by re-scoring the best candidates with full vectors.

Measuring the trade-offs with FAISS

The script builds 100,000 clustered, normalised 128-dimension vectors, computes exact top-10 neighbours for 500 queries, and measures recall@10 (the share of true neighbours found) for each index. Install with pip install faiss-cpu numpy.

import time, numpy as np, faiss

rng = np.random.default_rng(0)
d, n, nq, k = 128, 100_000, 500, 10
centers = rng.normal(size=(200, d)).astype("float32")
xb = (centers[rng.integers(0, 200, n)] + 0.5 * rng.normal(size=(n, d))).astype("float32")
xq = (centers[rng.integers(0, 200, nq)] + 0.5 * rng.normal(size=(nq, d))).astype("float32")
faiss.normalize_L2(xb); faiss.normalize_L2(xq)

flat = faiss.IndexFlatIP(d); flat.add(xb)
_, gt = flat.search(xq, k)
recall = lambda I: np.mean([len(set(I[i]) & set(gt[i])) / k for i in range(nq)])

def bench(name, index):
    t = time.perf_counter(); _, I = index.search(xq, k)
    print(f"{name}: recall@10={recall(I):.3f} {(time.perf_counter()-t)*1000/nq:.3f} ms/query")

hnsw = faiss.IndexHNSWFlat(d, 16, faiss.METRIC_INNER_PRODUCT)
hnsw.hnsw.efConstruction = 64; hnsw.add(xb)
for ef in (16, 40, 128):
    hnsw.hnsw.efSearch = ef; bench(f"HNSW efSearch={ef}", hnsw)

ivfpq = faiss.IndexIVFPQ(faiss.IndexFlatIP(d), d, 316, 16, 8, faiss.METRIC_INNER_PRODUCT)
ivfpq.train(xb); ivfpq.add(xb)
for p in (1, 8, 32):
    ivfpq.nprobe = p; bench(f"IVF316,PQ16 nprobe={p}", ivfpq)

base = faiss.IndexIVFPQ(faiss.IndexFlatIP(d), d, 316, 16, 8, faiss.METRIC_INNER_PRODUCT)
refined = faiss.IndexRefineFlat(base); refined.train(xb); refined.add(xb)
refined.k_factor = 10; base.nprobe = 32; bench("IVF-PQ16 + refine", refined)
bench("Flat (exact)", flat)

Results on the test machine (timings are batched, multi-threaded and will differ on yours; the PQ 64-byte row comes from the same script with 64 sub-quantisers instead of 16):

Table 2. Measuring the trade-offs with FAISS
Index Setting Recall@10 ms per query
Flat (exact) n/a 1.000 0.745
HNSW, M = 16 efSearch = 16 0.859 0.016
HNSW, M = 16 efSearch = 40 0.967 0.024
HNSW, M = 16 efSearch = 128 0.997 0.055
IVF 316 lists, PQ 16 bytes nprobe = 1 0.189 0.006
IVF 316 lists, PQ 16 bytes nprobe = 32 0.197 0.044
IVF 316 lists, PQ 64 bytes nprobe = 32 0.802 0.167
IVF-PQ 16 bytes + full-vector refine (10 × k) nprobe = 32 0.720 0.060

Read the table in three steps.

  1. HNSW gives most of the recall at a small fraction of the cost. At pgvector's default ef_search of 40, recall is 0.967 and queries are about 30 times faster than exact search here. Raising ef_search to 128 buys the last three points of recall for roughly twice the latency.
  2. Aggressive PQ caps recall regardless of nprobe. With 16-byte codes, recall stays near 0.19 to 0.20 however many lists are probed, because the compressed distances cannot tell close neighbours apart. More probes cannot fix lost information.
  3. Compression is a dial, and re-scoring recovers much of the loss. Four times more bytes per code (64) lifts recall to 0.80. Keeping the 16-byte codes but re-scoring 100 candidates with full vectors lifts recall to 0.72 at a third of the latency of PQ64. The raw vectors here take 51.2 MB; the 16-byte codes take 1.6 MB.

Note what the latency column hides: the build. The HNSW index took far longer to build than the flat index, and IVF needed a k-means training pass before any vector could be added. For a corpus that is rebuilt nightly, build time can matter as much as query time.

These are synthetic vectors, so the absolute numbers will not transfer, but the shapes of the curves do. Always run the same test on a sample of your own embeddings. The site's pages on FAISS, HNSW and IVF-PQ go deeper into each index.

From algorithms to databases

A vector database wraps these indexes with storage, updates, filtering, replication and an API. The table summarises five common choices using their own descriptions.

Table 3. From algorithms to databases
System What it is Index types Notes for RAG
pgvector Postgres extension HNSW, IVFFlat; vector, halfvec, bit, sparsevec types Vectors next to your relational data; SQL filters and joins
Qdrant Open-source engine written in Rust HNSW with quantisation options Built for extended payload filtering
Weaviate Open-source, cloud-native database HNSW plus keyword search Combines vector search, keyword filtering and reranking in one query interface
Milvus Open-source distributed database written in Go and C++ HNSW, IVF, FLAT, SCANN, DiskANN, quantised variants, GPU indexes such as CAGRA Designed to scale out across nodes
Pinecone Fully managed service Managed, not user-selected No infrastructure to run; pay per use

Filtering is where products differ most. RAG queries often carry filters: this tenant, these document types, newer than this date. pgvector's README explains the trap clearly: with approximate indexes the filter is applied after the index scan, so if a condition matches 10 percent of rows and ef_search is 40, only about 4 rows match on average. Since 0.8.0, pgvector can run iterative index scans (SET hnsw.iterative_scan = strict_order or relaxed_order) that keep scanning until enough rows pass the filter, bounded by hnsw.max_scan_tuples. Dedicated engines build filtering into graph traversal itself. Test your real filter selectivity, not just unfiltered recall.

Storage limits shape model choice. In pgvector, each vector takes 4 × dimensions + 8 bytes; HNSW and IVFFlat can index vector up to 2,000 dimensions, halfvec up to 4,000 and bit up to 64,000. A 3,072-dimension embedding must therefore be indexed as halfvec, binary-quantised, or truncated.

What it means in practice

For most RAG systems below a few tens of millions of chunks, HNSW with default parameters is the right first choice, and the main tuning knob is ef_search. The benchmark shows the familiar curve: recall rises quickly and then flattens, while latency keeps rising. Pick the point where your end-to-end answer quality stops improving, not the point where recall reaches 1.0.

Compression is for scale and cost. When raw vectors no longer fit in memory, use product or scalar quantisation, and always re-score candidates with full-precision vectors kept on disk. The 16-byte example shows how much recall can be lost without that step.

The database choice follows your constraints more than your algorithms. If your data already lives in Postgres and fits on one server, pgvector removes a whole system. If you need heavy filtering, multi-tenancy and horizontal scale, a dedicated engine earns its operational cost. If you want no operations at all, a managed service is the answer. This month's FAISS and pgvector releases are reminders to keep these components patched: index corruption and buffer overflows are real failure modes.

What to do now

  1. Benchmark on your own vectors. Take 100,000 of your embeddings and 500 real queries, compute exact neighbours, and measure recall@10 for each index setting.
  2. Start with HNSW defaults. m = 16, ef_construction = 64, then tune ef_search between 40 and 200 against recall and latency.
  3. Test filtered queries separately. Measure recall with your real filters; enable pgvector iterative scans or use an engine with filter-aware traversal if results come back short.
  4. Re-score after compression. If you use PQ or binary quantisation, keep full vectors and re-score the top 50 to 200 candidates.
  5. Size memory before buying hardware. Vectors take dimension × bytes per number, plus about 128 bytes per vector of HNSW links at M = 16.
  6. Patch pgvector to 0.8.7 or later. The 2026 patch releases fix HNSW vacuum corruption and IVFFlat build overflows.
  7. Try the FAISS 1.16 HNSW change in a staging index. Rebuild a copy and compare recall at the same efSearch.
  8. Plan for rebuilds. Changing embedding models or index parameters means rebuilding; keep the pipeline scripted and timed.

Risks and open questions

Recall is not answer quality. A 0.97 recall@10 index can still miss the one passage that matters. Measure end-to-end with labelled questions.

Synthetic benchmarks mislead. Real embeddings are clustered in ways random data is not, and the right nprobe or ef_search depends on that structure.

Deletes and updates degrade graphs. HNSW indexes handle deletions with tombstones and repairs; heavy churn can lower recall and needs vacuuming or rebuilds, as pgvector's vacuum fixes show.

Filtered search remains hard. Highly selective filters push approximate indexes towards brute force. Partitioning by tenant or using filter-aware indexes may be needed.

New index types need time. FAISS's PiPNN index is new; its recall, build time and memory on real RAG workloads still need independent measurement.

Watch next: pgvector 0.9.0 with asynchronous I/O and the Postgres 15 minimum, and whether FAISS's level-0 sampling change shows up as higher recall in database engines built on similar HNSW code.

Frequently asked questions

What is the difference between a vector database and a vector index?

A vector index, such as HNSW in FAISS, is a data structure that finds nearest neighbours quickly. A vector database adds storage, updates, filtering, access control, replication and an API around one or more indexes.

Is HNSW always better than IVF?

No. HNSW usually gives higher recall at low latency, but it uses more memory and builds more slowly. IVF builds faster, uses less memory and combines well with product quantisation for very large collections.

What should I set ef_search to?

Start at the default, 40 in pgvector, and raise it while measuring recall and latency. In the benchmark above, 40 gave 0.967 recall@10 and 128 gave 0.997 at about twice the latency.

Can I use pgvector for production RAG?

Yes, many teams do, especially when their data already lives in Postgres. Check the dimension limits for indexing, enable iterative scans for filtered queries, and keep the extension patched.

Why did my filtered vector search return fewer results than requested?

Because the approximate index found k candidates first and the filter removed most of them. Raise ef_search, enable iterative index scans in pgvector, or use a database that applies filters during graph traversal.

Summary

Vector databases make similarity search fast by checking only part of the data. HNSW navigates a layered graph and, in the FAISS benchmark here, reached 0.967 recall@10 at pgvector's default ef_search of 40 while running about 30 times faster than exact search. IVF clusters vectors and probes a few lists, and product quantisation compresses them, but heavy compression capped recall near 0.20 until candidates were re-scored with full vectors. The products, from pgvector to Qdrant, Weaviate, Milvus and Pinecone, wrap the same ideas with different filtering, scaling and operations models. FAISS 1.16.0 and pgvector 0.8.7 are this autumn's updates to test; the durable advice is to benchmark on your own vectors and filters.

Sources

Cite this article

Kelahmet, Ö. C. (2026, November 24). Vector databases explained: HNSW, IVF and product quantisation measured with FAISS. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/vector-databases-hnsw-ivf-pq-pgvector

BibTeX
@online{kelahmet2026vector,
  author = {Kelahmet, {\"O}zer Cem},
  title  = {{Vector databases explained: HNSW, IVF and product quantisation measured with FAISS}},
  year   = {2026},
  month  = {nov},
  url    = {https://www.ozercemkelahmet.com/articles/vector-databases-hnsw-ivf-pq-pgvector}
}
Version historyfirst version
  1. Published

Factual corrections are listed here with what changed. Wording and formatting edits are not listed.

Last updated Nov 24, 2026
Type to search.
    ↑↓ navigate↵ open