Skip to main content
Distance metrics define how vectors are compared for similarity. Choosing the right metric is critical for accurate search results and depends on your embedding model.

Available Distance Metrics

Qdrant supports four distance metrics:

Cosine Similarity

Measures the angle between vectors, ignoring magnitude:
Formula:
Score Range: -1 (opposite) to 1 (identical) Characteristics:
  • Normalized: Vector magnitude doesn’t affect similarity
  • Order: Higher scores are better (maximization)
  • Symmetric: cosine(A, B) = cosine(B, A)
Cosine is the most common metric for semantic search and text embeddings. Most embedding models (OpenAI, Cohere, Sentence Transformers) are optimized for cosine similarity.

When to Use Cosine

✅ Use Cosine when:
  • Working with text embeddings (BERT, GPT, etc.)
  • Your embedding model outputs normalized vectors
  • You care about direction, not magnitude
  • Using pre-trained models (OpenAI, Cohere, etc.)
❌ Don’t use Cosine when:
  • Vector magnitude contains important information
  • Your model was specifically trained for Euclidean distance

Example: Text Similarity

Euclidean Distance (L2)

Measures straight-line distance between vectors:
Formula:
Score Range: 0 (identical) to ∞ (very different) Characteristics:
  • Magnitude-sensitive: Vector length affects distance
  • Order: Lower scores are better (minimization)
  • Symmetric: euclid(A, B) = euclid(B, A)
Euclidean distance considers both direction and magnitude. It’s commonly used for image embeddings and when vector magnitude is meaningful.

When to Use Euclidean

✅ Use Euclidean when:
  • Vector magnitude is meaningful
  • Working with image embeddings (ResNet, EfficientNet)
  • Your model was trained with Euclidean distance
  • You need geometric distance in embedding space
❌ Don’t use Euclidean when:
  • Vectors have inconsistent magnitudes
  • You only care about direction

Example: Spatial Distance

Dot Product

Computes the product of corresponding elements:
Formula:
Score Range: -∞ to ∞ Characteristics:
  • Unnormalized: Magnitude matters significantly
  • Order: Higher scores are better (maximization)
  • Symmetric: dot(A, B) = dot(B, A)
  • Efficient: Fastest to compute
Dot product is sensitive to vector magnitude. Longer vectors will have higher scores even if less similar in direction.

When to Use Dot Product

✅ Use Dot Product when:
  • Your vectors are pre-normalized
  • Working with binary or categorical features
  • Your model was specifically trained for dot product
  • Maximum computational efficiency is needed
❌ Don’t use Dot Product when:
  • Vectors have inconsistent magnitudes
  • You need normalized similarity scores

Relationship with Cosine

For normalized vectors (||v|| = 1), dot product equals cosine similarity:
If your model outputs normalized vectors, use Dot Product instead of Cosine for better performance.

Manhattan Distance (L1)

Sum of absolute differences:
Formula:
Score Range: 0 (identical) to ∞ (very different) Characteristics:
  • Axis-aligned: Measures distance along axes
  • Order: Lower scores are better (minimization)
  • Symmetric: manhattan(A, B) = manhattan(B, A)
  • Robust: Less sensitive to outliers than Euclidean

When to Use Manhattan

✅ Use Manhattan when:
  • Your features are independent/axis-aligned
  • You want robustness to outliers
  • Working with grid-like data
  • Your model was trained with Manhattan distance
❌ Don’t use Manhattan when:
  • Most embedding models (rarely optimized for L1)
  • You need standard semantic similarity
Manhattan is less common in vector search but useful for specialized applications where features are independent.

Score Ordering

Qdrant automatically handles score ordering. Top results always represent most similar vectors regardless of metric.

Common Embedding Models

Match your distance metric to your model:
Always check your model’s documentation for the recommended distance metric.

Performance Comparison

Threshold Filtering

Set minimum similarity thresholds:
Threshold direction depends on the metric:
  • Cosine/Dot: Use high thresholds (e.g., 0.7) to filter for similar items
  • Euclidean/Manhattan: Use low thresholds (e.g., 5.0) to filter for similar items

Choosing the Right Metric

Decision Flow

  1. Check your model’s documentation - Use the recommended metric
  2. Are vectors normalized?
    • Yes → Use Dot Product (fastest) or Cosine (more intuitive)
    • No → Continue to step 3
  3. Does magnitude matter?
    • No → Use Cosine
    • Yes → Use Euclidean
  4. Special requirements?
    • Need outlier robustness → Manhattan
    • Maximum speed → Dot Product (with normalization)

Quick Reference

Use Cosine. Nearly all text embedding models are optimized for cosine similarity.
Use Euclidean or Cosine. Check your model’s documentation. ResNets often use Euclidean, CLIP uses Cosine.
Use Dot Product if your vectors are pre-normalized. It’s computationally cheaper than Cosine.
Use Dot Product. It’s equivalent to Cosine but faster.

Vector Normalization

Normalize vectors for consistent Cosine/Dot Product behavior:
Many embedding models (OpenAI, Cohere) return pre-normalized vectors. Check before normalizing!

Best Practices

Dot Product is sensitive to magnitude. Normalize vectors first unless magnitude is meaningful.
Benchmark different metrics with your queries to find what works best in practice.
If using Cosine with normalized vectors, switch to Dot Product for better performance.
Use the same metric for indexing and querying. Mixing metrics will produce incorrect results.

Collections

Learn how to configure distance metrics in collections

Vectors

Understand vector types and preprocessing

Indexing

Explore how HNSW indexes work with distance metrics

Points

Learn how points store vectors for comparison