Factory string: FAISS's string API to build indexes. Combine: IVF (coarse), PQ (compression), Flat (exact), HNSW (graph).
Rule of thumb: nlist ≈ √n. Train the index on a subset (≥30×nlist vectors) before adding all vectors.
GPU FAISS: flatly 10-100× QPS over CPU for Flat/IVF. Not supported for HNSW.
FAISS Index Types: Build, Query, and Memory - Interactive Visualization
FAISS (Facebook AI Similarity Search) is the production standard for billion-scale vector search. It provides four primary index types: IndexFlatL2 gives exact results scanning all vectors - perfect recall but O(n) query time, practical only below 1M vectors. IndexIVFFlat partitions vectors into Voronoi cells via k-means and searches only the nprobe nearest cells - recall and speed both controlled by nprobe. IndexIVFPQ adds Product Quantization to compress 128-dimensional float32 vectors (512 bytes each) down to as few as 8 bytes, enabling billion-scale search in memory. IndexHNSWFlat builds a Hierarchical Navigable Small World graph for logarithmic query time with the best recall-speed tradeoff, at the cost of high memory overhead for graph edges. FAISS factory strings are a concise API to compose index types.
IndexFlatL2: exact search, 100% recall, O(n) query - benchmarking baseline, not production at scale
IndexIVFFlat: train k-means (nlist ≈ √n cells), set nprobe at query time - IVF1024,Flat factory string
IndexIVFPQ: Product Quantization compresses 512 bytes → 32 bytes (16x), billion-scale on a single server
IndexHNSWFlat: no training needed, log-time search, M=32 links per node, ~99% recall at 1-2ms query
GPU acceleration: FAISS-GPU delivers 10-100x QPS for Flat and IVF indexes - not supported for HNSW
Factory string API: faiss.index_factory(d, "IVF1024,PQ64x8") composes index types in a single line
Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.