Skip to main content

Crate bm25_rerank

Crate bm25_rerank 

Source
Expand description

§bm25-rerank

Stateless BM25 reranker. Given a query and a candidate set, computes per-doc BM25 scores against an in-memory term-frequency corpus derived from the candidates themselves.

This is the second-stage reranker pattern: dense retrieval pulls ~50 candidates, BM25 reranks them against the literal query terms to surface keyword matches that the embedding may have missed.

§Example

use bm25_rerank::rerank;
let docs = [
    "the quick brown fox",
    "a brown dog sleeps",
    "lazy fox jumps over",
];
let order = rerank("fox", &docs, Default::default());
// Doc 0 has "fox" and is shorter -> higher BM25 score
assert_eq!(order[0], 0);

Structs§

Bm25Opts
BM25 hyperparameters.

Functions§

rerank
Returns the candidate indices in BM25-score-descending order.
score
Per-doc BM25 scores, parallel to docs.