Skip to main content

Crate rank_bm25

Crate rank_bm25 

Source
Expand description

BM25Okapi, BM25L and BM25Plus with scores identical to Python’s rank_bm25 0.2.2, down to the last bit.

rank_bm25 computes each term’s contribution for every document with NumPy. This crate keeps an inverted index, visits only the documents that contain a term where the other documents’ contribution is exactly zero, and performs the remaining floating-point operations in the same order as NumPy, so every score equals rank_bm25’s.

use rank_bm25::{Builder, Params};

let mut builder = Builder::new(Params::okapi());
builder.add_document(["hello", "there", "good", "man"])?;
builder.add_document(["it", "is", "quite", "windy", "in", "london"])?;
builder.add_document(["how", "is", "the", "weather", "today"])?;
let index = builder.build()?;
let scores = index.get_scores(&["windy", "london"]);
assert!(scores[1] > 0.0 && scores[0] == 0.0);

Structs§

Builder
Collects documents, then builds an Index.
Index
A BM25 index over a fixed corpus.
Params
k1, b and the variant, with rank_bm25’s defaults in the constructors.

Enums§

Error
rank_bm25 divides by the number of documents, and BM25Okapi by the number of distinct terms.
Variant
The BM25 variant and its own parameter.