/** * Scalar Quantizer for Int8 vector compression * * Provides a one-byte-per-component traversal representation by converting * Float32 vectors to Int8. The production HNSW path retains Float32 vectors * for rescoring, so this is not a whole-index compression guarantee. Recall * and latency depend on the dataset and search configuration. * * Uses range quantization: maps [min, max] to [-128, 127]. */ export interface QuantizationParams { min: Float32Array; max: Float32Array; scale: Float32Array; offset: Float32Array; } export declare class ScalarQuantizer { private dimension; private params; private trained; constructor(dimension: number); getDimension(): number; /** * Train the quantizer on a set of vectors to determine optimal range */ train(vectors: Float32Array[]): void; /** * Get training status */ isTrained(): boolean; /** * Get quantization parameters */ getParams(): QuantizationParams | null; private validateParams; private validateVector; /** * Set quantization parameters (for loading saved quantizer) */ setParams(params: QuantizationParams): void; /** * Quantize a single float32 vector to int8 */ quantize(vector: Float32Array): Int8Array; /** * Quantize a float32 vector directly into a target Int8Array at the given offset. * Zero-allocation: avoids creating a new Int8Array per vector. * * @param vector Source float32 vector * @param target Target Int8Array to write into * @param targetOffset Byte offset in target where quantized values start */ quantizeInto(vector: Float32Array, target: Int8Array, targetOffset: number): void; /** * Quantize multiple vectors */ quantizeBatch(vectors: Float32Array[]): Int8Array[]; /** * Dequantize an int8 vector back to float32 (for rescoring) */ dequantize(vector: Int8Array): Float32Array; /** * Serialize quantization parameters for saving */ serialize(): ArrayBuffer; /** * Load quantization parameters */ static deserialize(buffer: ArrayBuffer): ScalarQuantizer; } /** * Fast Int8 distance calculations. * These kernels are optimized for quantized vectors; actual end-to-end speed * depends on runtime, dimensionality, and whether Float32 rescoring is used. */ /** * Compute dot product between two Int8 vectors * Uses 8-wide unrolling for better ILP (instruction-level parallelism) */ export declare function dotProductInt8(a: Int8Array, b: Int8Array): number; /** * Compute L2 squared distance between two Int8 vectors * Uses 8-wide unrolling for better ILP */ export declare function l2SquaredInt8(a: Int8Array, b: Int8Array): number; /** * Compute approximate cosine distance for Int8 vectors * Note: This is approximate because quantization changes magnitude * Uses 8-wide unrolling with separate accumulators for better ILP */ export declare function cosineDistanceInt8(a: Int8Array, b: Int8Array): number; //# sourceMappingURL=ScalarQuantizer.d.ts.map