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

Function encode_raw

nodedb-codec/src/spherical.rs:68–73  ·  view source on GitHub ↗

Encode f32 embeddings without transformation (raw + lz4). Fallback for non-normalized embeddings where spherical transform doesn't help.

(data: &[f32], dims: usize, vectors: usize)

Source from the content-addressed store, hash-verified

66/// Fallback for non-normalized embeddings where spherical transform
67/// doesn't help.
68pub fn encode_raw(data: &[f32], dims: usize, vectors: usize) -> Result<Vec<u8>, CodecError> {
69 let raw_bytes: Vec<u8> = data.iter().flat_map(|f| f.to_le_bytes()).collect();
70 let compressed = crate::lz4::encode(&raw_bytes);
71
72 Ok(build_header(dims as u32, vectors as u32, 0, &compressed))
73}
74
75/// Decode spherical-compressed embeddings back to f32 Cartesian coordinates.
76pub fn decode(data: &[u8]) -> Result<(Vec<f32>, usize, usize), CodecError> {

Callers 1

raw_roundtripFunction · 0.70

Calls 4

build_headerFunction · 0.85
collectMethod · 0.80
encodeFunction · 0.70
iterMethod · 0.45

Tested by 1

raw_roundtripFunction · 0.56