Cosine Similarity

Drag the red and blue vectors around the unit circle. The orange segment shows the projection of B onto A, whose length equals cos θ.

Cosine Similarity

0.71
Angle: 45.0°
Projection of B on A: 0.71
Vector A (unit): (0.87, 0.50)
Vector B (unit): (0.31, 0.95)

The Cosine Function

Cosine Similarity Formula

$$\cos(\theta) = \hat{\mathbf{A}} \cdot \hat{\mathbf{B}} = A_x B_x + A_y B_y \qquad \text{(for unit vectors } |\hat{\mathbf{A}}| = |\hat{\mathbf{B}}| = 1\text{)}$$
Current calculation:
$$\cos(\theta) = \hat{\mathbf{A}} \cdot \hat{\mathbf{B}} = (0.87)(0.31) + (0.50)(0.95) = 0.74$$