Skip to main content

Bm25Index

Struct Bm25Index 

Source
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>

Source

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.

Source

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).

Source

pub fn df(&self, term: u32) -> u32

Document frequency of a term.

Source

pub fn docs(&self) -> u64

Number of indexed documents.

Source

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).

Source

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).

Source

pub fn pool_bytes(&self) -> usize

Bytes held by the underlying pools.

Source

pub fn total_len(&self) -> u64

Total token count across the corpus (persisted in the engine state).

Trait Implementations§

Source§

impl<'a> Debug for Bm25Index<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Bm25Index<'a>

§

impl<'a> RefUnwindSafe for Bm25Index<'a>

§

impl<'a> Send for Bm25Index<'a>

§

impl<'a> Sync for Bm25Index<'a>

§

impl<'a> Unpin for Bm25Index<'a>

§

impl<'a> UnsafeUnpin for Bm25Index<'a>

§

impl<'a> UnwindSafe for Bm25Index<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.