Skip to main content

Crate lexir

Crate lexir 

Source
Expand description

§lexir

Lexical scoring over postings lists

Status: Experimental. The API may change.

lexir ranks token streams that you supply. Its in-memory index stores postings and corpus statistics. The raw-segment feature scores immutable postings files. You supply tokenization and document storage; positional matching and segment lifecycle are separate.

The default BM25 comes from rankfns: Lucene’s IDF with the (k1 + 1) numerator and exact document lengths; BM25L and BM25+ are opt-in variants. The variants apply the term-frequency transforms of Lv and Zhai (2011) but keep Lucene’s IDF, ln((N + 1) / (df + 0.5)), where the paper uses ln((N + 1) / df), so their rankings can differ from the paper.

§Install

[dependencies]
lexir = "0.5"

§Usage

use lexir::bm25::InvertedIndex;

let mut index = InvertedIndex::new();
index.add_document(1, &["red".into(), "fox".into()]);
index.add_document(2, &["blue".into(), "whale".into()]);

let hits = index.retrieve(&["fox".into()], 10, Default::default())?;
assert_eq!(hits[0].0, 1);

§Features

  • persistence (default): save and load in-memory indexes
  • raw-segment: score file-backed raw segments; see the guide
  • recordlog: append operations for rebuilding an index
  • cli: build and search indexes from the command line
  • fuzzy: expand out-of-vocabulary query terms

The default and non-CLI library features support Rust 1.80. The cli feature and all-feature builds require Rust 1.85 with the current Clap dependency.

Run cargo run --features cli -- --help for CLI usage.

§License

MIT OR Apache-2.0 lexir: lexical IR built on postings.

Lexical retrieval built on postings:

  • postings provides postings lists + candidate planning (no false negatives).
  • lexir provides scoring + ranking (BM25 / TF-IDF) over postings.
  • Exact filters, such as phrase/proximity matches, can supply candidate docs for lexir to rank while keeping their storage and execution elsewhere.

Scope:

  • In-memory indexes
  • Deterministic ranking (tie-break by doc id)
  • Caller-provided token streams (so different products can choose tokenization)

Non-goals:

  • Storing document content (index-only)
  • Owning positional storage or phrase/proximity execution (that lives in postings)
  • Query language beyond “bag of terms”

References:

  • Robertson & Walker (1994): probabilistic retrieval foundations
  • Robertson & Zaragoza (2009): BM25 and beyond
  • Spärck Jones (1972): term specificity / IDF motivation

Modules§

bm25
Okapi BM25 over postings::PostingsIndex.
query_likelihood
Query likelihood language model retrieval.
tfidf
TF-IDF scoring over the shared postings-backed index.

Enums§

Error
Errors for lexical retrieval.