pub struct SparseEmbed {
pub indices: Vec<u32>,
pub values: Vec<f32>,
pub vocab_id: String,
}Expand description
A sparse embedding over a fixed vocabulary.
indices MUST be strictly ascending; values MUST have the same
length as indices. Both invariants are checked by Self::new
and enforced on deserialise in a future CBOR round-trip test.
vocab_id pins the model family so two adapters with different
vocabs never fuse posting lists; compare as a string (e.g.
"bert-base-uncased@30522").
Fields§
§indices: Vec<u32>Token IDs in the vocabulary, strictly ascending.
values: Vec<f32>Non-zero weights, aligned with indices.
vocab_id: StringVocabulary identifier.
Implementations§
Source§impl SparseEmbed
impl SparseEmbed
Sourcepub fn new(
indices: Vec<u32>,
values: Vec<f32>,
vocab_id: impl Into<String>,
) -> Result<Self, SparseError>
pub fn new( indices: Vec<u32>, values: Vec<f32>, vocab_id: impl Into<String>, ) -> Result<Self, SparseError>
Construct a SparseEmbed. Panics (debug) / errors (release)
if the invariants are violated. indices is taken as-is; if
the caller is unsure whether it is sorted, use
Self::from_unsorted instead.
§Errors
SparseError::Configifindices.len() != values.len()orindicescontains duplicates / non-ascending entries.
Sourcepub fn from_unsorted(
pairs: impl IntoIterator<Item = (u32, f32)>,
vocab_id: impl Into<String>,
) -> Self
pub fn from_unsorted( pairs: impl IntoIterator<Item = (u32, f32)>, vocab_id: impl Into<String>, ) -> Self
Construct from an unsorted (index, value) pair list.
Duplicate indices are kept as the maximum value (SPLADE’s
own pooling rule). Useful from ONNX-side decoders that
produce vectors in token-emission order.
Trait Implementations§
Source§impl Clone for SparseEmbed
impl Clone for SparseEmbed
Source§fn clone(&self) -> SparseEmbed
fn clone(&self) -> SparseEmbed
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more