Cosine similarity measures the angle between two vectors and ignores their length. Take the dot product of the two vectors and divide by the product of their lengths: the result is the cosine of the angle between them. Vectors pointing the same way score 1, perpendicular vectors score 0, and opposite vectors score -1.
Why angle, not distance
Information retrieval made the cosine standard. Represent each document as a vector of word counts, and a long document and a short one about the same topic point the same way while sitting far apart, simply because one has more words. Manning, Raghavan and Schütze’s textbook gives exactly this reason for using the cosine: it compensates for document length. Measuring the angle compares what two things are about rather than how much of it there is.
Where you meet it
The same logic carries over to embeddings. Models place words, sentences and images in a vector space where related items point in similar directions, and cosine similarity is the usual score for how related two of them are. The word2vec paper answered analogy questions by finding the word vector closest to a computed one under cosine distance (the paper).
Today it is the default comparison in semantic search, in vector databases, and in the retrieval step of RAG: embed the question, then return the stored passages with the highest cosine similarity. Contrastive models such as CLIP are trained so that matching pairs score high on it.
A practical note: if every vector is normalized to length 1 first, cosine similarity is just the dot product, which is why many systems normalize embeddings once and then use fast dot-product search. And a high score means the model placed two items close together, not that they are true, relevant or interchangeable.