Perbandingan distance metrics untuk embedding search.
| Metric | Formula | Range | Best For |
|---|---|---|---|
| Cosine | cos(theta) = A.B / ( | A | |
| Euclidean | d = sqrt(sum(A-B)^2) | [0, inf) | Dense vectors, magnitude matters |
| Dot Product | A.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