pub struct Quantizer { /* private fields */ }Expand description
The quantiser for one collection: its rotation and its width.
Implementations§
Source§impl Quantizer
impl Quantizer
Sourcepub fn new(dim: usize, bits: Bits, seed: u64) -> Quantizer
pub fn new(dim: usize, bits: Bits, seed: u64) -> Quantizer
The quantiser for dim dimensional vectors at bits, with seed
choosing the rotation.
§Panics
If dim is zero.
Sourcepub fn seed(&self) -> u64
pub fn seed(&self) -> u64
The seed the rotation was built from, which is what a catalogue stores.
Sourcepub fn code_bytes(&self) -> usize
pub fn code_bytes(&self) -> usize
How many bytes one code takes.
A plane is whole 64 bit words because the scan reads words, so a dimension that is not a multiple of 64 pays for the rest of its last word. At the dimensions embedding families actually use there is nothing to pay.
Sourcepub fn rotate(&self, v: &[f32]) -> Vec<f32>
pub fn rotate(&self, v: &[f32]) -> Vec<f32>
A vector in the frame everything else here works in.
The rotation is linear, so rotate(v - c) is rotate(v) - rotate(c),
and an index that keeps its centroids already rotated never has to
rotate one again. That is what Quantizer::encode_rotated and
Quantizer::query_rotated are for, and the rotation is the expensive
half of both of the two calls above them.
§Panics
If v is not Quantizer::dim long.
Sourcepub fn encode(&self, v: &[f32], centroid: &[f32], code: &mut [u8]) -> Coded
pub fn encode(&self, v: &[f32], centroid: &[f32], code: &mut [u8]) -> Coded
Write v’s code against the centroid of the partition it is going into.
§Panics
If v or centroid is not Quantizer::dim long, or code is not
Quantizer::code_bytes long.
Sourcepub fn encode_rotated(
&self,
x: &[f32],
centroid: &[f32],
code: &mut [u8],
) -> Coded
pub fn encode_rotated( &self, x: &[f32], centroid: &[f32], code: &mut [u8], ) -> Coded
The same as Quantizer::encode with both sides already rotated.
§Panics
If x or centroid is not Quantizer::dim long, or code is not
Quantizer::code_bytes long.
Sourcepub fn query(&self, q: &[f32], centroid: &[f32]) -> Query
pub fn query(&self, q: &[f32], centroid: &[f32]) -> Query
Prepare a query against the centroid of a partition being scanned.
This is the per partition half of a search and it happens once, where the estimate against a code happens once per vector in the partition.
§Panics
If q or centroid is not Quantizer::dim long.
Sourcepub fn query_rotated(&self, q: &[f32], centroid: &[f32]) -> Query
pub fn query_rotated(&self, q: &[f32], centroid: &[f32]) -> Query
The same as Quantizer::query with both sides already rotated.
A search rotates its query once and then meets every partition it probes through this, so the rotation is paid for once rather than once per partition.
§Panics
If q or centroid is not Quantizer::dim long.