What is Cosine similarity?
In Turkish: Kosinüs benzerliği · Topic: Math foundations
A way of measuring how closely two vectors point in the same direction by looking at the angle between them. In AI it is used to compare the meaning of texts, images and other data.
How does it work?
Texts and images are first converted into vectors called embeddings. Cosine similarity then computes the cosine of the angle between two such vectors. Vectors pointing the same way score the maximum of 1, perpendicular ones score 0, and opposite ones score -1. Because it looks at direction rather than length, a long text and a short text on the same topic can still score high. Search systems use this score to rank results.
Why does it matter?
Semantic search, recommendation systems and retrieval-augmented generation (RAG) all rely on a 'find the most similar content' step, and cosine similarity is one of the most common measures used for it. Which documents count as closest to a query determines whether the system reaches the right source.
Example
In a company's internal search tool, the vector for 'how do I apply for leave' scores high against the 'annual leave request form' document, even though the wording differs.
FAQ
What is the difference between cosine similarity and Euclidean distance?
Euclidean distance measures the straight-line gap between the tips of two vectors and is affected by their length, while cosine similarity looks only at direction. If the vectors are normalized to the same length, both produce the same ranking.
Does a cosine similarity of 1 mean two texts are identical?
No. It only says the two vectors point in the same direction. The texts may be very close in meaning without being word-for-word the same.