pub struct SparseIndex {
pub total_docs: u32,
pub total_vectors: u32,
/* private fields */
}Expand description
Sparse vector index for a field: lazy loading with mmap
Only stores the offset table in memory. Posting lists are loaded on-demand during queries using mmap for memory efficiency.
Fields§
§total_docs: u32Total document count in this segment (for IDF computation)
total_vectors: u32Total sparse vectors in this segment (for multi-valued IDF)
Implementations§
Source§impl SparseIndex
impl SparseIndex
Sourcepub fn new(
handle: LazyFileHandle,
offsets: Vec<(u64, u32)>,
total_docs: u32,
total_vectors: u32,
) -> Self
pub fn new( handle: LazyFileHandle, offsets: Vec<(u64, u32)>, total_docs: u32, total_vectors: u32, ) -> Self
Create a new lazy sparse index
Sourcepub async fn get_posting(
&self,
dim_id: u32,
) -> Result<Option<Arc<BlockSparsePostingList>>>
pub async fn get_posting( &self, dim_id: u32, ) -> Result<Option<Arc<BlockSparsePostingList>>>
Get posting list for a dimension (async, loads on-demand)
Sourcepub fn has_dimension(&self, dim_id: u32) -> bool
pub fn has_dimension(&self, dim_id: u32) -> bool
Check if dimension exists (without loading)
Sourcepub fn num_dimensions(&self) -> usize
pub fn num_dimensions(&self) -> usize
Get the number of dimensions in the index
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the cache (useful for memory pressure)
Sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
Get cache size (number of cached posting lists)
Sourcepub fn active_dimensions(&self) -> impl Iterator<Item = u32> + '_
pub fn active_dimensions(&self) -> impl Iterator<Item = u32> + '_
Iterate over all active dimension IDs (dimensions that have posting lists) This is synchronous and doesn’t load the posting lists
Sourcepub fn get_cached(&self, dim_id: u32) -> Option<Arc<BlockSparsePostingList>>
pub fn get_cached(&self, dim_id: u32) -> Option<Arc<BlockSparsePostingList>>
Get cached posting list if available (for synchronous access) Returns None if not cached (doesn’t load from disk)
Sourcepub fn idf(&self, dim_id: u32) -> f32
pub fn idf(&self, dim_id: u32) -> f32
Compute IDF (inverse document frequency) for a dimension Uses cached posting if available, otherwise returns 0
Sourcepub fn idf_weights(&self, dim_ids: &[u32]) -> Vec<f32>
pub fn idf_weights(&self, dim_ids: &[u32]) -> Vec<f32>
Get IDF weights for multiple dimensions (uses cache only)
Sourcepub fn get_posting_blocking(
&self,
dim_id: u32,
) -> Result<Option<Arc<BlockSparsePostingList>>>
pub fn get_posting_blocking( &self, dim_id: u32, ) -> Result<Option<Arc<BlockSparsePostingList>>>
Get posting list synchronously (blocking) - for merger use only Prefer async get_posting() for query-time access
Trait Implementations§
Source§impl Clone for SparseIndex
impl Clone for SparseIndex
Source§fn clone(&self) -> SparseIndex
fn clone(&self) -> SparseIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SparseIndex
impl !RefUnwindSafe for SparseIndex
impl Send for SparseIndex
impl Sync for SparseIndex
impl Unpin for SparseIndex
impl !UnwindSafe for SparseIndex
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.