Database / Milvus Vector database Interview questions
What is the difference between L2 and Cosine similarity in Milvus?
L2 (Euclidean) distance measures the straight-line distance between two vectors' endpoints in space, taking both their direction and their magnitude into account. Cosine similarity measures only the angle between two vectors, ignoring their magnitude entirely, so two vectors pointing in the same direction are considered maximally similar regardless of their length.
| L2 (Euclidean) | Cosine |
| Sensitive to vector magnitude. | Ignores vector magnitude entirely. |
| Smaller distance = more similar. | Higher cosine value = more similar. |
| Common for embeddings where scale is meaningful. | Common for text embeddings where direction (semantic meaning) matters more than scale. |
If an embedding model normalizes its output vectors to unit length before returning them, L2 distance and Cosine similarity become mathematically equivalent up to a monotonic transformation, which is why some embedding providers explicitly document their vectors as pre-normalized and default to recommending Cosine (or IP) regardless of which one a downstream system technically uses.
More Related questions...