pub struct RaBitQCodebook {
pub dim: usize,
pub seed: u64,
/* private fields */
}Expand description
RaBitQ projection codebook: holds the random rotation matrix P.
The matrix is regenerated deterministically from seed — not stored in
the serialized form. Call RaBitQCodebook::rebuild_proj after
deserialization before calling encode or prepare_query.
Fields§
§dim: usize§seed: u64Implementations§
Source§impl RaBitQCodebook
impl RaBitQCodebook
Sourcepub fn rebuild_proj(&mut self)
pub fn rebuild_proj(&mut self)
Regenerate the projection matrix after deserialization.
Must be called before encode/prepare_query when deserializing.
pub fn is_ready(&self) -> bool
Sourcepub fn encode(&self, v: &[f32]) -> RaBitQVec
pub fn encode(&self, v: &[f32]) -> RaBitQVec
Encode a database vector to a RaBitQVec.
The input vector is normalized to unit length before rotation so that the binary code is independent of magnitude; the original norm is stored separately for Euclidean distance estimation.
Sourcepub fn prepare_query(&self, q: &[f32]) -> (Vec<f32>, f32)
pub fn prepare_query(&self, q: &[f32]) -> (Vec<f32>, f32)
Prepare a query for search: project + compute scale.
Returns (projected_query, scale) where projected_query has dim elements.
Sourcepub fn estimate_ip_binary(
&self,
b_q: &[u8],
q_scale: f32,
entry: &RaBitQVec,
) -> f32
pub fn estimate_ip_binary( &self, b_q: &[u8], q_scale: f32, entry: &RaBitQVec, ) -> f32
Estimate inner product using pre-binarized query codes.
b_q: bits_from_signs(q_proj) — compute once per query, reuse for all entries.
q_scale: output of prepare_query().1.
This avoids recomputing bits_from_signs inside the parallel search loop.
Sourcepub fn estimate_ip(
&self,
q_proj: &[f32],
q_scale: f32,
entry: &RaBitQVec,
) -> f32
pub fn estimate_ip( &self, q_proj: &[f32], q_scale: f32, entry: &RaBitQVec, ) -> f32
Estimate inner product between a prepared query and a database entry.
q_proj: output of prepare_query().0
q_scale: output of prepare_query().1
Prefer [estimate_ip_binary] when calling in a tight loop — it avoids
recomputing bits_from_signs for every entry.
Trait Implementations§
Source§impl Clone for RaBitQCodebook
impl Clone for RaBitQCodebook
Source§fn clone(&self) -> RaBitQCodebook
fn clone(&self) -> RaBitQCodebook
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 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>,
Auto Trait Implementations§
impl Freeze for RaBitQCodebook
impl RefUnwindSafe for RaBitQCodebook
impl Send for RaBitQCodebook
impl Sync for RaBitQCodebook
impl Unpin for RaBitQCodebook
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> 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