Documentation
¶
Index ¶
- Constants
- type DistanceEstimate
- type EncodedVector
- type Metric
- type Quantizer
- func (q *Quantizer) Decode(storedBytes []byte, numDimensions int) ([]float64, error)
- func (q *Quantizer) Distance(query []float64, storedBytes []byte, numDimensions int) (float64, error)
- func (q *Quantizer) Encode(vector []float64) []byte
- func (q *Quantizer) GetTypeByte() byte
- func (q *Quantizer) NewScorer(query []float64) *Scorer
- type RaBitEstimator
- type RaBitQuantizer
- type Scorer
Constants ¶
const TypeByte byte = 3
TypeByte is the wire ordinal for RaBitQ-encoded vectors. Matches Java's VectorType.RABITQ.ordinal() = 3.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistanceEstimate ¶
DistanceEstimate holds estimated distance and error bound.
type EncodedVector ¶
type EncodedVector struct {
// Encoded stores one quantized level per dimension.
// Each value is in [0, 2^(numExBits+1) - 1].
// Matches Java's int[] encoded field.
Encoded []int
// FAddEx is the precomputed additive factor (||residual||^2 for Euclidean metrics).
FAddEx float64
// FRescaleEx is the precomputed rescale factor for the dot product term.
FRescaleEx float64
// FErrorEx is the precomputed error bound scaling factor.
FErrorEx float64
// NumExBits is the number of extra bits used for quantization (1-8).
NumExBits int
}
EncodedVector is the quantized representation of a real vector using RaBitQ. Wire-compatible with Java's EncodedRealVector.
func EncodedVectorFromBytes ¶
func EncodedVectorFromBytes(data []byte, numDimensions, numExBits int) (*EncodedVector, error)
EncodedVectorFromBytes deserializes an EncodedVector from bytes. Wire-compatible with Java's EncodedRealVector.fromBytes().
func (*EncodedVector) NumDimensions ¶
func (e *EncodedVector) NumDimensions() int
NumDimensions returns the number of dimensions of the encoded vector.
func (*EncodedVector) ToBytes ¶
func (e *EncodedVector) ToBytes() []byte
ToBytes serializes the encoded vector to bytes, wire-compatible with Java's EncodedRealVector.getRawData(). Format:
[1 byte: type ordinal 3 = RABITQ] [8 bytes: fAddEx as big-endian float64] [8 bytes: fRescaleEx as big-endian float64] [8 bytes: fErrorEx as big-endian float64] [remaining: bit-packed encoded components, big-endian]
Each component is packed in (numExBits+1) bits, big-endian bit order.
type Metric ¶
type Metric int
Metric identifies a distance metric for RaBitQ quantization. Values match recordlayer.VectorMetric so that a simple type conversion works.
type Quantizer ¶
type Quantizer struct {
// contains filtered or unexported fields
}
Quantizer implements recordlayer.VectorQuantizer using RaBitQ.
func NewQuantizer ¶
NewQuantizer creates a new RaBitQ quantizer implementing VectorQuantizer. numExBits is clamped to [1, 8]; out-of-range values default to 4.
func (*Quantizer) Decode ¶
Decode reconstructs an approximate float64 vector from stored quantized bytes. Used for pairwise distance in the neighbor selection heuristic.
func (*Quantizer) Distance ¶
func (q *Quantizer) Distance(query []float64, storedBytes []byte, numDimensions int) (float64, error)
Distance estimates the distance between a raw query vector and stored quantized bytes. Returns the estimated distance.
func (*Quantizer) GetTypeByte ¶
GetTypeByte returns the type ordinal byte used as the first byte of encoded data.
type RaBitEstimator ¶
RaBitEstimator estimates distance between a raw query vector and an encoded vector. Matches Java's RaBitEstimator.
func NewRaBitEstimator ¶
func NewRaBitEstimator(metric Metric, numExBits int) *RaBitEstimator
NewRaBitEstimator creates a new estimator with the given metric and precision.
func (*RaBitEstimator) Distance ¶
func (e *RaBitEstimator) Distance(query []float64, encoded *EncodedVector) (float64, error)
Distance returns the estimated distance between a raw query and an encoded vector. Returns an error if the result is non-finite (Inf or NaN), matching Java's behavior of throwing on non-finite distance estimates.
func (*RaBitEstimator) EstimateDistance ¶
func (e *RaBitEstimator) EstimateDistance(query []float64, encoded *EncodedVector) DistanceEstimate
EstimateDistance estimates the distance between a raw query vector and an encoded vector, returning both the estimated distance and the error bound. Matches Java's RaBitEstimator.estimateDistanceAndErrorBound().
type RaBitQuantizer ¶
RaBitQuantizer implements the RaBitQ quantization scheme for compressing high-dimensional vectors into compact integer-based representations. Matches Java's RaBitQuantizer.
func NewRaBitQuantizer ¶
func NewRaBitQuantizer(metric Metric, numExBits int) *RaBitQuantizer
NewRaBitQuantizer creates a new quantizer with the given metric and bit precision. numExBits must be in [1, 8].
func (*RaBitQuantizer) Encode ¶
func (q *RaBitQuantizer) Encode(vec []float64) *EncodedVector
Encode quantizes a real-valued vector into an EncodedVector. Matches Java's RaBitQuantizer.encode().
type Scorer ¶
type Scorer struct {
// contains filtered or unexported fields
}
Scorer is a single-threaded, per-query distance estimator: the query's self-dot is computed ONCE and the component buffer is reused across codes. The general Distance path paid a fresh []int allocation, a bit-unpack, an estimator construction AND a re-derived query norm PER CODE — at SPFresh posting-scan volume (thousands of codes per query) that overhead dominated the estimate cost (RFC-094 094.4 tuning).