Artificial Intelligence · Retrieval & Search
Approximate Nearest Neighbor Search
Why production search uses HNSW instead of brute force.
1 min readPublished Updated
- ann
- hnsw
Exact nearest-neighbor search is too slow at scale, so production systems use approximate methods like HNSW.
rust
fn euclidean_distance(a: &[f32], b: &[f32]) -> f32 {
a.iter().zip(b).map(|(x, y)| (x - y).powi(2)).sum::<f32>().sqrt()
}HNSW builds a multi-layer graph so search can skip large portions of the index on each hop.
Explore the graph#
Click the plot to drop a query point and follow the greedy search from the sparse top layer down to the dense bottom one.
HNSW explorer