pub struct Embedding(/* private fields */);Expand description
A vector with two explicit construction policies.
Embedding::from_raw truncates and L2-normalises model output;
Embedding::from_preserved validates nonempty, finite input and preserves
every component’s bits without truncation or normalization. A zero vector
remains zero and reports normalized() == false.
Derived deserialization retains its existing, unvalidated behavior.
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub fn from_raw(raw: Vec<f32>, dim: Dimension) -> Result<Embedding, Error>
pub fn from_raw(raw: Vec<f32>, dim: Dimension) -> Result<Embedding, Error>
Truncate a raw model output to dim leading components, then L2-normalise.
Normalising after truncation matters: a slice of a unit vector is not unit length, and skipping this silently degrades ranking.
Sourcepub fn from_preserved(values: Vec<f32>) -> Result<Embedding, Error>
pub fn from_preserved(values: Vec<f32>) -> Result<Embedding, Error>
Restore a nonempty, finite vector without truncating or normalizing it. Every component’s bits are preserved, including signed zero and subnormals.
pub fn as_slice(&self) -> &[f32]
pub fn dim(&self) -> usize
Sourcepub fn dimension(&self) -> usize
pub fn dimension(&self) -> usize
Width derived from the vector, never duplicated mutable metadata.
Sourcepub fn normalized(&self) -> bool
pub fn normalized(&self) -> bool
Whether this vector has unit L2 norm (within 1e-5).