Skip to main content
InterviewHubPRO
Section Overview
Q4

Question 4 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

8%
Vector DBs & RAG (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is Cosine Similarity and how does it compare to Dot Product and Euclidean (L2) distance?

junior LevelCode ExampleCLI

In Simple Words: These are the three primary distance metrics used to measure vector closeness:

  1. Cosine Similarity: Measures the cosine of the angle between two vectors (-1 to 1). It ignores vector magnitude (length); ideal when text lengths vary significantly.
  2. Dot Product (Inner Product): Multiplies matching coordinates. If vectors are normalized to unit length (magnitude = 1), Dot Product equals Cosine Similarity and is computationally faster.
  3. Euclidean Distance (L2): Measures the straight-line geometric distance between vector endpoints in N-dimensional Euclidean space. Shorter distance means higher similarity.
text
Formulas:
Cosine Similarity:  cos(θ) = (A · B) / (||A|| * ||B||)
Dot Product:        A · B  = Σ (Ai * Bi)
Euclidean (L2):     ||A - B|| = sqrt(Σ (Ai - Bi)²)