Overview
MetricType defines the distance or similarity function used to compare vectors during search operations. The choice of metric affects search results and performance.
Available Metrics
Euclidean distance (L2 norm). Measures straight-line distance between two vectors in Euclidean space.Formula:
√(Σ(a[i] - b[i])²)Range: [0, ∞) (0 = identical, larger = more different)When to use: When magnitude matters, working with embeddings not normalized to unit length.Inner Product (dot product). Computes the dot product of two vectors.Formula:
Σ(a[i] × b[i])Range: (-∞, ∞) (larger = more similar)When to use: When vectors are already normalized, or working with models that output IP-optimized embeddings. Faster than cosine for unit-normalized vectors.Cosine similarity/distance. Measures the cosine of the angle between two vectors, normalized by their magnitudes.Formula:
1 - (a · b) / (||a|| × ||b||) (as distance)Range: [0, 2] as distance (0 = identical direction, 2 = opposite)When to use: When direction matters more than magnitude, comparing text embeddings, semantic similarity.Metric Properties
AllMetricType enum members have these properties:
The name of the metric as a string.
The internal integer value of the metric.
Usage Examples
Defining Vector Field with Metric
Querying with Different Metrics
Comparing Metrics
Choosing the Right Metric
Decision Guide
When to use COSINE
When to use COSINE
Best for:
- Text embeddings from language models (BERT, GPT, etc.)
- Semantic similarity tasks
- When vector magnitude is not meaningful
- Comparing documents of different lengths
- Normalized comparison (only direction matters)
- Range-independent
- Most common for text embeddings
- Document similarity
- Semantic search
- Recommendation systems
- Question answering
When to use IP (Inner Product)
When to use IP (Inner Product)
Best for:
- Pre-normalized embeddings (unit vectors)
- Maximum Inner Product Search (MIPS)
- Models specifically trained for IP
- Performance-critical applications with normalized vectors
- Fastest for unit-normalized vectors
- Equivalent to cosine for normalized vectors
- No magnitude normalization
- Retrieval with normalized embeddings
- Recommendation systems with pre-normalized features
- Real-time search with unit vectors
When to use L2
When to use L2
Best for:
- Embeddings where magnitude is meaningful
- Image embeddings
- Spatial data
- When distance in Euclidean space matters
- Considers both direction and magnitude
- Natural geometric interpretation
- Can be slower than IP for high dimensions
- Image similarity
- Spatial search
- Anomaly detection
- Clustering
Performance Comparison
Metric Equivalence for Normalized Vectors
For unit-normalized vectors (||v|| = 1):Working with Metrics in Reranking
MetricType is used in weighted reranking for score normalization:
Common Pitfalls
See Also
- Field Definition
- DataType - Vector data types
- WeightedReRanker - Score normalization with metrics
- IndexType - Index types for vector search