pub struct SparseWeights {
pub entries: Vec<(usize, f32)>,
}Expand description
Sparse lexical weight representation (SPLADE-like).
Stores non-zero (dimension_index, weight) pairs, sorted by descending absolute weight. Used for sparse retrieval ranking.
Fields§
§entries: Vec<(usize, f32)>(index, weight) pairs, sorted by descending absolute weight.
Implementations§
Source§impl SparseWeights
impl SparseWeights
Sourcepub fn from_dense(vec: &[f32], top_k: usize, min_weight: f32) -> Self
pub fn from_dense(vec: &[f32], top_k: usize, min_weight: f32) -> Self
Build a sparse representation from a dense vector by keeping the top-k dimensions with the largest absolute values, filtered by a minimum threshold.
This is a pragmatic derivation from the dense embedding. When a native
SPLADE-style sparse output is available from the model, use
SparseWeights::from_entries instead.
Sourcepub fn from_entries(entries: Vec<(usize, f32)>) -> Self
pub fn from_entries(entries: Vec<(usize, f32)>) -> Self
Build directly from pre-computed (index, weight) entries.
Sourcepub fn dot(&self, other: &SparseWeights) -> f32
pub fn dot(&self, other: &SparseWeights) -> f32
Dot product between two sparse vectors.
Efficiently computed by intersecting the sorted-by-index entries. Since entries are sorted by weight (not index), we use a HashMap-based merge for correctness.
Trait Implementations§
Source§impl Clone for SparseWeights
impl Clone for SparseWeights
Source§fn clone(&self) -> SparseWeights
fn clone(&self) -> SparseWeights
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SparseWeights
impl Debug for SparseWeights
Source§impl PartialEq for SparseWeights
impl PartialEq for SparseWeights
Source§fn eq(&self, other: &SparseWeights) -> bool
fn eq(&self, other: &SparseWeights) -> bool
self and other values to be equal, and is used by ==.