pub struct RaBitQIndex {
pub config: RaBitQConfig,
pub centroid: Vec<f32>,
pub random_signs: Vec<i8>,
pub random_perm: Vec<u32>,
pub vectors: Vec<QuantizedVector>,
pub raw_vectors: Option<Vec<Vec<f32>>>,
}Expand description
RaBitQ index for dense vector search
Fields§
§config: RaBitQConfigConfiguration
centroid: Vec<f32>Centroid of all indexed vectors
random_signs: Vec<i8>Random orthogonal matrix P (stored as flat array, row-major) For efficiency, we use a random sign-flip + permutation instead of full matrix
random_perm: Vec<u32>§vectors: Vec<QuantizedVector>Quantized vectors
raw_vectors: Option<Vec<Vec<f32>>>Original vectors for re-ranking (optional, can be stored separately)
Implementations§
Source§impl RaBitQIndex
impl RaBitQIndex
Sourcepub fn new(config: RaBitQConfig) -> Self
pub fn new(config: RaBitQConfig) -> Self
Create a new empty RaBitQ index
Sourcepub fn build(
config: RaBitQConfig,
vectors: &[Vec<f32>],
store_raw: bool,
) -> Self
pub fn build( config: RaBitQConfig, vectors: &[Vec<f32>], store_raw: bool, ) -> Self
Build index from a set of vectors
Sourcepub fn prepare_query(&self, raw_query: &[f32]) -> QuantizedQuery
pub fn prepare_query(&self, raw_query: &[f32]) -> QuantizedQuery
Prepare a query for fast distance estimation
Sourcepub fn estimate_distance(&self, query: &QuantizedQuery, vec_idx: usize) -> f32
pub fn estimate_distance(&self, query: &QuantizedQuery, vec_idx: usize) -> f32
Estimate squared distance between query and a quantized vector
Uses the formula from RaBitQ paper: ||o_r - q_r||^2 = ||o_r - c||^2 + ||q_r - c||^2 - 2 * ||o_r - c|| * ||q_r - c|| * <o, q>
Where <o, q> is estimated from the binary/scalar quantized representations.
Sourcepub fn search(
&self,
query: &[f32],
k: usize,
rerank_factor: usize,
) -> Vec<(usize, f32)>
pub fn search( &self, query: &[f32], k: usize, rerank_factor: usize, ) -> Vec<(usize, f32)>
Search for k nearest neighbors
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Memory usage in bytes
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Alias for memory_usage (for benchmark compatibility)
Sourcepub fn compression_ratio(&self) -> f32
pub fn compression_ratio(&self) -> f32
Compression ratio compared to raw float32 vectors
Trait Implementations§
Source§impl Clone for RaBitQIndex
impl Clone for RaBitQIndex
Source§fn clone(&self) -> RaBitQIndex
fn clone(&self) -> RaBitQIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RaBitQIndex
impl Debug for RaBitQIndex
Source§impl<'de> Deserialize<'de> for RaBitQIndex
impl<'de> Deserialize<'de> for RaBitQIndex
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>,
Auto Trait Implementations§
impl Freeze for RaBitQIndex
impl RefUnwindSafe for RaBitQIndex
impl Send for RaBitQIndex
impl Sync for RaBitQIndex
impl Unpin for RaBitQIndex
impl UnwindSafe for RaBitQIndex
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
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>
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>
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 more