Skip to main content
AI / MLRetrieval & RAGDiagramBeginner

Cosine Similarity

KO: 코사인 유사도·EN: Cosine Similarity·JA: コサイン類似度

A metric that measures semantic similarity between two embedding vectors by the cosine of the angle between them (-1 to 1), independent of vector magnitude

Table of Contents

Structure Diagram

Cosine Similarity cos(θ) Across Vector Angles
Angle θ (deg) →Score
(60, 50)60°: Moderate (+0.50)
Quick Answer

What is Cosine Similarity?

A metric that measures semantic similarity between two embedding vectors by the cosine of the angle between them (-1 to 1), independent of vector magnitude. It is a core concept in Retrieval & RAG within AI / ML.

Core Principles

Cosine Similarity measures the cosine of the angle between two vectors: cos(θ) = (A · B) / (‖A‖ · ‖B‖). Values range from -1 (opposite) through 0 (orthogonal/unrelated) to +1 (identical direction).

Because it ignores vector magnitude and focuses purely on orientation, cosine similarity compares semantic meaning reliably across texts of different lengths.

Practical Takeaways

  • Use Dot Product on L2-normalized embeddings: Most modern embedding APIs output unit-length vectors (||v|| = 1), making Dot Product mathematically identical to Cosine Similarity while avoiding extra normalization compute.
  • Never hardcode universal score thresholds: A score of 0.75 may signal a strong match in one embedding model and noise in another. Always calibrate cutoffs on your own evaluation queries.
  • Watch Cosine Similarity vs Cosine Distance: Many vector databases return distance = 1 - similarity (lower is better). Double-check sort order and threshold comparisons.

Notable Examples

  • RAG Top-K Retrieval: Ranks document chunks by cosine similarity against the embedded user query.
  • Semantic Caching: Triggers a cache hit when incoming query embeddings exceed a calibrated cosine threshold.
  • Content Recommendations: Matches a user's interest vector against catalog embeddings.