Cosine similarity compares the direction of two vectors. It is widely used in semantic search because two pieces of text can point in a similar direction even when their vector lengths differ.
This playground uses a small set of four-dimensional word vectors with named features such as natural versus artificial and safe versus dangerous. The vectors are hand-authored so the calculation is easy to inspect. A real embedding model learns hundreds or thousands of dimensions from data, and people usually cannot assign a simple label to each one.
The angle diagram is reconstructed from the cosine score across all four dimensions. It is not a two-dimensional projection that drops part of the calculation.
Try this:
- Start with puppy and dog. Their feature patterns point in nearly the same direction, so the cosine score is close to 1.
- Choose contrasting weather. Sunshine and blizzard disagree across several dimensions, producing a negative score and an angle greater than 90 degrees.
- Inspect each product. Positive products increase alignment; negative products pull the score down.
- Scale the second vector. The dot product and magnitude change, but cosine similarity remains fixed because the direction does not change.
- Open “A useful warning.” Wolf and storm score highly in this toy space even though they are not synonyms. Cosine compares vectors, so the embedding model must create useful vectors before the metric can produce useful rankings.