Perbandingan distance metrics untuk embedding search.

MetricFormulaRangeBest For
Cosinecos(theta) = A.B / (A
Euclideand = sqrt(sum(A-B)^2)[0, inf)Dense vectors, magnitude matters
Dot ProductA.B = sum(AxB)(-inf, inf)Unnormalized, speed-optimized

When to Use

  • Cosine: text search, document similarity, RAG (OpenAI embeddings)
  • Euclidean: image similarity, clustering (k-means)
  • Dot Product: fast search with normalized vectors