Two vectors, a and b
A vector is an arrow from the origin, so it has a direction and a length.
Components
Any arrow can be described by how far it goes across and how far it goes up.
a goes 1 across and 3 up, so a = [1, 3]. b goes 3 across and 1 up, so b = [3, 1].
b goes 3 across and 1 up, so b = [3, 1].
The recipe
Multiply the components that line up, then add the results.
First the across parts: 1 × 3 = 3. Then the up parts: 3 × 1 = 3. Add them together: a · b = 6.
One number
Two vectors go in and one number comes out.
The angle
There's a second way to get the same number: multiply the two lengths, then multiply by the cosine of the angle θ between the vectors.
Here |a| = |b| = √10 ≈ 3.16 and cos θ = 0.6, which gives 6 again.
Projection
Shine a light straight down onto the line through b and a casts a shadow. The dot product is the shadow's length times |b|.
The shadow is signed. When the angle is wider than 90°, it lands behind the origin and counts as negative.
The sign
As you scroll, b swings away from a.
While they point roughly the same way, the dot product is positive. At exactly 90° the shadow disappears and the dot product is 0: the vectors are orthogonal. Past 90° it turns negative.
Length matters too
The angle isn't the whole story. Stretch b and the dot product grows with it: double b and you double a · b.
So a large dot product can mean the vectors are well aligned, or just that they're long.
Cosine similarity
To compare only directions, shrink both vectors to length 1 first. Then the dot product is just cos θ, which always falls between −1 and 1.
That's cosine similarity, the score search engines and embedding models use to measure how alike two things are.
Try dragging the arrowheads around the circle.
More dimensions
Nothing in the recipe cares how many components there are. In three dimensions, multiply the three matching pairs and add them up.
Text embeddings often have hundreds or thousands of components, and the dot product is still just multiply and add.
Your turn
Drag either arrowhead, or Tab to one and use the arrow keys. Watch the recipe, the angle formula and the shadow move together.