| Crates.io | rrf |
| lib.rs | rrf |
| version | 0.1.0 |
| created_at | 2025-08-29 02:44:49.215158+00 |
| updated_at | 2025-08-29 02:44:49.215158+00 |
| description | Reciprocal Rank Fusion (RRF) algorithm implementation in Rust |
| homepage | |
| repository | https://github.com/pengxiaochao/rrf |
| max_upload_size | |
| id | 1815173 |
| size | 10,470 |
A lightweight, efficient implementation of the Reciprocal Rank Fusion (RRF) algorithm in Rust.
Reciprocal Rank Fusion (RRF) is a simple but effective method for combining multiple ranked lists. It's commonly used in information retrieval, search engines, and recommendation systems to fuse results from different ranking algorithms.
RRF works by assigning a score to each document based on its position in each ranked list, then combining these scores to create a final ranking. The formula is:
RRF_score(document) = ∑ 1/(k + rank_i)
where k is a constant (commonly 60) that mitigates the impact of high rankings in individual lists.
Add this to your Cargo.toml:
[dependencies]
rrf = "0.1.0"
use rrf::fuse;
fn main() {
// Three different ranking algorithms produced these results
let bm25 = vec!["D3", "D1", "D2", "D5"];
let vector = vec!["D2", "D4", "D1"];
let rules = vec!["D5", "D2", "D6"];
// Fuse them with RRF (k=60)
let fused_results = fuse(&[bm25, vector, rules], 60);
// Print results (document ID and score)
for (doc, score) in fused_results {
println!("{} -> {:.6}", doc, score);
}
}
If some ranking algorithms are more trustworthy than others, you can assign weights:
use rrf::fuse_weighted;
fn main() {
let bm25 = vec!["D3", "D1", "D2", "D5"];
let vector = vec!["D2", "D4", "D1"];
let rules = vec!["D5", "D2", "D6"];
// Assign weights to each ranking algorithm
let fused_results = fuse_weighted(
&[bm25, vector, rules],
&[1.0, 2.0, 0.5], // Vector search gets double weight, rules half weight
60
);
for (doc, score) in fused_results {
println!("{} -> {:.6}", doc, score);
}
}
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to open issues or pull requests.