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
impl Query
Sourcepub fn scan(&self, codes: &[u8], meta: &[Coded], out: &mut [f32])
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.
Sourcepub fn distance(&self, code: &[u8], coded: &Coded) -> f32
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.
Sourcepub fn cosine(&self, code: &[u8], coded: &Coded) -> f32
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.
Sourcepub fn cosine_exact(&self, code: &[u8], coded: &Coded) -> f32
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.