Intermediate LevelAI, LLMs, Embeddings & MCP
What is an IVFFlat (Inverted File Index) vector index and how does it use Voronoi cells?
❓ Interview Prompt: Explain IVFFlat clustering, Voronoi partitions, nlist parameter, and nprobe search depth in pgvector.
IVFFlat (Inverted File Flat) is a clustering-based vector index popular in engines like FAISS and PostgreSQL pgvector.
Indexing Process:
1
Uses k-means clustering to partition vector space into $N$ clusters (Voronoi cells) defined by central centroids (
nlist parameter).2
Assigns every vector to its nearest cluster centroid.
Query Execution (nprobe Parameter):
When querying, IVFFlat compares the query vector against cluster centroids first, searching vector items inside only the top `nprobe` closest clusters, bypassing 95%+ of the database!
Code Implementation Example
sql
-- PostgreSQL pgvector IVFFlat index creation
CREATE INDEX ON items USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);
-- Query execution setting search depth (nprobe)
SET ivfflat.probes = 10;
SELECT * FROM items ORDER BY embedding <=> '[0.02, -0.15, ...]' LIMIT 5;💡pgvector SQL creating IVFFlat index and configuring search nprobe depth.
🎯 Interview Key Takeaway
IVFFlat partitions vectors into Voronoi clusters, searching only the nearest nprobe cluster centroids during queries.
#IVFFlat#pgvector#Voronoi#Vector Index#Intermediate
Back to all AI, LLMs, Embeddings & MCP Questions→