Retrieval is an angle
Chunks and a query as vectors on a sphere. Drag the query and the nearest chunks re-rank by cosine similarity.
The 3D view needs WebGL, which this browser does not provide; the controls and the ranked list still work.
drag the query, or orbit
score = q·c / (‖q‖ ‖c‖) = cos θscore = q·c = ‖q‖ ‖c‖ cos θ = ‖c‖ cos θ, because ‖q‖ = 1 here
A 3D toy. Real embeddings have hundreds of dimensions (384 for the bge-small model in the article). These vectors really are 3D, so every score is exact for the picture. The snippets are made up. Each sits at a random point near its topic, with the closer ones written to be the more relevant; no model embedded them.
What to look for
- Relevant means a small angle. Drag the query across the sphere. The top k are the chunks inside the cone, and the search scores every chunk against the query, as the code in the article does.
- k decides what the model reads. With k = 2, the article's setting, two chunks reach the prompt. Pick the ambiguous query: it lands between two topics, the scores drop, and the context is one chunk from each.
- Cosine ignores length. Dot product rewards it. Keep the espresso query and stretch the sourdough chunk: its cosine score never moves. Switch to dot product and the cone becomes a flat cutoff. Once the chunk is long enough to cross it, a bread fact joins the coffee context. The two rankings agree only while every chunk has the same length.