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

Method prepare_query

nodedb-vector/src/rerank/codecs/bbq.rs:155–174  ·  view source on GitHub ↗

Prepare the query by centering it and serialising the exact FP32 centered vector alongside the query norm. The prepared form is `PreparedQuery::Bytes` with the layout: 4 bytes query_norm (f32 LE) || dim × 4 bytes centered f32 LE.

(&self, q: &[f32])

Source from the content-addressed store, hash-verified

153 /// The prepared form is `PreparedQuery::Bytes` with the layout:
154 /// 4 bytes query_norm (f32 LE) || dim × 4 bytes centered f32 LE.
155 fn prepare_query(&self, q: &[f32]) -> Result<PreparedQuery, RerankError> {
156 if q.len() != self.dim {
157 return Err(RerankError::BadInput(format!(
158 "bbq prepare_query: query len {} != codec dim {}",
159 q.len(),
160 self.dim
161 )));
162 }
163 let codec = self.codec.as_ref().ok_or_else(|| {
164 RerankError::NotTrained(
165 "bbq: codec must be trained before prepare_query (call train() with a sample of vectors)"
166 .to_string(),
167 )
168 })?;
169 let query = codec.prepare_query(q);
170 Ok(PreparedQuery::Bytes(encode_payload(
171 query.query_norm,
172 &query.centered,
173 )))
174 }
175
176 /// Compute asymmetric L2 distance from a prepared query to a BBQ-encoded
177 /// candidate.

Callers 2

Calls 4

to_stringMethod · 0.80
encode_payloadFunction · 0.70
lenMethod · 0.45
as_refMethod · 0.45

Tested by 2