LLM Learning Hub

workspace/llm-course/home

Approximate Nearest Neighbor

Approximate Nearest Neighbour (ANN) search trades a small recall loss for large speed gains by using graph-based (HNSW) or clustering-based (IVF) indexes that prune the search space.

What is Approximate Nearest Neighbor?

Approximate Nearest Neighbour (ANN) search trades a small recall loss for large speed gains by using graph-based (HNSW) or clustering-based (IVF) indexes that prune the search space.

Approximate Nearest Neighbour (ANN) search trades a small recall loss for large speed gains by using graph-based (HNSW) or clustering-based (IVF) indexes that prune the search space.

Where is it used?

HNSW is the default in Qdrant, Weaviate, and Chroma; IVF-PQ in FAISS and Milvus compresses vectors for billion-scale search; Spotify Annoy uses tree-based ANNs.

How to build it

Use `faiss.IndexIVFPQ(quantizer, d, nlist=1024, m=8, nbits=8)`, train on a sample, add vectors, set `nprobe=16`, and measure recall@10 vs query latency compared to flat search.