Skip to main content

SparseInvertedIndex

Struct SparseInvertedIndex 

Source
pub struct SparseInvertedIndex { /* private fields */ }
Expand description

A sparse inverted index over SparseEmbed values.

Build incrementally via Self::new + Self::add, or in bulk via Self::build_from_repo. Query via Self::search.

Posting lists are stored as HashMap<u32 token_id, Vec<Posting>>, where every Vec<Posting> is sorted by NodeId ASC for deterministic tie-break behaviour matching the rest of mnem-core’s indexes.

Implementations§

Source§

impl SparseInvertedIndex

Source

pub fn new(vocab_id: impl Into<String>) -> Self

Construct an empty index bound to vocab_id. Nodes added via Self::add whose own vocab_id disagrees are silently skipped - mirrors BruteForceVectorIndex behaviour for cross-model documents.

Source

pub fn vocab_id(&self) -> &str

Vocabulary identifier this index is bound to.

Source

pub const fn doc_count(&self) -> u32

Number of documents indexed.

Source

pub fn add(&mut self, node: NodeId, embed: &SparseEmbed)

Feed one (node, sparse_embed) pair. Silently skips when the embed’s vocab_id disagrees with the index’s or when the embed has zero non-zero entries.

Source

pub fn finalize(&mut self)

Finalise the index: sort each posting list by NodeId ASC so search results tie-break deterministically. Call once after all add() calls; idempotent.

Source

pub fn search( &self, query: &SparseEmbed, k: usize, ) -> Result<Vec<VectorHit>, Error>

Search the index for the top-k documents by sparse-dot-product score against query. Returns VectorHit (same shape as the dense index so callers can fuse results without a custom type).

On vocab_id mismatch returns an empty vec - the caller receives no scores to fuse, same semantics as a disjoint vocabulary.

Source

pub fn build_from_repo( repo: &ReadonlyRepo, vocab_id: impl Into<String>, ) -> Result<Self, Error>

Build an index from all nodes in the current commit whose sparse_embed field matches vocab_id. Requires the nodes to have been indexed by an adapter at write time.

§Errors

Trait Implementations§

Source§

impl Clone for SparseInvertedIndex

Source§

fn clone(&self) -> SparseInvertedIndex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SparseInvertedIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more