How it works
The dot product adds the products of matching coordinates. Dividing by both vector norms gives cosine similarity, which describes directional alignment for nonzero vectors.
A concrete example
If a = [1, 0] and b = [0, 1], their dot product and cosine similarity are 0: they are perpendicular.
Watch for this
Cosine similarity is undefined for a zero vector. Decide explicitly how your application handles that case.
Try it yourself
Move the angle to 0°, 90°, and 180°. Predict the similarity before checking the display.