#tf-idf #bm25 #ranking #search

rankfns

IR ranking math kernels (no indexing): BM25/TF-IDF/LM transforms

5 releases

new 0.1.4 Jun 11, 2026
0.1.3 Apr 6, 2026
0.1.2 Mar 9, 2026
0.1.1 Mar 8, 2026
0.1.0 Feb 23, 2026

#2962 in Algorithms


Used in 2 crates

MIT/Apache

12KB
150 lines

rankfns

crates.io Documentation CI

IR ranking math kernels (no indexing): BM25, TF-IDF, and language-model transforms.

Scope

  • BM25 / TF-IDF: Standard scoring functions (Robertson-Walker, etc.).
  • Normalization: Document length normalization helpers.
  • Language-model smoothing: query-likelihood components (Jelinek–Mercer, Dirichlet).

If you want an inverted index, pair this with postings (storage) or lexir (scoring pipeline). For fusion and reranking of ranked lists (RRF, CombMNZ, MMR, etc.), use rankops.

Example (BM25 pieces)

use rankfns::{bm25_idf_plus1, bm25_tf};

let n_docs = 1_000u32;
let df = 10u32;
let tf = 3.0f32;
let doc_len = 120.0f32;
let avg_doc_len = 100.0f32;
let k1 = 1.2f32;
let b = 0.75f32;

let idf = bm25_idf_plus1(n_docs, df);
let tf_norm = bm25_tf(tf, doc_len, avg_doc_len, k1, b);
let score = idf * tf_norm;
assert!(score.is_finite());
assert!(score >= 0.0);

License

MIT OR Apache-2.0

No runtime deps