Class RaBitDistanceEstimator

java.lang.Object
com.apple.foundationdb.rabitq.RaBitDistanceEstimator
All Implemented Interfaces:
DistanceEstimator

public class RaBitDistanceEstimator extends Object implements DistanceEstimator
  • Constructor Details

    • RaBitDistanceEstimator

      public RaBitDistanceEstimator(@Nonnull Metric metric, int numExBits)
  • Method Details

    • getMetric

      @Nonnull public Metric getMetric()
      Description copied from interface: DistanceEstimator
      Returns the underlying Metric this estimator computes.
      Specified by:
      getMetric in interface DistanceEstimator
    • isOptimized

      public boolean isOptimized(@Nonnull RealVector vector1, @Nonnull RealVector vector2)
      Description copied from interface: DistanceEstimator
      Returns whether this estimator can compute the distance between vector1 and vector2 on a metric-specific fast path that bypasses the raw metric. For example, a quantization-aware estimator may report true when 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 return false. 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).

      Specified by:
      isOptimized in interface DistanceEstimator
      Parameters:
      vector1 - the first vector
      vector2 - the second vector
      Returns:
      true iff this estimator has a metric-specific fast path for the given pair
    • getNumExBits

      public int getNumExBits()
    • distance

      public double distance(@Nonnull RealVector vector1, @Nonnull RealVector vector2)
      Description copied from interface: DistanceEstimator
      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.

      Specified by:
      distance in interface DistanceEstimator
      Parameters:
      vector1 - the first pre-rotated and translated vector
      vector2 - the second pre-rotated and translated vector
      Returns:
      a non-negative double representing the distance between the two vectors
    • estimateDistanceAndErrorBound

      @Nonnull public RaBitDistanceEstimator.Result estimateDistanceAndErrorBound(@Nonnull RealVector query, @Nonnull EncodedRealVector encodedVector)