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])
| 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. |