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 indexesraw-segment: score file-backed raw segments; see the guiderecordlog: append operations for rebuilding an indexcli: build and search indexes from the command linefuzzy: 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:
postingsprovides postings lists + candidate planning (no false negatives).lexirprovides scoring + ranking (BM25 / TF-IDF) overpostings.- Exact filters, such as phrase/proximity matches, can supply candidate docs
for
lexirto 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.