Class RaBitQuantizer

java.lang.Object
com.apple.foundationdb.rabitq.RaBitQuantizer
All Implemented Interfaces:
Quantizer

public final class RaBitQuantizer extends Object implements Quantizer
Implements the RaBit quantization scheme, a technique for compressing high-dimensional vectors into a compact integer-based representation.

This class provides the logic to encode a RealVector into an EncodedRealVector. The encoding process involves finding an optimal scaling factor, quantizing the vector's components, and pre-calculating values that facilitate efficient distance estimation in the quantized space. It is configured with a specific Metric and a number of "extra bits" (numExBits) which control the precision of the quantization.

Note that this implementation largely follows this paper by Jianyang Gao et al. It also mirrors algorithmic similarity, terms, and variable/method naming-conventions of the C++ implementation that can be found here.

See Also:
  • Constructor Details

    • RaBitQuantizer

      public RaBitQuantizer(@Nonnull Metric metric, int numExBits)
      Constructs a new RaBitQuantizer instance.

      This constructor initializes the quantizer with a specific metric and the number of extra bits to be used in the quantization process.

      Parameters:
      metric - the Metric to be used for quantization; must not be null.
      numExBits - the number of extra bits for quantization.
  • Method Details

    • estimator

      @Nonnull public RaBitEstimator estimator()
      Creates and returns a new RaBitEstimator instance.

      This method acts as a factory, constructing the estimator based on the metric and numExBits configuration of this object. The @Override annotation indicates that this is an implementation of a method from a superclass or interface.

      Specified by:
      estimator in interface Quantizer
      Returns:
      a new, non-null instance of RaBitEstimator
    • encode

      @Nonnull public EncodedRealVector encode(@Nonnull RealVector vector)
      Encodes a given RealVector into its corresponding encoded representation.

      This method overrides the parent's encode method. It delegates the core encoding logic to an internal helper method and returns the final EncodedRealVector.

      Specified by:
      encode in interface Quantizer
      Parameters:
      vector - the RealVector to be encoded; must not be null.
      Returns:
      the resulting EncodedRealVector, guaranteed to be non-null.