MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / prepare_query

Method prepare_query

nodedb-codec/src/vector_quant/opq.rs:305–319  ·  view source on GitHub ↗

Rotate the query, then build flat ADC distance table `[M × K]`.

(&self, q: &[f32])

Source from the content-addressed store, hash-verified

303
304 /// Rotate the query, then build flat ADC distance table `[M × K]`.
305 fn prepare_query(&self, q: &[f32]) -> Self::Query {
306 let rotated = self.apply_rotation(q);
307 let mut table = vec![0.0f32; self.m * self.k];
308 for s in 0..self.m {
309 let offset = s * self.sub_dim;
310 let sub_q = &rotated[offset..offset + self.sub_dim];
311 for c in 0..self.k {
312 table[s * self.k + c] = l2_sq(sub_q, &self.codebooks[s][c]);
313 }
314 }
315 OpqQuery {
316 distance_table: table,
317 rotated,
318 }
319 }
320
321 fn adc_lut(&self, q: &Self::Query) -> Option<AdcLut> {
322 let mut lut = AdcLut::new(self.m as u16, self.k as u16);

Callers 2

distance_is_non_negativeFunction · 0.45

Calls 2

l2_sqFunction · 0.85
apply_rotationMethod · 0.45

Tested by 2

distance_is_non_negativeFunction · 0.36