Cosine Similarity Calculator
Calculate the cosine similarity between two text/feature vectors (up to 6 dimensions). Used in NLP, recommendation systems, and information retrieval.
Results
What is it?
Cosine similarity measures the cosine of the angle between two vectors: cos(ฮธ) = (AยทB) / (โAโ ร โBโ). A value of 1 means identical direction (most similar), 0 means orthogonal (unrelated), and -1 means opposite. It is widely used to measure document similarity in NLP and find related items in recommendation systems because it is magnitude-independent.
How to use
Enter the numerical values for each dimension of the two vectors. For TF-IDF document comparison, each dimension represents a word and the value is its TF-IDF score. For word embeddings (Word2Vec, GloVe), enter the embedding values.
Example scenario
A = [3, 2, 1], B = [2, 3, 1]. Dot product = 3ร2 + 2ร3 + 1ร1 = 13. โAโ = โ14 โ 3.742, โBโ = โ14 โ 3.742. Cosine = 13/14 โ 0.929 โ the vectors are 92.9% similar.
Pro tip
Unlike Euclidean distance, cosine similarity ignores magnitude โ a document with 1000 words and the same proportional term distribution as a 100-word document will score equally similar to a query. This is why it is preferred for document length-normalised comparisons.