Interface DistanceEstimator
- All Known Implementing Classes:
RaBitDistanceEstimator
Metric but may add behavior on top of the raw metric — for example, applying a
quantization-aware fast path when one or both vectors are encoded.
Search and clustering algorithms drive vector comparisons through this interface so they can stay agnostic of how distances are actually computed (raw metric, rabitq estimator, etc.).
-
Method Summary
Modifier and TypeMethodDescriptiondoubledistance(RealVector vector1, RealVector vector2) Calculates the distance between two vectors that have already been transformed into the estimator's coordinate system.default doubledistance(Transformed<? extends RealVector> vector1, Transformed<? extends RealVector> vector2) Convenience overload ofdistance(RealVector, RealVector)that unwraps the underlying vectors fromTransformedcontainers and forwards to theRealVectorvariant.Returns the underlyingMetricthis estimator computes.booleanisOptimized(RealVector vector1, RealVector vector2) Returns whether this estimator can compute the distance betweenvector1andvector2on a metric-specific fast path that bypasses the raw metric.default booleanisOptimized(Transformed<? extends RealVector> vector1, Transformed<? extends RealVector> vector2) Convenience overload ofisOptimized(RealVector, RealVector)that unwraps the underlying vectors fromTransformedcontainers and forwards to theRealVectorvariant.static DistanceEstimatorReturns a plainDistanceEstimatorthat delegates straight tometric.distance(...).
-
Method Details
-
getMetric
Returns the underlyingMetricthis estimator computes. -
isOptimized
default boolean isOptimized(@Nonnull Transformed<? extends RealVector> vector1, @Nonnull Transformed<? extends RealVector> vector2) Convenience overload ofisOptimized(RealVector, RealVector)that unwraps the underlying vectors fromTransformedcontainers and forwards to theRealVectorvariant. -
isOptimized
Returns whether this estimator can compute the distance betweenvector1andvector2on a metric-specific fast path that bypasses the raw metric. For example, a quantization-aware estimator may reporttruewhen at least one of the vectors is in the encoded form it knows how to consume directly.Default
ofMetric-built estimators have no fast path and always returnfalse. Callers can use this hint to skip work that is only worthwhile for the generic path (e.g. avoiding decode of an encoded vector if both will go through the estimator's fast path anyway).- Parameters:
vector1- the first vectorvector2- the second vector- Returns:
trueiff this estimator has a metric-specific fast path for the given pair
-
distance
default double distance(@Nonnull Transformed<? extends RealVector> vector1, @Nonnull Transformed<? extends RealVector> vector2) Convenience overload ofdistance(RealVector, RealVector)that unwraps the underlying vectors fromTransformedcontainers and forwards to theRealVectorvariant. -
distance
Calculates the distance between two vectors that have already been transformed into the estimator's coordinate system.Both arguments must already have been rotated/translated as expected by the estimator before calling this method — implementations do not apply any preprocessing. Implementations may reject distance values that are not finite (depending on the metric and on whether the inputs are zero vectors, etc.) by throwing an
IllegalArgumentException.- Parameters:
vector1- the first pre-rotated and translated vectorvector2- the second pre-rotated and translated vector- Returns:
- a non-negative
doublerepresenting the distance between the two vectors
-
ofMetric
Returns a plainDistanceEstimatorthat delegates straight tometric.distance(...). The result has no fast path (isOptimized(com.apple.foundationdb.linear.Transformed<? extends com.apple.foundationdb.linear.RealVector>, com.apple.foundationdb.linear.Transformed<? extends com.apple.foundationdb.linear.RealVector>)is alwaysfalse) and rejects non-finite distances with anIllegalArgumentException.- Parameters:
metric- the metric to wrap- Returns:
- a non-null estimator that computes
metric's distance directly
-