Vector DBs & RAG (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
How does IVFFlat (Inverted File Flat) indexing work and how does it compare to HNSW?
senior LevelMost AskedSystem DesignDatabases & SQL
In Simple Words: IVFFlat partitions vector space into Voronoi cells using k-means clustering:
- Index Build: Clusters vectors into N centroid points (
nlist). - Query Search: Finds the closest M centroids to the query vector (
nprobe), and only evaluates vectors stored inside those specific clusters. - Comparison:
- IVFFlat consumes significantly less RAM and builds faster than HNSW.
- HNSW delivers higher recall and lower latency on large, dynamic datasets.