Cosine Similarity Calculator

Enter two vectors (like text embeddings) to calculate their cosine similarity, the standard measure of semantic closeness.

Advertisement
ℹ️Enter comma-separated numbers for each vector. Both vectors must have the same number of dimensions.
Cosine Similarity
Dot Product
‖A‖ Magnitude
‖B‖ Magnitude
Angle (degrees)
Advertisement

What Cosine Similarity Measures

Cosine similarity measures the angle between two vectors, not their magnitude or distance, producing a value between -1 (pointing in exactly opposite directions) and 1 (pointing in exactly the same direction), with 0 meaning the vectors are orthogonal (unrelated). This makes it fundamentally different from Euclidean distance, two vectors can be very far apart in raw magnitude while still pointing in nearly the same direction, and cosine similarity would correctly identify them as similar, which is exactly the property that makes it useful for comparing text embeddings.

Why Cosine Similarity Is Central to Modern NLP

Every modern semantic search system, recommendation engine, and RAG (Retrieval-Augmented Generation) pipeline relies on embeddings, dense vector representations where semantically similar text maps to nearby vectors in high-dimensional space. Cosine similarity is the standard way to compare these embeddings, when you search a vector database for "documents similar to this query," the underlying operation is almost always computing cosine similarity between the query embedding and every candidate document's embedding, then returning the highest-scoring matches.

Why Not Just Use Euclidean Distance?

Embeddings are often not normalized to a fixed length, meaning their raw magnitude can vary based on factors unrelated to meaning, like text length or how "confident" the model was in its representation. Cosine similarity sidesteps this entirely by ignoring magnitude and only comparing direction, two embeddings representing the same concept should point the same direction in vector space regardless of their individual lengths. This is why cosine similarity, not Euclidean distance, is the default metric in essentially every production embedding-based search system.

Interpreting Cosine Similarity Values in Practice

With modern sentence embedding models, values above 0.8 typically indicate genuinely similar or paraphrased content, values in the 0.5-0.7 range often indicate related but distinct topics, and values below 0.3 usually indicate unrelated content. These thresholds vary somewhat by embedding model and domain, always calibrate against known similar/dissimilar pairs in your specific use case rather than assuming universal thresholds, since different embedding models compress similarity into different numeric ranges.