Skip to main content

Query

Struct Query 

Source
pub struct Query { /* private fields */ }
Expand description

A query, rotated and quantised once and then measured against every code in a partition.

Implementations§

Source§

impl Query

Source

pub fn scan(&self, codes: &[u8], meta: &[Coded], out: &mut [f32])

The estimated squared distance from this query to every code in a posting, written into out.

This is the loop a search spends most of its life in, and it takes a whole posting rather than one code because of what that costs. A code is dim / 64 words wide, and dim is not a compile time constant, so a scan written one code at a time meets a loop whose trip count the compiler cannot see and cannot unroll. Measured at 128 dimensions, the same popcount arithmetic is 1.98 nanoseconds a member with the word count known and 6.31 with it unknown, which is more than three times. Deciding the width once for a posting of a few hundred rather than once per member is what buys that back.

§Panics

If out is not as long as meta, or if codes is not meta.len() codes long.

Source

pub fn distance(&self, code: &[u8], coded: &Coded) -> f32

The estimated squared distance between the query and one coded vector.

Squared rather than the distance itself because the square root is monotone, so it changes no ordering and nothing above this needs it.

This is the convenient form and not the one a search calls. Query::scan is that one.

§Panics

If code is not as long as the codes this query’s quantiser writes.

Source

pub fn cosine(&self, code: &[u8], coded: &Coded) -> f32

The estimated cosine between the query’s residual and the coded one.

This is RaBitQ’s estimator: the inner product against what the code reconstructs to, divided by the cosine between that reconstruction and the vector it came from. The division is the part that makes it unbiased. The inner product is the popcount scan.

§Panics

If code is not as long as the codes this query’s quantiser writes.

Source

pub fn cosine_exact(&self, code: &[u8], coded: &Coded) -> f32

The same estimate with the query left at full precision.

This is the reference the popcount scan is checked against, and it is public because a divergence between the two is worth being able to measure from outside. It reads one coordinate at a time and it is not what a search should call.

§Panics

If code is not as long as the codes this query’s quantiser writes.

Auto Trait Implementations§

§

impl Freeze for Query

§

impl RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnsafeUnpin for Query

§

impl UnwindSafe for Query

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.