A retrieval-augmented-generation (RAG) system doesn't search raw text — it searches embeddings: dense numeric vectors produced by a neural encoder so that semantically similar passages land near each other in a high-dimensional space. This scene compresses that space to 3D. Each glowing point is a document chunk; its position is determined by its topic, so clusters emerge naturally — cooking recipes near cooking recipes, astronomy near astronomy.
Most production embedding models (OpenAI's text-embedding-3, Cohere Embed,
BGE, etc.) are trained so that cosine similarity is the intended comparison — vector
databases like Pinecone, Weaviate and pgvector default to it, and approximate-nearest-neighbour
indexes such as HNSW trade a little accuracy for searches that scale to billions of vectors
in milliseconds.
A 3D embedding space where document chunks cluster by topic; plotting a query vector among them and running nearest-neighbour search shows exactly how a vector database retrieves context for a RAG pipeline.
Semantically similar text lands near each other in embedding space. A vector database ranks every stored embedding against the query using a similarity metric and returns the top-K closest matches, which are then stuffed into the LLM's context window.
Pick a query topic and drift it toward a neighbouring one, choose cosine or Euclidean similarity, and adjust top-K and embedding spread. Press "Run retrieval" to watch the nearest documents stream up into the simulated LLM context.
At billion-vector scale, exact nearest-neighbour search is too slow — production vector databases use approximate methods like HNSW graphs or IVF indexes to trade a sliver of accuracy for millisecond-scale lookups.