Skip to main content

Crate sporse

Crate sporse 

Source
Expand description

Sparse vector index for learned sparse retrieval.

Indexes sparse vectors (SPLADE, LADE, learned sparse representations) using an inverted index with Block-Max WAND traversal for exact top-k inner product search.

§Quick start

use sporse::{SparseVec, SporseIndex};

let mut index = SporseIndex::new();

// Insert documents as sparse vectors
index.insert(0, &SparseVec::new(vec![(0, 1.0), (3, 2.5), (7, 0.8)]));
index.insert(1, &SparseVec::new(vec![(1, 3.0), (3, 1.0)]));
index.insert(2, &SparseVec::new(vec![(0, 0.5), (7, 2.0)]));

// Build the index (computes block-max metadata)
index.build();

// Search: returns (doc_id, score) pairs, highest score first
let query = SparseVec::new(vec![(0, 1.0), (3, 1.0)]);
let results = index.search(&query, 2);
assert_eq!(results[0].0, 0); // doc 0 scores 1.0*1.0 + 2.5*1.0 = 3.5

Structs§

SparseVec
A sparse vector: sorted list of (dimension, weight) pairs.
SporseIndex
Inverted index for sparse vector retrieval using Block-Max WAND.