Correctly construct the Embeddings struct

This commit is contained in:
Clément Renault 2024-11-28 13:53:25 +01:00
parent 58eab9a018
commit cc4bd54669
No known key found for this signature in database
GPG key ID: F250A4C4E3AE5F5F
3 changed files with 21 additions and 8 deletions

View file

@ -293,6 +293,20 @@ impl ArroySetVectors {
});
Some(&vec[..])
}
/// Read all the embeddings and write them into an aligned `f32` Vec.
pub fn read_all_embeddings_into_vec<'v>(
&self,
frame: &FrameGrantR<'_>,
vec: &'v mut Vec<f32>,
) -> &'v [f32] {
vec.clear();
Self::remaining_bytes(frame).chunks_exact(mem::size_of::<f32>()).for_each(|bytes| {
let f = bytes.try_into().map(f32::from_ne_bytes).unwrap();
vec.push(f);
});
&vec[..]
}
}
#[derive(Debug, Clone, Copy)]