Skip to main content

BbqCodec

Struct BbqCodec 

Source
pub struct BbqCodec {
    pub dim: usize,
    pub oversample: u8,
    /* private fields */
}
Expand description

BBQ centroid-centered asymmetric 1-bit quantization codec.

Calibration computes the dataset centroid which is subtracted from each vector before sign quantization. The resulting 1-bit codes are Hamming- coarse-comparable; exact rerank uses the 14-byte corrective factors stored in the unified header.

Fields§

§dim: usize§oversample: u8

Oversample multiplier for the caller’s rerank pass. Caller fetches oversample × top_k coarse candidates from the Hamming coarse pass, then calls exact_asymmetric_distance on each.

Implementations§

Source§

impl BbqCodec

Source

pub fn calibrate(vectors: &[&[f32]], dim: usize, oversample: u8) -> Self

Calibrate a new BbqCodec from a set of training vectors.

Computes the centroid as the mean of all training vectors.

§Panics

Does not panic; returns a zero-centroid codec if vectors is empty.

Trait Implementations§

Source§

impl VectorCodec for BbqCodec

Source§

fn fast_symmetric_distance(&self, q: &BbqQuantized, v: &BbqQuantized) -> f32

Fast Hamming-based symmetric distance estimate.

Uses the asymmetric corrective distance formula: approx = q_n² + v_n² − 2 · q_n · v_n · dot_estimate where dot_estimate = 1 − 2·hamming/dim maps the Hamming count to a normalised cosine-like similarity on {−1,+1} codes.

Source§

fn exact_asymmetric_distance(&self, q: &BbqQuery, v: &BbqQuantized) -> f32

Exact asymmetric L2 distance using the dequantized stored vector.

The query is exact centered FP32 (q.centered). The stored vector is reconstructed from its sign bits and residual_norm via BbqCodec::dequantize: each dimension ≈ ±residual_norm / √dim. This is the high-fidelity asymmetric path invoked during rerank on the oversample × top_k candidates returned by the coarse Hamming pass.

Source§

type Quantized = BbqQuantized

The packed quantized form. Must be convertible to a UnifiedQuantizedVector reference via AsRef.
Source§

type Query = BbqQuery

The prepared query form (codec-specific).
Source§

fn encode(&self, v: &[f32]) -> BbqQuantized

Encode a single FP32 vector into the codec’s packed form.
Source§

fn prepare_query(&self, q: &[f32]) -> BbqQuery

Prepare a query for distance computations against this codec. May rotate, normalize, build a LUT, etc.
Source§

fn adc_lut(&self, _q: &Self::Query) -> Option<AdcLut>

Optional: precompute ADC lookup table for codecs that use one (PQ, IVF-PQ, TurboQuant). Returns None for codecs that don’t (RaBitQ, BBQ, ternary, binary).
Source§

fn train(&mut self, samples: &[&[f32]]) -> Result<(), CodecError>

Optional: fit the codec’s learned parameters on a set of training vectors. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.