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: u8Oversample 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
impl BbqCodec
Sourcepub const ENVELOPE_MAGIC: &'static [u8; 5] = b"NDBBQ"
pub const ENVELOPE_MAGIC: &'static [u8; 5] = b"NDBBQ"
On-disk magic for BBQ codec envelopes.
Sourcepub const ENVELOPE_VERSION: u8 = 1
pub const ENVELOPE_VERSION: u8 = 1
Current on-disk envelope version for BBQ codecs.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, CodecError>
pub fn to_bytes(&self) -> Result<Vec<u8>, CodecError>
Serialize this codec to a self-describing byte buffer.
Sourcepub fn from_bytes(buf: &[u8]) -> Result<Self, CodecError>
pub fn from_bytes(buf: &[u8]) -> Result<Self, CodecError>
Deserialize a codec from a byte buffer produced by Self::to_bytes.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for BbqCodec
impl<'de> Deserialize<'de> for BbqCodec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'__msgpack_de> FromMessagePack<'__msgpack_de> for BbqCodec
impl<'__msgpack_de> FromMessagePack<'__msgpack_de> for BbqCodec
Source§impl ToMessagePack for BbqCodec
impl ToMessagePack for BbqCodec
Source§impl VectorCodec for BbqCodec
impl VectorCodec for BbqCodec
Source§fn fast_symmetric_distance(&self, q: &BbqQuantized, v: &BbqQuantized) -> f32
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
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
type Quantized = BbqQuantized
UnifiedQuantizedVector
reference via AsRef.Source§fn encode(&self, v: &[f32]) -> BbqQuantized
fn encode(&self, v: &[f32]) -> BbqQuantized
Source§fn prepare_query(&self, q: &[f32]) -> BbqQuery
fn prepare_query(&self, q: &[f32]) -> BbqQuery
Auto Trait Implementations§
impl Freeze for BbqCodec
impl RefUnwindSafe for BbqCodec
impl Send for BbqCodec
impl Sync for BbqCodec
impl Unpin for BbqCodec
impl UnsafeUnpin for BbqCodec
impl UnwindSafe for BbqCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> FromMessagePackOwned for Twhere
T: for<'a> FromMessagePack<'a>,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.