Home Knowledge Base Cosine Similarity

Cosine Similarity

Overview Cosine Similarity is the most common metric used to measure how similar two documents (vectors) are, irrespective of their size. It measures the cosine of the angle between two vectors projected in a multi-dimensional space.

Formula $$ ext{similarity} = cos( heta) = frac{A cdot B}{|A| |B|}$$

Why not Euclidean Distance? Euclidean distance measures the magnitude.

For text search, we usually care about the topic (angle), not the frequency (length), making Cosine Similarity superior.

Optimization If vectors are normalized (length = 1), then $|A| = 1$ and $|B| = 1$. The formula simplifies to just the Dot Product ($A cdot B$), which is extremely fast to compute on hardware.

triplet lossmargindistance

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.