pub struct RaBitQIndex {
pub rotation: Vec<f32>,
pub centroid: Vec<f32>,
pub dimension: usize,
}Expand description
RaBitQ index holding the random rotation matrix and dataset centroid.
Fields§
§rotation: Vec<f32>Random orthogonal rotation matrix (flattened D x D, row-major).
centroid: Vec<f32>Dataset centroid for centering.
dimension: usizeVector dimension.
Implementations§
Source§impl RaBitQIndex
impl RaBitQIndex
Sourcepub fn encode(&self, vector: &[f32]) -> Result<RaBitQVector, Error>
pub fn encode(&self, vector: &[f32]) -> Result<RaBitQVector, Error>
Encode a vector into a RaBitQVector.
Steps:
- Center the vector (subtract centroid).
- Compute the L2 norm of the centered vector.
- Normalize (handle zero-norm gracefully).
- Apply rotation matrix.
- Extract sign bits into u64 words.
- Compute correction factors.
§Errors
Returns Error::InvalidQuantizerConfig if vector dimension mismatches.
Sourcepub fn distance(&self, query: &[f32], encoded: &RaBitQVector) -> f32
pub fn distance(&self, query: &[f32], encoded: &RaBitQVector) -> f32
Estimate the L2 distance between a raw query vector and an encoded vector.
Uses XOR + popcount for fast Hamming-based inner product estimation, then applies affine correction with stored norms.
Sourcepub fn batch_distance(
&self,
query: &[f32],
encoded: &[RaBitQVector],
) -> Vec<f32>
pub fn batch_distance( &self, query: &[f32], encoded: &[RaBitQVector], ) -> Vec<f32>
Batch distance: process query once, then iterate over encoded vectors.
Amortizes query preprocessing (centering, normalization, rotation, sign extraction).
Source§impl RaBitQIndex
Training and persistence methods (require persistence feature for rayon).
impl RaBitQIndex
Training and persistence methods (require persistence feature for rayon).
Sourcepub fn train(vectors: &[Vec<f32>], seed: u64) -> Result<Self, Error>
pub fn train(vectors: &[Vec<f32>], seed: u64) -> Result<Self, Error>
Train a RaBitQ index from a set of vectors.
Computes dataset centroid and generates a random orthogonal rotation matrix via modified Gram-Schmidt orthogonalization of a random matrix.
§Errors
Returns Error::InvalidQuantizerConfig if:
vectorsis empty- vectors have inconsistent dimensions
- vector dimension is 0
Sourcepub fn save(&self, dir: &Path) -> Result<(), Error>
pub fn save(&self, dir: &Path) -> Result<(), Error>
Save RaBitQ index to <dir>/rabitq.idx using postcard with atomic write.
§Errors
Returns Error::Io if serialization or file I/O fails.
Sourcepub fn load(dir: &Path) -> Result<Option<Self>, Error>
pub fn load(dir: &Path) -> Result<Option<Self>, Error>
Load RaBitQ index from <dir>/rabitq.idx. Returns None if file doesn’t exist.
The decoded index is validated (validate_loaded) so a corrupt
rotation/centroid is rejected here rather than producing out-of-bounds
indexing in apply_rotation_flat during search.
§Errors
Returns Error::Io if deserialization or file I/O fails, or
Error::IndexCorrupted if the file exceeds the size cap or the decoded
rotation/centroid lengths are inconsistent with dimension.
Trait Implementations§
Source§impl Clone for RaBitQIndex
impl Clone for RaBitQIndex
Source§fn clone(&self) -> RaBitQIndex
fn clone(&self) -> RaBitQIndex
1.0.0 (const: unstable) · 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 UnsafeUnpin 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);