The cosine similarity between two vectors of an inner product space is the cosine of the angle between them. The cosine of 0° is 1 and the cosine of any other angle is less than 1. Therefore, the cosine similarity measures orientation and not magnitude. Regardless of their magnitude, two vectors with the same orientation have a cosine similarity of 1, two vectors at 90° have a cosine similarity of 0, and two diametrically opposed vectors have a cosine similarity of -1.
Given two vectors of attributes, A and B, the cosine similarity, cos(θ), is represented using a dot product and magnitude as:
Cosine similarity is most commonly used in high-dimensional positive spaces. In positive space, cosine similarity is often used for the complement, that is:
D cos(A, B) = 1 - S cos(A, B)