What are FAISS index types and when do you use each?
NLPLevel: IntermediateAdvanced Indexing
What are FAISS index types and when do you use each?
Hints
- Separate text representation, modeling and evaluation.
- Check ambiguity, rare terms and training versus target text distributions.
Answer
FAISS (Facebook AI Similarity Search) is the most widely used ANN library. Index type selection:
| Index | Description | When to Use | Notes |
|---|---|---|---|
IndexFlatL2 / IndexFlatIP | Exact brute-force search | <100K vectors, need perfect recall | Baseline; no approximation |
IndexIVFFlat | IVF with exact cell search | 1M–10M vectors, moderate recall | Set nprobe to tune recall/speed |
IndexIVFPQ | IVF + Product Quantization | 10M–1B+ vectors, memory-limited | 16–64× compression; use for scale |
IndexHNSWFlat | HNSW with full-precision vectors | 1M–100M, low-latency requirement | Best recall/speed tradeoff |
IndexHNSWSQ | HNSW + scalar quantization | 1M–100M, moderate memory | 4× compression, ~2% recall loss |
IndexScalarQuantizer | SQ8 vector storage | Any, add to above | Reduce memory 4× |
Practical recipe for production:
- < 500K vectors:
IndexFlatL2(exact is fast enough) - 500K–50M:
IndexIVFFlatwithnlist=sqrt(N),nprobe=20–50 - 50M+:
IndexIVFPQwithM=8(subspaces),nbits=8(256 centroids per subspace)
Source and licence: JustInCache & contributors — Awesome AI Interviews · Apache-2.0