From vectors to embeddings: the geometry behind similarity
Build an intuitive understanding of vectors, dot products, cosine similarity, and why embeddings turn meaning into geometry.
An embedding represents an object—a word, image, user, or document—as a list of numbers. That list is a vector:
The individual coordinates rarely have a simple human label. What matters is the geometry created by many vectors together.
Start with direction
Suppose two vectors point in nearly the same direction. Their coordinates may have different magnitudes, but they still express a similar pattern. Cosine similarity measures that directional agreement:
The numerator is the dot product. The denominator removes the effect of length.
A small worked example
Let and . Because , the vectors point in exactly the same direction and their cosine similarity is .
function dot(left, right) {
return left.reduce((sum, value, index) => sum + value * right[index], 0);
}
The code mirrors the mathematical definition .
Why embeddings are useful
Training arranges vectors so that useful relationships become geometric relationships. A search system can therefore retrieve nearby documents; a recommendation system can compare users with items; and a classifier can draw boundaries between regions.
The important idea is simple: an embedding is useful when distance or direction preserves a relationship we care about.