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

Function pq_codec_golden_format

nodedb-vector/src/quantize/pq.rs:452–468  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

450 // golden format test — verifies the on-disk layout is stable.
451 #[test]
452 fn pq_codec_golden_format() {
453 let vecs = make_clustered_data();
454 let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect();
455 let codec = PqCodec::train(&refs, 4, 2, 16, 10);
456
457 let bytes = codec.to_bytes().unwrap();
458
459 // Magic header.
460 assert_eq!(&bytes[0..6], b"NDPQ\0\0", "magic mismatch");
461 // Version byte.
462 assert_eq!(bytes[6], 1u8, "version must be 1");
463 // Payload at offset 7 must decode back to a valid PqCodec.
464 let restored = zerompk::from_msgpack::<PqCodec>(&bytes[7..])
465 .expect("msgpack payload at offset 7 must decode");
466 assert_eq!(restored.dim, codec.dim);
467 assert_eq!(restored.m, codec.m);
468 }
469
470 #[test]
471 fn pq_version_mismatch_returns_error() {

Callers

nothing calls this directly

Calls 6

make_clustered_dataFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
as_sliceMethod · 0.45
to_bytesMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected