|  | 
| 22 | 22 | 
 | 
| 23 | 23 | import javax.annotation.Nonnull; | 
| 24 | 24 | 
 | 
|  | 25 | +/** | 
|  | 26 | + * Defines the contract for a quantizer, a component responsible for encoding data vectors into a different, ideally | 
|  | 27 | + * a more compact, representation. | 
|  | 28 | + * <p> | 
|  | 29 | + * Quantizers are typically used in machine learning and information retrieval to transform raw data into a format that | 
|  | 30 | + * is more suitable for processing, such as a compressed representation. | 
|  | 31 | + */ | 
| 25 | 32 | public interface Quantizer { | 
|  | 33 | +    /** | 
|  | 34 | +     * Returns the {@code Estimator} instance associated with this object. | 
|  | 35 | +     * <p> | 
|  | 36 | +     * The estimator is responsible for performing the primary distance estimation or calculation logic. This method | 
|  | 37 | +     * provides access to that underlying component. | 
|  | 38 | +     * | 
|  | 39 | +     * @return the {@link Estimator} instance, which is guaranteed to be non-null. | 
|  | 40 | +     */ | 
| 26 | 41 |     @Nonnull | 
| 27 | 42 |     Estimator estimator(); | 
| 28 | 43 | 
 | 
|  | 44 | +    /** | 
|  | 45 | +     * Encodes the given data vector into another vector representation. | 
|  | 46 | +     * <p> | 
|  | 47 | +     * This method transforms the raw input data into a different, quantized format, which is often a vector more | 
|  | 48 | +     * suitable for processing/storing the data. The specifics of the encoding depend on the implementation of the class. | 
|  | 49 | +     * | 
|  | 50 | +     * @param data the input {@link RealVector} to be encoded. Must not be {@code null} and is assumed to have been | 
|  | 51 | +     *        preprocessed, such as by rotation and/or translation. The preprocessing has to align with the requirements | 
|  | 52 | +     *        of the specific quantizer. | 
|  | 53 | +     * @return the encoded vector representation of the input data, guaranteed to be non-null. | 
|  | 54 | +     */ | 
| 29 | 55 |     @Nonnull | 
| 30 | 56 |     RealVector encode(@Nonnull RealVector data); | 
| 31 | 57 | 
 | 
|  | 58 | +    /** | 
|  | 59 | +     * Creates a no-op {@code Quantizer} that does not perform any data transformation. | 
|  | 60 | +     * <p> | 
|  | 61 | +     * The returned quantizer's {@link Quantizer#encode(RealVector)} method acts as an | 
|  | 62 | +     * identity function, returning the input vector without modification. The | 
|  | 63 | +     * {@link Quantizer#estimator()} is created directly from the distance function | 
|  | 64 | +     * of the provided {@link Metric}. This can be useful for baseline comparisons | 
|  | 65 | +     * or for algorithms that require a {@code Quantizer} but where no quantization | 
|  | 66 | +     * is desired. | 
|  | 67 | +     * | 
|  | 68 | +     * @param metric the {@link Metric} used to build the distance estimator for the quantizer. | 
|  | 69 | +     * @return a new {@link Quantizer} instance that performs no operation. | 
|  | 70 | +     */ | 
| 32 | 71 |     @Nonnull | 
| 33 | 72 |     static Quantizer noOpQuantizer(@Nonnull final Metric metric) { | 
| 34 | 73 |         return new Quantizer() { | 
|  | 
0 commit comments