Vectors: RAG Retrieval Is Finding Nearest Neighbors
When we learned RAG, we said Embedding turns a passage into a string of numbers. What are those numbers, really? The answer is almost too simple—coordinates. Each sentence gets a spot on a “semantic map”: closer in meaning means closer in place. So “retrieving documents” becomes a game every kid knows: find the neighbors closest to you on the map.
Below is a mini semantic map: 12 words already seated by Embedding, naturally clustering into three “districts.” Drag the black ❓ query point (or click anywhere on the map to place it). Watch for: the lines always point to the 3 nearest words, distances update live, and the closest one wears 👑. Drag ❓ between two districts and see the neighbors swap.
The dumbest way to find nearest neighbors is to measure distance to every point. Sixty points are fine—but RAG knowledge bases often hit millions of chunks, and recommenders hit billions. Below, the same map scatters 60 points; 🌟 is your query. Click “Brute-force” first and count the steps, then “HNSW layered hops” to compare—watch how the blue jump lines “big hop first, then small hops.”
RAG retrieval
Questions and documents both become coordinates; find the nearest passages and feed them to the LLM—the “answer from a knowledge base” you use every day is exactly these two animations under the hood.
Image search
Images can be Embedded into coordinates too. Snap a photo of a sofa to find matches—that’s finding your photo’s neighbors on a semantic map of hundreds of millions of images.
You might also like
Your taste is a coordinate; every song and show is one too. What recommenders do all day: find the content closest to you and serve it up.
✅ What this lesson wants to share
- Meaning → coordinates: Embedding gives every sentence and image a spot on a high-dimensional map
- Similarity → distance: closer in meaning means closer in place—the whole idea behind “semantic search”
- Retrieval → find neighbors: RAG, image search, and recommendations are all the same nearest-neighbor search problem
- Speed from layered shortcuts: HNSW stores a few sparse “highway” layers so hundred-million-scale data arrives in dozens of steps
- Space for time, again: spend storage on shortcut graphs to drop retrieval from minutes to milliseconds