pub struct Bm25Index<'a> { /* private fields */ }Expand description
The BM25 index: postings with term frequencies plus per-document lengths and corpus statistics.
Implementations§
Source§impl<'a> Bm25Index<'a>
impl<'a> Bm25Index<'a>
Sourcepub fn new(shards: usize, max_bytes: usize) -> Result<Self, Error>
pub fn new(shards: usize, max_bytes: usize) -> Result<Self, Error>
Creates an empty index; shards per the engine config
(shards_postings), max_bytes bounds each underlying pool.
Sourcepub fn index_doc(
&mut self,
fact: FactId,
term_tfs: &[(u32, u8)],
) -> Result<(), Error>
pub fn index_doc( &mut self, fact: FactId, term_tfs: &[(u32, u8)], ) -> Result<(), Error>
Indexes one document given its (term, tf) pairs (the caller
tokenizes and counts; pairs may arrive in any order, terms must be
unique). Documents must arrive in ascending fact-id order.
§Errors
Error::Arena when a pool hits its byte ceiling; the index may
then hold the document partially — the engine treats that as fatal
for the whole operation (journal replay rebuilds consistently).
Sourcepub fn idf(&self, df: u32) -> f32
pub fn idf(&self, df: u32) -> f32
Robertson idf for a term with document frequency df in this
corpus (monotonically decreasing in df, always positive).
Sourcepub fn search(
&self,
(k1, b): (f32, f32),
terms: &[u32],
k: usize,
live: &mut dyn FnMut(FactId) -> bool,
scratch: &mut Bm25Scratch,
out: &mut Vec<(FactId, f32)>,
)
pub fn search( &self, (k1, b): (f32, f32), terms: &[u32], k: usize, live: &mut dyn FnMut(FactId) -> bool, scratch: &mut Bm25Scratch, out: &mut Vec<(FactId, f32)>, )
Scores terms against the corpus and writes the top k live
documents into out (descending score, ties by ascending id).
live filters candidates (tombstones, as-of, tag allow-sets) —
filtered documents cost their posting decode but never rank.
Duplicate query terms are the caller’s choice: each occurrence accumulates again (a term repeated in the query weighs more).
Sourcepub fn pool_bytes(&self) -> usize
pub fn pool_bytes(&self) -> usize
Bytes held by the underlying pools.