AI vector search: pgvector
This course covers approximate nearest neighbor search in Postgres with pgvector. It starts from a sequential scan, reads EXPLAIN ANALYZE output, and explains recall as the cost of approximate indexes. It then covers distance operators and matching operator classes, IVFFlat lists and probes, and HNSW with m, ef_construction and ef_search. Later lessons handle filtered queries with iterative scans, partial indexes and partitioning, then quantization with halfvec and binary vectors plus rescoring. The last lesson measures recall against exact search and tracks it in CI.
What you'll learn
- ✓Reading EXPLAIN ANALYZE and calculating recall@k for vector queries
- ✓Pairing distance operators with the matching operator class
- ✓Sizing and tuning IVFFlat lists and probes and HNSW m, ef_construction and ef_search
- ✓Handling filtered queries with iterative scans, partial indexes and partitioning
- ✓Reducing storage with halfvec, binary quantization and rescoring
- ✓Tracking recall against exact search in CI
From sequential scan to vector index
A nearest-neighbor query with no index is honest work. Postgres computes the distance from your query vector to every row, sorts, and returns the top ten. It is exact, and at ten thousand rows it takes about the time you would spend blinking.
Read the full lesson free →Curriculum
7 lessonsFrom sequential scan to vector index
Why exact scans slow down at scale, what recall measures, and the latency, build time and memory costs of vector indexes.
Distance metrics and operator classes
How cosine, L2 and inner product differ, and why a mismatched operator class makes Postgres ignore the index.
IVFFlat: lists and probes
How IVFFlat clusters vectors with k-means, how to size lists and probes, and why empty tables produce bad centroids.
HNSW: graphs, m, and ef_search
How HNSW searches a layered graph, what m, ef_construction and ef_search control, and how to speed up builds.
Filtering with approximate indexes
Why selective WHERE clauses return short results, and how iterative scans, partial indexes and partitioning address it.
Quantization: halfvec and binary vectors
Shrinking vector storage with halfvec and binary quantization, using a cheap first pass followed by rescoring with full vectors.
Measuring recall and shipping it
Computing ground truth with indexes off, plotting recall against latency, and a production checklist ending with recall tests in CI.