Applied LLM Systems: RAG, Agents & MCP / Retrieval-Augmented Generation
Meaning as geometry, measured by cosine.
Reviewed by Yuvaraj
Retrieval needs a way to ask "which of these passages is about the same thing as my question?", even when they share no words. The tool for that is the embedding: a way of turning text into a point in space so that meaning becomes distance.
An embedding maps a piece of text to a vector, a list of numbers, often hundreds or thousands of them. Individually the numbers mean nothing; what matters is the arrangement:
Text with similar meaning lands close together; unrelated text lands far apart.
Once meaning is geometry, "find related text" becomes "find nearby points", a problem computers are very good at. This is why a search for "auto repair" can surface a document about "car maintenance" with no shared words.
Because embeddings are vectors, we can score how alike two of them are. The standard measure is cosine similarity, the cosine of the angle between the vectors:
Answer from memory before revealing, retrieval practice is what builds durable recall.
How is the similarity between two embeddings usually measured?
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
Cosine looks at direction, not magnitude, which is usually what we want: a long document and a short query can still be "about the same thing."
Suppose a user asks about a refund, and you have two stored passages. With toy 3-number vectors:
refund = [2, 2, 0]returns and refunds = [3, 3, 1]weather forecast = [0, 1, 3]Score each passage against the query:
Passage A scores far higher, so retrieval returns it, even though the query word "refund" never literally appears in "returns." That single ranking step, repeated across a whole collection, is semantic search:
Production embeddings are learned. A model is trained so that texts which should be close (a question and its answer, a sentence and its paraphrase) end up close in the space. The geometry is a by-product of that training objective.
Try it in the Embedding Explorer
The linked lab lets you type phrases and see them placed in 2D with a live cosine-similarity table. It is honest about its limits: it uses character trigram hashing, so it captures surface similarity (shared substrings, spelling) rather than learned meaning. It is enough to feel how similarity scoring works; a real system swaps in a trained embedding model.
Everything downstream rests on this: semantic search, the retrieval step of RAG, clustering, and recommendation all reduce to "embed, then compare." The next lesson turns comparison into search at scale.