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

Function encode_vector

nodedb-strict/src/encode.rs:603–619  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

601
602 #[test]
603 fn encode_vector() {
604 let schema =
605 StrictSchema::new(vec![ColumnDef::required("emb", ColumnType::Vector(3))]).unwrap();
606 let encoder = TupleEncoder::new(&schema);
607
608 let vals = vec![Value::Array(vec![
609 Value::Float(1.0),
610 Value::Float(2.0),
611 Value::Float(3.0),
612 ])];
613 let tuple = encoder.encode(&vals).unwrap();
614 // Header: 10 bytes. Fixed: 12 bytes (3 × f32).
615 let f0 = f32::from_le_bytes(tuple[10..14].try_into().unwrap());
616 let f1 = f32::from_le_bytes(tuple[14..18].try_into().unwrap());
617 let f2 = f32::from_le_bytes(tuple[18..22].try_into().unwrap());
618 assert_eq!((f0, f1, f2), (1.0, 2.0, 3.0));
619 }
620
621 /// Asserts NDST magic at [0..4], FORMAT_VERSION == 1 at [4], and
622 /// schema_version u32 at [5..9].

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected