Meaning as coordinates
Keyword search matches characters. "Money back" and "reimbursement" share none of them, so it finds nothing — even though any human reads them as the same request. That's the gap RAG kept falling into at the end of the last topic.
An embedding closes it by turning text into a list of numbers — a vector, typically a few hundred to a few thousand of them. The model that produces it was trained so that text with similar meaning lands in similar positions.
"Get my money back", "refund policy", and "reimbursement eligibility" end up clustered together. "Onboarding a new hire" ends up somewhere else entirely. Nobody wrote a synonym list; the geometry was learned from how words are actually used.
Once meaning is coordinates, "find similar text" becomes "find nearby points" — and that's just arithmetic, which computers are extremely good at.
Cosine similarity
The standard measure is the angle between two vectors, ignoring their length. Same direction scores 1.0. Unrelated, roughly 0. Opposite, -1.
Ignoring length matters more than it sounds: it's what lets a two-line question match a two-paragraph answer. Direction carries the meaning; magnitude mostly carries the length. You want the first and not the second.
Semantic search, end to end
- Embed every chunk of your corpus, once, ahead of time. Store the vectors.
- Embed the incoming query — same model, always.
- Find the nearest chunks by cosine similarity.
- Hand them to the model as context.
Steps 1 to 3 are the "retrieve" in Retrieval-Augmented Generation. This is the engine underneath it.