Cosine similarity compares vectors by direction rather than raw magnitude. In document retrieval, TF-IDF represents each document as a weighted feature vector, then uses the vectors’ directional agreement to measure document similarity. section 4.6.1 section 2.5.6
For vectors a and b, cosine similarity is the dot product divided by their lengths: cos(θ) = (a · b) / (||a|| ||b||). Equivalently, it is the dot product of unit-length versions of the vectors. The angle supplies the interpretation: aligned vectors score positively, perpendicular vectors score zero, and opposite vectors score negatively. section 2.5.6
In retrieval, the score has practical consequences:
- TF-IDF down-weights common terms and emphasizes distinctive terms before cosine comparison. section 4.6.1
- Cosine similarity detects direct vocabulary overlap, but misses semantic relationships expressed through different words. section 4.6.2
- Latent semantic analysis addresses this limitation by comparing document projections onto topic directions rather than only their original term vectors. section 4.6.2 section 4.7
A misleading zero
Documents d5 and d6 receive cosine similarity zero because one contains “gun” and the other “violence,” with no direct term overlap. Human readers may still recognize a relationship because those terms co-occur elsewhere; cosine similarity alone does not capture that secondary evidence. section 4.6.2
Equation 4.13
Use the equation figure to inspect the normalized dot-product calculation. section 4.6.1













