Cosine Similarity
Interactive 3D visualization of vector relationships, angles, and similarity metrics.
Vectors
Presets
3D Space
Metrics
Formula:
similarity = (A · B) / (||A|| ||B||)
Measures the cosine of the angle between two vectors.
Interactive 3D visualization of vector relationships, angles, and similarity metrics.
Presets
Formula:
similarity = (A · B) / (||A|| ||B||)
Measures the cosine of the angle between two vectors.
How do we measure how "similar" two things are, especially when they are represented as lists of numbers (vectors)? While we could measure the distance between their endpoints (Euclidean distance), Cosine Similarity offers a different perspective: it measures the angle between two vectors. This simple but powerful idea is fundamental to modern AI, from search engines to recommendation systems. This 3D lab lets you build an intuition for what that angle really means.
Imagine two arrows starting from the same point (the origin). Cosine similarity doesn't care about the length of these arrows (their "magnitude"); it only cares about the direction they are pointing.
This focus on direction is why cosine similarity is so useful. For example, in text analysis, the documents "the cat sat on the mat" and "a cat was sitting on a mat" are different in length and exact wording, but their vector representations will point in very similar directions, resulting in a high cosine similarity score.
The similarity score is literally the cosine of the angle ($\theta$) between the two vectors, $\vec{A}$ and $\vec{B}$. The formula looks like this:
Similarity = cos($\theta$) = (A · B) / (||A|| * ||B||)
Let's break that down:
This measures how much the vectors "agree." You calculate it by multiplying the corresponding components of each vector and summing the results. (A.x * B.x) + (A.y * B.y) + ...
This is the length of each vector, calculated using the Pythagorean theorem. By dividing by the magnitudes, we "normalize" the vectors, effectively ignoring their lengths and focusing only on their direction.
Use the controls and presets to explore the concept.
How do we measure how "similar" two things are, especially when they are represented as lists of numbers (vectors)? While we could measure the distance between their endpoints (Euclidean distance), Cosine Similarity offers a different perspective: it measures the angle between two vectors. This simple but powerful idea is fundamental to modern AI, from search engines to recommendation systems. This 3D lab lets you build an intuition for what that angle really means.