pub struct Embedding {
pub vector: Vec<f32>,
pub usage: Option<EmbeddingUsage>,
}Expand description
One embedded text’s vector plus optional usage metadata.
usage is None when the backend does not surface token
accounting (in-process stub embedders, hash-based encoders).
Cost-aware backends (OpenAI, Voyage, Cohere) return Some so
downstream meters can charge per call.
Fields§
§vector: Vec<f32>The encoded vector. Length always equals
Embedder::dimension.
usage: Option<EmbeddingUsage>Token-accounting metadata when the backend reports it.
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub const fn new(vector: Vec<f32>) -> Self
pub const fn new(vector: Vec<f32>) -> Self
Build an embedding with no usage metadata. Stub backends and tests use this when they have no token count to report.
Sourcepub const fn with_usage(self, usage: EmbeddingUsage) -> Self
pub const fn with_usage(self, usage: EmbeddingUsage) -> Self
Builder-style usage attachment.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Embedding
impl<'de> Deserialize<'de> for Embedding
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Embedding
Auto Trait Implementations§
impl Freeze for Embedding
impl RefUnwindSafe for Embedding
impl Send for Embedding
impl Sync for Embedding
impl Unpin for Embedding
impl UnsafeUnpin for Embedding
impl UnwindSafe for Embedding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more