Vector Indexes — Semantic Search, ANN & Exact kNN
Studies in this cluster, in series order. Each one keeps its own URL.
Databases
Indexes, isolation, storage engines, shard and partition keys, and zero-downtime migrations you can ship without a maintenance window.
- 1.Vector Indexes — Semantic Search, ANN, and When Exact kNN WinsSemantic search turns text, images, or events into vectors and answers what is closest to the query vector. Exact kNN scans every vector: perfect recall, zero build cost, trivial filters, and cost linear in N. ANN indexes give up a little recall for sub-linear queries. This hub is the decision map across HNSW, IVF, PQ, LSH, ScaNN, and DiskANN, including when brute force is the right answer.
- 2.HNSW — Layers, Greedy Search, M and efHNSW is a stack of proximity graphs. Layer 0 holds every vector, and each higher layer keeps an exponentially smaller sample. A query greedily walks the sparse top layers, then runs a beam of width efSearch on layer 0. M, efConstruction, and efSearch are the three knobs that set memory, graph quality, and the recall versus latency dial.
- 3.IVF, PQ, and ScaNN — Partition, Quantize, Re-rankIVF partitions space with k-means and scans only the nprobe cells nearest the query. PQ compresses each vector into a few bytes of codebook ids and scores them with table lookups. Together, with an exact re-rank, that is the classic recipe from hundreds of millions to billions of vectors. ScaNN spends its quantization error where inner-product rank actually moves.
- 4.Filtered and Hybrid Search — Metadata, BM25, and Broken RecallReal queries are nearest vectors for this tenant, in stock, that this user may see, and often matching an exact error code. Filters fight ANN structures: post-filtering returns too few hits, a matching-only walk strands, and a filter-aware walk gets expensive when the predicate is selective. Hybrid search adds a BM25 leg and fuses ranks so one score scale cannot silently win.
- 5.Recall, Latency, and Memory — Tuning and EvaluationEvery ANN index trades recall, latency, and memory, with build time as the fourth wheel. The first artifact is an evaluation harness: frozen real queries, exact ground truth, recall at k plus tail recall, p50 and p99, and bytes per replica. Sweep efSearch, nprobe, quantization, and re-rank depth, then pick the cheapest point that meets the target.
- 6.Sharding, Updates, and Stale Embeddings — Production Vector SearchA vector index that works on a laptop fails in production in predictable ways. It outgrows one node, scatter-gather inflates p99, tombstones erode recall, and embeddings go stale when the text or the model changes. Mixing two embedding models fails silently: no error, just garbage neighbors. Hash-shard, return full k per shard, and cut over models with a second index and an alias.