Encode f32 embeddings without transformation (raw + lz4). Fallback for non-normalized embeddings where spherical transform doesn't help.
(data: &[f32], dims: usize, vectors: usize)
| 66 | /// Fallback for non-normalized embeddings where spherical transform |
| 67 | /// doesn't help. |
| 68 | pub 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. |
| 76 | pub fn decode(data: &[u8]) -> Result<(Vec<f32>, usize, usize), CodecError> { |