Documentation
¶
Index ¶
- Constants
- func DotFour(c0, c1, c2, c3 *Code, q []float64) (d0, d1, d2, d3 float64)
- func DotPairs(c0, c1 *Code, q0, q1 []float64) (d00, d01, d10, d11 float64)
- func ValidNumExBits(numExBits int) bool
- type Code
- type DistanceEstimate
- type EncodedVector
- type Metric
- type Quantizer
- func (q *Quantizer) Decode(storedBytes []byte, numDimensions int) ([]float64, error)
- func (q *Quantizer) DecodeCode(storedBytes []byte, numDimensions int) ([]float64, *Code, error)
- func (q *Quantizer) Distance(query []float64, storedBytes []byte, numDimensions int) (float64, error)
- func (q *Quantizer) DistanceCode(query []float64, code *Code) (float64, error)
- func (q *Quantizer) Encode(vector []float64) []byte
- func (q *Quantizer) GetTypeByte() byte
- func (q *Quantizer) NewScorer(query []float64) *Scorer
- func (q *Quantizer) NumExBits() int
- 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 ¶
func DotPairs ¶
DotPairs is Dot of codes c0 and c1, of one length, with queries q0 and q1, each at least that long: four interleaved sums, not inlined so that they stay in registers.
func ValidNumExBits ¶
ValidNumExBits reports whether the encoder supports numExBits extra bits: 1 to 8, the range Java's RaBitQuantizer constructor checks (RaBitQuantizer.java:76, TIGHT_START's length).
Types ¶
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
Code is a stored code decoded once, so estimates against it skip the unpack.
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 vectorindex.VectorMetric so that a simple type conversion works.
type Quantizer ¶
type Quantizer struct {
// contains filtered or unexported fields
}
Quantizer implements vectorindex.VectorQuantizer using RaBitQ.
func NewQuantizer ¶
NewQuantizer creates a new RaBitQ quantizer implementing VectorQuantizer. numExBits is kept as given: a count outside what the encoder supports (ValidNumExBits) is refused by the caller where it first quantizes, as Java refuses it where it constructs its RaBitQuantizer, never replaced by another count, which would store codes of a width the configuration does not name.
func (*Quantizer) Decode ¶
Decode reconstructs an approximate float64 vector from stored quantized bytes. Used for pairwise distance in the neighbor selection heuristic.
func (*Quantizer) DecodeCode ¶
DecodeCode is Decode that also returns the code, from the same unpack.
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) DistanceCode ¶
DistanceCode is Distance to the bytes code was decoded from by this quantizer.
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).