pub struct SparseIndex {
pub index: InvertedIndex,
/* private fields */
}Expand description
High-level facade over InvertedIndex.
Owns a file path and delegates all indexing/search operations to the
underlying InvertedIndex. Persist with save(); reconstruct from disk
with open().
Fields§
§index: InvertedIndexImplementations§
Source§impl SparseIndex
impl SparseIndex
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open an existing index from path, or create empty if file absent.
Sourcepub fn index_document(&mut self, id: &VectorId, text: &str) -> Result<()>
pub fn index_document(&mut self, id: &VectorId, text: &str) -> Result<()>
Add or update a document.
Sourcepub fn remove_document(&mut self, id: &VectorId) -> Result<()>
pub fn remove_document(&mut self, id: &VectorId) -> Result<()>
Remove a document. Returns NotFound if absent.
Sourcepub fn search(&self, query: &str, k: usize) -> Result<Vec<(VectorId, f32)>>
pub fn search(&self, query: &str, k: usize) -> Result<Vec<(VectorId, f32)>>
Full-text BM25 search. Returns up to k results sorted by score desc.
Sourcepub fn score(
&self,
query_text: &str,
candidate_ids: &[VectorId],
) -> Result<Vec<(VectorId, f32)>>
pub fn score( &self, query_text: &str, candidate_ids: &[VectorId], ) -> Result<Vec<(VectorId, f32)>>
Score query_text against a specific set of candidate document IDs.
Tokenizes the query internally. Returns BM25 scores only for the
provided candidates. If candidate_ids is empty, all documents are
scored (same as score_all but without a k truncation).
Sourcepub fn score_all(
&self,
query_text: &str,
k: usize,
) -> Result<Vec<(VectorId, f32)>>
pub fn score_all( &self, query_text: &str, k: usize, ) -> Result<Vec<(VectorId, f32)>>
Score query_text against all indexed documents. Returns top k.
pub fn doc_count(&self) -> usize
Auto Trait Implementations§
impl Freeze for SparseIndex
impl RefUnwindSafe for SparseIndex
impl Send for SparseIndex
impl Sync for SparseIndex
impl Unpin for SparseIndex
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
Converts
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> ⓘ
Converts
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 more