pub struct SparseEmbeddingSpace { /* private fields */ }Expand description
Metadata about a sparse embedding space.
A sparse embedding space defines the properties of sparse embeddings stored within it:
- The maximum dimension (vocabulary size for SPLADE, etc.)
- The distance metric used for similarity search
Unlike dense embedding spaces, sparse spaces don’t require a fixed dimension since sparse vectors only store non-zero elements.
§Example
use manifoldb_vector::types::{EmbeddingName, SparseEmbeddingSpace};
use manifoldb_vector::distance::sparse::SparseDistanceMetric;
let name = EmbeddingName::new("splade_embedding").unwrap();
let space = SparseEmbeddingSpace::new(name, 30522, SparseDistanceMetric::DotProduct);
assert_eq!(space.max_dimension(), 30522); // BERT vocab size
assert_eq!(space.distance_metric(), SparseDistanceMetric::DotProduct);Implementations§
Source§impl SparseEmbeddingSpace
impl SparseEmbeddingSpace
Sourcepub const fn new(
name: EmbeddingName,
max_dimension: u32,
distance_metric: SparseDistanceMetric,
) -> Self
pub const fn new( name: EmbeddingName, max_dimension: u32, distance_metric: SparseDistanceMetric, ) -> Self
Create a new sparse embedding space.
Sourcepub fn name(&self) -> &EmbeddingName
pub fn name(&self) -> &EmbeddingName
Get the name of the embedding space.
Sourcepub fn max_dimension(&self) -> u32
pub fn max_dimension(&self) -> u32
Get the maximum dimension (vocabulary size) for this space.
Sourcepub fn distance_metric(&self) -> SparseDistanceMetric
pub fn distance_metric(&self) -> SparseDistanceMetric
Get the distance metric used for similarity search.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, VectorError>
pub fn to_bytes(&self) -> Result<Vec<u8>, VectorError>
Encode the sparse embedding space to bytes.
Format:
- 1 byte: version (2 for sparse)
- 2 bytes: name length (big-endian u16)
- N bytes: name (UTF-8)
- 4 bytes: max dimension (big-endian u32)
- 1 byte: distance metric
§Errors
Returns an error if the name length exceeds u16::MAX.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, VectorError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, VectorError>
Decode a sparse embedding space from bytes.
§Errors
Returns an error if the bytes are invalid or truncated.
Trait Implementations§
Source§impl Clone for SparseEmbeddingSpace
impl Clone for SparseEmbeddingSpace
Source§fn clone(&self) -> SparseEmbeddingSpace
fn clone(&self) -> SparseEmbeddingSpace
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseEmbeddingSpace
impl Debug for SparseEmbeddingSpace
Source§impl PartialEq for SparseEmbeddingSpace
impl PartialEq for SparseEmbeddingSpace
impl Eq for SparseEmbeddingSpace
impl StructuralPartialEq for SparseEmbeddingSpace
Auto Trait Implementations§
impl Freeze for SparseEmbeddingSpace
impl RefUnwindSafe for SparseEmbeddingSpace
impl Send for SparseEmbeddingSpace
impl Sync for SparseEmbeddingSpace
impl Unpin for SparseEmbeddingSpace
impl UnwindSafe for SparseEmbeddingSpace
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