By Sagar Shankaran, Founder of CallSphere
Understand the four major vector index algorithms — Flat, IVF, HNSW, and Product Quantization — with clear explanations of accuracy vs speed tradeoffs and guidance on tuning parameters.
Key takeaways
When you have 1,000 documents, finding the nearest neighbors to a query vector is trivial — compute the distance to every vector and sort. When you have 10 million documents, that brute-force approach takes seconds per query, which is unacceptable for interactive applications.
Vector indexes solve this by trading a small amount of accuracy for dramatic speed improvements. Instead of comparing against every vector (exact search), approximate nearest neighbor (ANN) indexes use clever data structures to narrow the search space. The four most important index types are Flat, IVF (Inverted File), HNSW (Hierarchical Navigable Small World), and PQ (Product Quantization).
A flat index stores vectors in a simple array and performs exhaustive comparison at query time. It is not really an "index" in the traditional sense — it is brute-force search.
flowchart LR
FP16(["FP16 model<br/>baseline weights"])
CALIB["Calibration set<br/>128 to 1024 samples"]
METHOD{"Quantization<br/>method"}
GPTQ["GPTQ<br/>weight only INT4"]
AWQ["AWQ<br/>activation aware"]
GGUF["llama.cpp GGUF<br/>K-quants for CPU"]
EVAL["Eval delta vs FP16<br/>perplexity, MMLU"]
SERVE[("Serve on<br/>consumer GPU")]
FP16 --> CALIB --> METHOD
METHOD --> GPTQ --> EVAL
METHOD --> AWQ --> EVAL
METHOD --> GGUF --> EVAL
EVAL --> SERVE
style METHOD fill:#4f46e5,stroke:#4338ca,color:#fff
style EVAL fill:#f59e0b,stroke:#d97706,color:#1f2937
style SERVE fill:#059669,stroke:#047857,color:#fff
import faiss
import numpy as np
dimension = 1536
vectors = np.random.rand(10000, dimension).astype("float32")
# Flat index with L2 distance
index = faiss.IndexFlatL2(dimension)
index.add(vectors)
# Query — compares against all 10,000 vectors
query = np.random.rand(1, dimension).astype("float32")
distances, indices = index.search(query, k=5)
print(f"Nearest IDs: {indices[0]}")
Pros: 100% recall (exact results), no training step, simple to use. Cons: Query time scales linearly with dataset size. Impractical above ~100K vectors for real-time applications.
When to use: Small datasets, ground truth evaluation, accuracy benchmarking of other index types.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
IVF partitions the vector space into nlist clusters using k-means. At query time, it only searches the nprobe nearest clusters instead of the entire dataset.
nlist = 100 # number of clusters
quantizer = faiss.IndexFlatL2(dimension)
index = faiss.IndexIVFFlat(quantizer, dimension, nlist)
# IVF requires training on representative data
index.train(vectors)
index.add(vectors)
# Search the 10 nearest clusters
index.nprobe = 10
distances, indices = index.search(query, k=5)
The key tradeoff is nprobe:
Rule of thumb: Set nlist to roughly 4 * sqrt(n) where n is the number of vectors. Set nprobe to 5-10% of nlist as a starting point.
HNSW builds a multi-layer graph where each vector is a node. Upper layers are sparse (long-range connections for coarse navigation), and lower layers are dense (short-range connections for precise search). Queries start at the top layer and greedily navigate toward the nearest neighbors.
# HNSW in FAISS
M = 32 # connections per node
ef_construction = 40 # build-time search depth
index = faiss.IndexHNSWFlat(dimension, M)
index.hnsw.efConstruction = ef_construction
index.add(vectors)
# Query-time search depth
index.hnsw.efSearch = 64
distances, indices = index.search(query, k=5)
Key parameters:
Pros: Best recall-speed tradeoff for most workloads. Supports incremental inserts without rebuilding. No training step required. Cons: High memory usage (stores the graph structure). Slower to build than IVF for very large datasets.
PQ compresses vectors by splitting each vector into subvectors and quantizing each subvector independently. This reduces memory usage dramatically — a 1536-dimensional float32 vector (6KB) can be compressed to ~64 bytes.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
m = 48 # number of subquantizers (must divide dimension evenly)
nbits = 8 # bits per subquantizer (256 centroids each)
index = faiss.IndexPQ(dimension, m, nbits)
index.train(vectors)
index.add(vectors)
distances, indices = index.search(query, k=5)
PQ is often combined with IVF for a powerful combination:
# IVF + PQ: partitioned search with compressed vectors
index = faiss.IndexIVFPQ(quantizer, dimension, nlist, m, nbits)
index.train(vectors)
index.add(vectors)
index.nprobe = 10
Pros: Massive memory reduction (10-50x). Enables billion-scale search on a single machine. Cons: Lower recall than uncompressed indexes. Requires training. Distance calculations are approximate.
| Criteria | Flat | IVF | HNSW | PQ |
|---|---|---|---|---|
| Dataset size | < 100K | 100K - 10M | 100K - 50M | 1M - 1B+ |
| Recall | 100% | 90-99% | 95-99.9% | 80-95% |
| Memory | High | High | Very high | Low |
| Build time | None | Moderate | Slow | Moderate |
| Query speed | Slow at scale | Fast | Very fast | Fast |
| Incremental insert | Yes | Rebuild needed | Yes | Rebuild needed |
For most applications with fewer than 10 million vectors, HNSW is the best default. It delivers the highest recall at competitive query speeds without requiring a training step.
Yes. The most common combination is IVF + PQ (IndexIVFPQ in FAISS), which partitions the space with IVF and compresses vectors with PQ. HNSW can also use PQ compression (IndexHNSWPQ) for memory-constrained environments. These composite indexes trade some recall for dramatic memory and speed improvements.
Generate a ground truth by running exact search (Flat index) on a representative query set. Then run the same queries against your ANN index and calculate recall at K — the fraction of true nearest neighbors that appear in the ANN results. A recall of 0.95 at K=10 means 9.5 out of 10 true nearest neighbors are found on average.
Higher dimensions increase memory usage and computation time for all index types, but they impact PQ most significantly because more subquantizers are needed. For very high dimensions (3072+), HNSW with dimensionality reduction or PQ compression becomes important. For typical dimensions (384-1536), any index type works without special consideration.
#VectorIndex #HNSW #IVF #ANN #Algorithm #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
The four major vector index algorithms in 2026 — HNSW, IVF, ScaNN, DiskANN — and which one fits your scale, recall, and latency budget.
Fertility and reproductive endocrinology clinics deploy AI voice agents for IVF consult scheduling, cycle monitoring coordination, and emotionally-aware callbacks on difficult days.
pgvector 0.8 with binary quantization cut HNSW build time 150x and hits 471 QPS at 99% recall on 50M vectors. Here is the production tuning guide for Postgres-shop teams.
435,000 ART cycles a year, 45-52% first-cycle success under 35, and 140 best-of-list clinics in 2026. Fertility intake is the most emotionally sensitive call in healthcare. Here is how voice AI runs it with empathy and HIPAA discipline.
A measured guide to tuning pgvector HNSW indexes for AI agent workloads — what m, ef_construction, and ef_search actually do, how to size them at 1M, 10M, and 50M rows, and how to monitor recall in production.
How generative AI produces verified dbt models for data migration — from scratch and incrementally — with SME validation and strict data governance.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.