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

Function decode_payload

nodedb-vector/src/rerank/codecs/bbq.rs:39–59  ·  view source on GitHub ↗
(payload: &[u8], dim: usize)

Source from the content-addressed store, hash-verified

37}
38
39fn decode_payload(payload: &[u8], dim: usize) -> Result<(f32, Vec<f32>), RerankError> {
40 let expected = 4 + dim * 4;
41 if payload.len() != expected {
42 return Err(RerankError::BadInput(format!(
43 "bbq distance: payload len {} != expected {} for dim {}",
44 payload.len(),
45 expected,
46 dim
47 )));
48 }
49 let query_norm = f32::from_le_bytes(
50 payload[..4]
51 .try_into()
52 .expect("slice of 4 bytes always converts to [u8;4]"),
53 );
54 let centered: Vec<f32> = payload[4..]
55 .chunks_exact(4)
56 .map(|b| f32::from_le_bytes(b.try_into().expect("chunks_exact(4) always 4 bytes")))
57 .collect();
58 Ok((query_norm, centered))
59}
60
61// ── Inline dequantize (mirrors BbqCodec::dequantize, which is private) ────────
62

Callers 1

distance_preparedMethod · 0.70

Calls 3

collectMethod · 0.80
lenMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected