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

Method prepare_query

nodedb-vector/src/rerank/codecs/pq.rs:111–128  ·  view source on GitHub ↗

Prepare the query by precomputing the M×K asymmetric distance table. The prepared form is `PreparedQuery::Lut` where `lut[sub][centroid]` holds the squared L2 distance from the query's sub-vector to each centroid of subspace `sub`. This is the standard ADC lookup table.

(&self, q: &[f32])

Source from the content-addressed store, hash-verified

109 /// holds the squared L2 distance from the query's sub-vector to each
110 /// centroid of subspace `sub`. This is the standard ADC lookup table.
111 fn prepare_query(&self, q: &[f32]) -> Result<PreparedQuery, RerankError> {
112 if q.len() != self.dim {
113 return Err(RerankError::BadInput(format!(
114 "pq prepare_query: query len {} != codec dim {}",
115 q.len(),
116 self.dim
117 )));
118 }
119 let codec = self.codec.as_ref().ok_or_else(|| {
120 RerankError::NotTrained(
121 "pq: codec must be trained before prepare_query (call train() with a sample of vectors)"
122 .to_string(),
123 )
124 })?;
125 use nodedb_codec::vector_quant::codec::VectorCodec;
126 let pq_query = <PqCodec as VectorCodec>::prepare_query(codec, q);
127 Ok(PreparedQuery::Lut(pq_query.distance_table))
128 }
129
130 /// Compute asymmetric ADC distance from a prepared query to a PQ-encoded
131 /// candidate.

Callers 1

Calls 3

to_stringMethod · 0.80
lenMethod · 0.45
as_refMethod · 0.45

Tested by 1