pub struct RaBitQCodebook {
pub config: RaBitQConfig,
pub random_signs: Vec<i8>,
pub random_perm: Vec<u32>,
pub version: u64,
}Expand description
RaBitQ codebook (random transform parameters)
Trained once, shared across all segments for merge compatibility.
Fields§
§config: RaBitQConfigConfiguration
random_signs: Vec<i8>Random signs for transform (+1 or -1)
random_perm: Vec<u32>Random permutation for transform
version: u64Version for merge compatibility checking
Implementations§
Source§impl RaBitQCodebook
impl RaBitQCodebook
Sourcepub fn new(config: RaBitQConfig) -> Self
pub fn new(config: RaBitQConfig) -> Self
Create a new RaBitQ codebook with random transform
Sourcepub fn encode(
&self,
vector: &[f32],
centroid: Option<&[f32]>,
) -> QuantizedVector
pub fn encode( &self, vector: &[f32], centroid: Option<&[f32]>, ) -> QuantizedVector
Encode a vector to binary quantized form
If centroid is provided, encodes the residual (vector - centroid).
Sourcepub fn prepare_query(
&self,
query: &[f32],
centroid: Option<&[f32]>,
) -> QuantizedQuery
pub fn prepare_query( &self, query: &[f32], centroid: Option<&[f32]>, ) -> QuantizedQuery
Prepare a query for fast distance estimation
Sourcepub fn estimate_distance(
&self,
query: &QuantizedQuery,
code: &QuantizedVector,
) -> f32
pub fn estimate_distance( &self, query: &QuantizedQuery, code: &QuantizedVector, ) -> f32
Estimate squared distance between query and a quantized vector
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Memory usage in bytes
Trait Implementations§
Source§impl Clone for RaBitQCodebook
impl Clone for RaBitQCodebook
Source§fn clone(&self) -> RaBitQCodebook
fn clone(&self) -> RaBitQCodebook
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RaBitQCodebook
impl Debug for RaBitQCodebook
Source§impl<'de> Deserialize<'de> for RaBitQCodebook
impl<'de> Deserialize<'de> for RaBitQCodebook
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Quantizer for RaBitQCodebook
impl Quantizer for RaBitQCodebook
Source§type Code = QuantizedVector
type Code = QuantizedVector
The quantized code type
Source§type Config = RaBitQConfig
type Config = RaBitQConfig
Configuration type
Source§type QueryData = QuantizedQuery
type QueryData = QuantizedQuery
Query-specific precomputed data for fast distance computation
Source§fn encode(&self, vector: &[f32], centroid: Option<&[f32]>) -> Self::Code
fn encode(&self, vector: &[f32], centroid: Option<&[f32]>) -> Self::Code
Encode a vector (optionally relative to a centroid)
Source§fn prepare_query(
&self,
query: &[f32],
centroid: Option<&[f32]>,
) -> Self::QueryData
fn prepare_query( &self, query: &[f32], centroid: Option<&[f32]>, ) -> Self::QueryData
Prepare query-specific data for fast distance computation
Source§fn compute_distance(
&self,
query_data: &Self::QueryData,
code: &Self::Code,
) -> f32
fn compute_distance( &self, query_data: &Self::QueryData, code: &Self::Code, ) -> f32
Compute approximate distance using precomputed query data
Source§fn size_bytes(&self) -> usize
fn size_bytes(&self) -> usize
Memory usage of the quantizer itself (codebooks, etc.)
Auto Trait Implementations§
impl Freeze for RaBitQCodebook
impl RefUnwindSafe for RaBitQCodebook
impl Send for RaBitQCodebook
impl Sync for RaBitQCodebook
impl Unpin for RaBitQCodebook
impl UnwindSafe for RaBitQCodebook
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.