ragbench-eval 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. ragbench_eval-1.1.1/.github/workflows/benchmark.yml +48 -0
  2. ragbench_eval-1.1.1/.github/workflows/ci.yml +109 -0
  3. ragbench_eval-1.1.1/.github/workflows/publish.yml +68 -0
  4. ragbench_eval-1.1.1/.gitignore +9 -0
  5. ragbench_eval-1.1.1/CHANGELOG.md +35 -0
  6. ragbench_eval-1.1.1/LICENSE +21 -0
  7. ragbench_eval-1.1.1/PKG-INFO +259 -0
  8. ragbench_eval-1.1.1/README.md +231 -0
  9. ragbench_eval-1.1.1/action.yml +135 -0
  10. ragbench_eval-1.1.1/examples/overlap.py +32 -0
  11. ragbench_eval-1.1.1/pyproject.toml +50 -0
  12. ragbench_eval-1.1.1/results/arguana/bm25-stem.json +5712 -0
  13. ragbench_eval-1.1.1/results/arguana/bm25.json +5710 -0
  14. ragbench_eval-1.1.1/results/arguana/compare.json +36 -0
  15. ragbench_eval-1.1.1/results/arguana/dense-bge-small.json +5712 -0
  16. ragbench_eval-1.1.1/results/nfcorpus/bm25-stem.json +1380 -0
  17. ragbench_eval-1.1.1/results/nfcorpus/bm25.json +1378 -0
  18. ragbench_eval-1.1.1/results/nfcorpus/compare.json +36 -0
  19. ragbench_eval-1.1.1/results/nfcorpus/dense-bge-small.json +1380 -0
  20. ragbench_eval-1.1.1/results/scifact/bm25-stem.json +1288 -0
  21. ragbench_eval-1.1.1/results/scifact/bm25.json +1286 -0
  22. ragbench_eval-1.1.1/results/scifact/compare.json +36 -0
  23. ragbench_eval-1.1.1/results/scifact/dense-bge-small.json +1288 -0
  24. ragbench_eval-1.1.1/scripts/benchmark.sh +26 -0
  25. ragbench_eval-1.1.1/scripts/update_readme.py +82 -0
  26. ragbench_eval-1.1.1/src/ragbench/__init__.py +25 -0
  27. ragbench_eval-1.1.1/src/ragbench/__main__.py +3 -0
  28. ragbench_eval-1.1.1/src/ragbench/cli.py +206 -0
  29. ragbench_eval-1.1.1/src/ragbench/compare.py +69 -0
  30. ragbench_eval-1.1.1/src/ragbench/datasets.py +103 -0
  31. ragbench_eval-1.1.1/src/ragbench/download.py +124 -0
  32. ragbench_eval-1.1.1/src/ragbench/gate.py +108 -0
  33. ragbench_eval-1.1.1/src/ragbench/metrics.py +69 -0
  34. ragbench_eval-1.1.1/src/ragbench/report.py +28 -0
  35. ragbench_eval-1.1.1/src/ragbench/retriever.py +124 -0
  36. ragbench_eval-1.1.1/src/ragbench/retrievers/__init__.py +11 -0
  37. ragbench_eval-1.1.1/src/ragbench/retrievers/bm25.py +102 -0
  38. ragbench_eval-1.1.1/src/ragbench/retrievers/dense.py +80 -0
  39. ragbench_eval-1.1.1/src/ragbench/runner.py +181 -0
  40. ragbench_eval-1.1.1/src/ragbench/stats.py +66 -0
  41. ragbench_eval-1.1.1/tests/__init__.py +0 -0
  42. ragbench_eval-1.1.1/tests/conftest.py +18 -0
  43. ragbench_eval-1.1.1/tests/fixtures/gate/tiny-bm25.json +98 -0
  44. ragbench_eval-1.1.1/tests/fixtures/tiny/corpus.jsonl +6 -0
  45. ragbench_eval-1.1.1/tests/fixtures/tiny/qrels/test.tsv +8 -0
  46. ragbench_eval-1.1.1/tests/fixtures/tiny/queries.jsonl +4 -0
  47. ragbench_eval-1.1.1/tests/test_cli.py +185 -0
  48. ragbench_eval-1.1.1/tests/test_datasets.py +54 -0
  49. ragbench_eval-1.1.1/tests/test_gate.py +115 -0
  50. ragbench_eval-1.1.1/tests/test_metrics.py +95 -0
  51. ragbench_eval-1.1.1/tests/test_retrievers.py +104 -0
  52. ragbench_eval-1.1.1/tests/test_runner.py +187 -0
  53. ragbench_eval-1.1.1/tests/test_stats.py +65 -0
  54. ragbench_eval-1.1.1/tests/test_update_readme.py +48 -0
@@ -0,0 +1,48 @@
1
+ name: Benchmark
2
+
3
+ # Runs scripts/benchmark.sh on BEIR datasets and uploads results/ as an artifact.
4
+ # The result files committed to this repository are that artifact, unedited; each
5
+ # one records this workflow's run URL and the commit it ran on.
6
+
7
+ on:
8
+ workflow_dispatch:
9
+ inputs:
10
+ datasets:
11
+ description: "Space-separated BEIR datasets"
12
+ default: "scifact nfcorpus arguana"
13
+ pull_request:
14
+ paths:
15
+ - "scripts/benchmark.sh"
16
+ - ".github/workflows/benchmark.yml"
17
+ - "src/ragbench/retrievers/**"
18
+
19
+ permissions:
20
+ contents: read
21
+
22
+ jobs:
23
+ benchmark:
24
+ runs-on: ubuntu-latest
25
+ timeout-minutes: 90
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: actions/setup-python@v5
29
+ with:
30
+ python-version: "3.12"
31
+ - uses: actions/cache@v4
32
+ with:
33
+ path: |
34
+ data
35
+ /tmp/fastembed_cache
36
+ key: beir-and-models-v2
37
+ - run: pip install -e '.[dense,stem,hf]'
38
+ - name: Run the benchmark
39
+ env:
40
+ DATASETS: ${{ github.event.inputs.datasets || 'scifact nfcorpus arguana' }}
41
+ FASTEMBED_CACHE_PATH: /tmp/fastembed_cache
42
+ run: bash scripts/benchmark.sh
43
+ - name: Results table
44
+ run: ragbench report results/*/bm25.json results/*/bm25-stem.json results/*/dense-bge-small.json | tee -a "$GITHUB_STEP_SUMMARY"
45
+ - uses: actions/upload-artifact@v4
46
+ with:
47
+ name: benchmark-results
48
+ path: results/
@@ -0,0 +1,109 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ lint:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+ - run: pip install "ruff>=0.6"
20
+ - run: ruff check .
21
+ - run: ruff format --check .
22
+
23
+ test:
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ fail-fast: false
27
+ matrix:
28
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+ - uses: actions/setup-python@v5
32
+ with:
33
+ python-version: ${{ matrix.python-version }}
34
+ - name: Install
35
+ run: pip install -e '.[dev,stem,hf]' numpy pytrec-eval-terrier
36
+ - name: Test (metrics cross-checked against trec_eval)
37
+ run: pytest --cov=ragbench --cov-report=term-missing
38
+ - name: README results match results/
39
+ run: python scripts/update_readme.py --check
40
+
41
+ package:
42
+ runs-on: ubuntu-latest
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+ - uses: actions/setup-python@v5
46
+ with:
47
+ python-version: "3.12"
48
+ - run: pip install build twine
49
+ - run: python -m build
50
+ - run: twine check --strict dist/*
51
+ - name: Install the wheel in a clean venv and run the CLI
52
+ run: |
53
+ python -m venv /tmp/venv
54
+ /tmp/venv/bin/pip install dist/*.whl
55
+ /tmp/venv/bin/ragbench --version
56
+ /tmp/venv/bin/ragbench run --data tests/fixtures/tiny \
57
+ --retriever examples/overlap.py:WordOverlap --out /tmp/r.json --quiet
58
+
59
+ dense-smoke:
60
+ # Exercises the real fastembed path end to end (downloads a ~67 MB ONNX model).
61
+ runs-on: ubuntu-latest
62
+ steps:
63
+ - uses: actions/checkout@v4
64
+ - uses: actions/setup-python@v5
65
+ with:
66
+ python-version: "3.12"
67
+ - uses: actions/cache@v4
68
+ with:
69
+ path: /tmp/fastembed_cache
70
+ key: fastembed-bge-small-en-v1.5
71
+ - run: pip install -e '.[dense]'
72
+ - name: Run Dense on the tiny fixture
73
+ env:
74
+ FASTEMBED_CACHE_PATH: /tmp/fastembed_cache
75
+ run: |
76
+ ragbench run --data tests/fixtures/tiny --retriever ragbench.retrievers:Dense \
77
+ --param model=BAAI/bge-small-en-v1.5 --out /tmp/dense.json --quiet
78
+ python -c "import json; d = json.load(open('/tmp/dense.json')); assert d['metrics']['recall@10']['mean'] > 0, d['metrics']"
79
+
80
+ gate-action:
81
+ runs-on: ubuntu-latest
82
+ steps:
83
+ - uses: actions/checkout@v4
84
+ - name: Same retriever as the baseline passes
85
+ id: same
86
+ uses: ./
87
+ with:
88
+ data: tests/fixtures/tiny
89
+ retriever: ragbench.retrievers:BM25
90
+ baseline: tests/fixtures/gate/tiny-bm25.json
91
+ metrics: ndcg@10,recall@10
92
+ - name: A worse retriever fails
93
+ id: worse
94
+ continue-on-error: true
95
+ uses: ./
96
+ with:
97
+ data: tests/fixtures/tiny
98
+ retriever: examples/overlap.py:WordOverlap
99
+ params: |
100
+ min_overlap=2
101
+ baseline: tests/fixtures/gate/tiny-bm25.json
102
+ - name: Check both outcomes
103
+ env:
104
+ SAME: ${{ steps.same.outputs.passed }}
105
+ WORSE: ${{ steps.worse.outputs.passed }}
106
+ WORSE_OUTCOME: ${{ steps.worse.outcome }}
107
+ run: |
108
+ echo "same=$SAME worse=$WORSE worse_outcome=$WORSE_OUTCOME"
109
+ [ "$SAME" = "true" ] && [ "$WORSE" = "false" ] && [ "$WORSE_OUTCOME" = "failure" ]
@@ -0,0 +1,68 @@
1
+ name: Publish to PyPI
2
+
3
+ # Publishes a tagged release to PyPI with trusted publishing (no API token is
4
+ # stored anywhere). It runs when a GitHub release is published, or by hand for
5
+ # a tag that already has a release, such as v1.0.0.
6
+
7
+ on:
8
+ release:
9
+ types: [published]
10
+ workflow_dispatch:
11
+ inputs:
12
+ tag:
13
+ description: "Tag to publish, for example v1.0.0"
14
+ required: true
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ build:
21
+ runs-on: ubuntu-latest
22
+ env:
23
+ TAG: ${{ github.event.release.tag_name || inputs.tag }}
24
+ steps:
25
+ - name: Check the tag looks like vX.Y.Z
26
+ run: |
27
+ echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$' \
28
+ || { echo "::error::tag '$TAG' is not vX.Y.Z"; exit 1; }
29
+ - uses: actions/checkout@v4
30
+ with:
31
+ ref: refs/tags/${{ env.TAG }}
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: "3.12"
35
+ - name: Check the package version matches the tag
36
+ run: |
37
+ version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
38
+ [ "v$version" = "$TAG" ] \
39
+ || { echo "::error::pyproject.toml says $version but the tag is $TAG"; exit 1; }
40
+ - run: pip install build twine
41
+ - run: python -m build
42
+ - run: twine check --strict dist/*
43
+ - name: Install the wheel in a clean venv and run the CLI
44
+ run: |
45
+ python -m venv /tmp/venv
46
+ /tmp/venv/bin/pip install dist/*.whl
47
+ /tmp/venv/bin/ragbench --version
48
+ /tmp/venv/bin/ragbench run --data tests/fixtures/tiny \
49
+ --retriever examples/overlap.py:WordOverlap --out /tmp/r.json --quiet
50
+ - uses: actions/upload-artifact@v4
51
+ with:
52
+ name: dist
53
+ path: dist/
54
+
55
+ publish:
56
+ needs: build
57
+ runs-on: ubuntu-latest
58
+ environment:
59
+ name: pypi
60
+ url: https://pypi.org/project/ragbench-eval/
61
+ permissions:
62
+ id-token: write
63
+ steps:
64
+ - uses: actions/download-artifact@v4
65
+ with:
66
+ name: dist
67
+ path: dist/
68
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ .coverage
6
+ dist/
7
+ build/
8
+ .venv/
9
+ /data/
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ ## 1.1.1 (unreleased)
4
+
5
+ - The distribution is renamed `ragbench-eval`, because PyPI refuses `ragbench` as too
6
+ close to the existing `rag-bench` project. The import name and the `ragbench` command
7
+ are unchanged.
8
+
9
+ ## 1.1.0 (unreleased)
10
+
11
+ - `ragbench gate`: compares a candidate run with a baseline on the same queries and
12
+ exits 1 when a metric drops by more than `--max-drop`, judged on the mean change or,
13
+ with `--mode ci`, on the whole 95% interval. Runs that differ in split, depth, nDCG
14
+ cutoff or identical-id handling are refused. Writes a Markdown summary to
15
+ `$GITHUB_STEP_SUMMARY` when set.
16
+ - `action.yml`: a GitHub Action that runs the candidate retriever and the gate, so a
17
+ pull request fails when retrieval quality drops below a committed baseline.
18
+
19
+ ## 1.0.0 (2026-11-27)
20
+
21
+ First stable release.
22
+
23
+ - BEIR loader (`corpus.jsonl`, `queries.jsonl`, `qrels/<split>.tsv`) and `ragbench download`,
24
+ with a Hugging Face fallback when the UKP mirror is unreachable.
25
+ - Metrics: nDCG@10 (linear gains, matching trec_eval `ndcg_cut.10`), Recall@10, Recall@100,
26
+ MRR@10, cross-checked against pytrec_eval in the tests.
27
+ - Seeded percentile bootstrap intervals for every mean, and a paired bootstrap for
28
+ comparing two runs on the same queries.
29
+ - Retriever protocol: any object with `search(query, k)`, loaded from `module:Name` or
30
+ `file.py:Name`, with optional `index()` and `search_batch()`.
31
+ - Built-in retrievers: Lucene-style BM25 (optional Snowball stemming) and a dense
32
+ retriever over fastembed embeddings.
33
+ - CLI: `download`, `info`, `run`, `compare`, `report`.
34
+ - Benchmark results on SciFact, NFCorpus and ArguAna, generated by
35
+ `scripts/benchmark.sh` and committed unedited under `results/`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Harshit Gadge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,259 @@
1
+ Metadata-Version: 2.5
2
+ Name: ragbench-eval
3
+ Version: 1.1.1
4
+ Summary: Evaluate any retriever on BEIR-format data: nDCG, recall and MRR with bootstrap confidence intervals and paired comparisons.
5
+ Project-URL: Repository, https://github.com/HarshitGadge/ragbench
6
+ Author: Harshit Gadge
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: beir,benchmark,evaluation,information-retrieval,rag,retrieval
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
15
+ Requires-Python: >=3.10
16
+ Provides-Extra: dense
17
+ Requires-Dist: fastembed>=0.4; extra == 'dense'
18
+ Requires-Dist: numpy>=1.26; extra == 'dense'
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
21
+ Requires-Dist: pytest>=8; extra == 'dev'
22
+ Requires-Dist: ruff>=0.6; extra == 'dev'
23
+ Provides-Extra: hf
24
+ Requires-Dist: pyarrow>=15; extra == 'hf'
25
+ Provides-Extra: stem
26
+ Requires-Dist: snowballstemmer>=2.2; extra == 'stem'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # RAGBench
30
+
31
+ Evaluate any retriever on [BEIR](https://github.com/beir-cellar/beir)-format data and
32
+ get numbers you can defend: nDCG@10, Recall@10/100 and MRR@10 per query, a bootstrap
33
+ 95% confidence interval on every mean, and a paired bootstrap when you compare two runs.
34
+
35
+ - **Bring your own retriever.** Anything with a `search(query, k)` method plugs in,
36
+ from a module or a single `.py` file. No base class, no framework.
37
+ - **No runtime dependencies.** The core is the Python standard library.
38
+ - **Checked against `trec_eval`.** The metric tests compare every score with
39
+ `pytrec_eval` on randomised runs with graded judgements.
40
+ - **Reproducible results.** Each result file records the exact command, parameters,
41
+ seed, Python and RAGBench versions, and every per-query score.
42
+ - **A CI gate.** A GitHub Action fails a pull request when retrieval quality drops
43
+ below a committed baseline, the way a coverage check does for tests.
44
+
45
+ Every number in this README comes from a result file in [`results/`](results), produced
46
+ by [`scripts/benchmark.sh`](scripts/benchmark.sh) in the Benchmark workflow. The table
47
+ below is generated from those files, and CI fails if it drifts.
48
+
49
+ ## Results
50
+
51
+ Built-in retrievers on three BEIR test sets: SciFact, NFCorpus
52
+ and ArguAna. Dense uses `BAAI/bge-small-en-v1.5` through fastembed with no query
53
+ instruction; BM25 uses k1=0.9, b=0.4. Latency is per query on a GitHub-hosted runner,
54
+ and Dense batches its queries, so its p50 is the batch time divided by the query count.
55
+
56
+ <!-- results:start -->
57
+ | dataset | retriever | ndcg@10 | recall@10 | recall@100 | mrr@10 | queries | p50 ms |
58
+ |---|---|---|---|---|---|---|---|
59
+ | arguana | bm25 | 0.4052 (0.387 to 0.424) | 0.6814 (0.657 to 0.707) | 0.9317 (0.918 to 0.945) | 0.3203 (0.302 to 0.340) | 1406 | 10.10 |
60
+ | arguana | bm25-stem | 0.4012 (0.382 to 0.420) | 0.6643 (0.639 to 0.689) | 0.9324 (0.919 to 0.946) | 0.3198 (0.301 to 0.339) | 1406 | 13.53 |
61
+ | arguana | dense-bge-small | 0.5973 (0.578 to 0.616) | 0.8535 (0.835 to 0.871) | 0.9844 (0.978 to 0.991) | 0.5166 (0.495 to 0.538) | 1406 | 182.74 |
62
+ | nfcorpus | bm25 | 0.3061 (0.272 to 0.340) | 0.1466 (0.122 to 0.173) | 0.2360 (0.208 to 0.266) | 0.5106 (0.462 to 0.561) | 323 | 0.14 |
63
+ | nfcorpus | bm25-stem | 0.3208 (0.287 to 0.355) | 0.1523 (0.127 to 0.179) | 0.2461 (0.218 to 0.276) | 0.5231 (0.474 to 0.572) | 323 | 0.22 |
64
+ | nfcorpus | dense-bge-small | 0.3385 (0.306 to 0.373) | 0.1609 (0.137 to 0.187) | 0.3057 (0.277 to 0.336) | 0.5305 (0.484 to 0.577) | 323 | 3.21 |
65
+ | scifact | bm25 | 0.6635 (0.620 to 0.710) | 0.7834 (0.737 to 0.829) | 0.8859 (0.851 to 0.922) | 0.6316 (0.585 to 0.681) | 300 | 0.91 |
66
+ | scifact | bm25-stem | 0.6804 (0.635 to 0.724) | 0.8030 (0.758 to 0.846) | 0.9220 (0.891 to 0.951) | 0.6475 (0.600 to 0.694) | 300 | 1.40 |
67
+ | scifact | dense-bge-small | 0.7201 (0.677 to 0.760) | 0.8452 (0.806 to 0.883) | 0.9533 (0.927 to 0.977) | 0.6846 (0.637 to 0.728) | 300 | 9.41 |
68
+
69
+
70
+ Means over test queries with 95% bootstrap intervals; ragbench 0.1.0, commit 16ed3d5, workflow run [45932384237](https://github.com/HarshitGadge/ragbench/actions/runs/45932384237).
71
+
72
+
73
+ Paired bootstrap, dense minus BM25 (stemmed), same queries:
74
+
75
+ - arguana, ndcg@10: +0.1961 (95% CI +0.1776 to +0.2148, 1406 queries, interval excludes 0)
76
+ - arguana, recall@100: +0.0519 (95% CI +0.0391 to +0.0647, 1406 queries, interval excludes 0)
77
+ - nfcorpus, ndcg@10: +0.0177 (95% CI -0.0040 to +0.0390, 323 queries, interval includes 0)
78
+ - nfcorpus, recall@100: +0.0596 (95% CI +0.0405 to +0.0795, 323 queries, interval excludes 0)
79
+ - scifact, ndcg@10: +0.0397 (95% CI +0.0051 to +0.0730, 300 queries, interval excludes 0)
80
+ - scifact, recall@100: +0.0313 (95% CI -0.0013 to +0.0660, 300 queries, interval includes 0)
81
+ <!-- results:end -->
82
+
83
+ Reproduce:
84
+
85
+ ```bash
86
+ pip install -e '.[dense,stem,hf]'
87
+ bash scripts/benchmark.sh
88
+ python scripts/update_readme.py
89
+ ```
90
+
91
+ ## Install
92
+
93
+ ```bash
94
+ pip install "git+https://github.com/HarshitGadge/ragbench@v1.1.1"
95
+
96
+ # with the built-in dense retriever, stemming and the Hugging Face download fallback
97
+ pip install "ragbench-eval[dense,stem,hf] @ git+https://github.com/HarshitGadge/ragbench@v1.1.1"
98
+ ```
99
+
100
+ The distribution is named `ragbench-eval`, because PyPI reserves names too close to the
101
+ existing `rag-bench` package; you still `import ragbench` and run `ragbench`.
102
+ The core package has no runtime dependencies. Extras: `dense` (fastembed, numpy),
103
+ `stem` (snowballstemmer), `hf` (pyarrow).
104
+
105
+ ## Quick start
106
+
107
+ ```bash
108
+ ragbench info # datasets worth starting with
109
+ ragbench download scifact # into ./data/scifact
110
+ ragbench run --data data/scifact --retriever examples/overlap.py:WordOverlap
111
+ ```
112
+
113
+ `run` prints a Markdown table and writes `results/<dataset>__<name>.json`.
114
+
115
+ ## Built-in retrievers
116
+
117
+ Two baselines ship with RAGBench, and they double as examples of the interface.
118
+
119
+ | retriever | spec | needs |
120
+ |---|---|---|
121
+ | BM25 (Lucene scoring, k1=0.9, b=0.4) | `ragbench.retrievers:BM25` | nothing |
122
+ | Dense, cosine over normalised embeddings | `ragbench.retrievers:Dense` | `pip install 'ragbench-eval[dense]'` |
123
+
124
+ ```bash
125
+ ragbench run --data data/scifact --retriever ragbench.retrievers:BM25 --param stem=true
126
+ ragbench run --data data/scifact --retriever ragbench.retrievers:Dense \
127
+ --param model=BAAI/bge-small-en-v1.5
128
+ ```
129
+
130
+ BM25 takes `k1`, `b`, `stopwords` (Lucene's English list, on by default) and `stem`
131
+ (Snowball, `pip install 'ragbench-eval[stem]'`). Its tokeniser is simpler than an
132
+ Elasticsearch analyser, so its scores will not match Elasticsearch-based BEIR
133
+ baselines exactly. Dense takes `model` (any [fastembed](https://github.com/qdrant/fastembed)
134
+ text model), `query_prefix` for models that expect one, and `batch_size`; from Python
135
+ you can pass `encoder=` with any object that has `embed_documents` and `embed_query`.
136
+
137
+ ## Plug in a retriever
138
+
139
+ ```python
140
+ # my_retriever.py
141
+ class MyRetriever:
142
+ def __init__(self, top_n: int = 100):
143
+ self.top_n = top_n
144
+
145
+ def index(self, corpus): # optional: {doc_id: Document(id, title, body)}
146
+ ...
147
+
148
+ def search(self, query: str, k: int):
149
+ return [("doc-17", 12.3), ("doc-4", 11.0)] # ids, Hit objects or (id, score)
150
+ ```
151
+
152
+ ```bash
153
+ ragbench run --data data/scifact --retriever my_retriever.py:MyRetriever --param top_n=50
154
+ ```
155
+
156
+ `--param key=value` values are parsed as JSON when they can be (`0.5`, `true`, `[1,2]`).
157
+ A retriever can also define `search_batch(queries, k)`, which RAGBench uses instead of
158
+ `search` when present. Returning several chunks of the same document is fine: a
159
+ document counts once, at the rank of its best chunk.
160
+
161
+ From Python:
162
+
163
+ ```python
164
+ from ragbench import load_beir, evaluate
165
+
166
+ dataset = load_beir("data/scifact")
167
+ result = evaluate(MyRetriever(), dataset, name="mine")
168
+ print(result.summary()["ndcg@10"]) # {'mean': ..., 'ci': [low, high], 'level': 0.95}
169
+ result.save("results/scifact__mine.json")
170
+ ```
171
+
172
+ ## Compare two runs
173
+
174
+ ```bash
175
+ ragbench compare results/scifact__baseline.json results/scifact__mine.json --metric ndcg@10
176
+ ```
177
+
178
+ The difference is resampled over queries (2,000 rounds, seeded), so the interval says
179
+ whether the change would survive a different sample of questions. Both runs must cover
180
+ the same queries.
181
+
182
+ ## Gate pull requests on retrieval quality
183
+
184
+ `ragbench gate` compares a candidate run with a baseline run on the same queries and
185
+ exits 1 when a metric dropped by more than `--max-drop`:
186
+
187
+ ```bash
188
+ ragbench gate baseline.json candidate.json --metric ndcg@10 --max-drop 0.01
189
+ ```
190
+
191
+ With `--mode mean` (the default) it fails on the mean change. With `--mode ci` it fails
192
+ only when the whole 95% interval for the change is below `-max-drop`, so a drop that
193
+ could be noise doesn't fail the build. Runs that differ in split, depth, nDCG cutoff
194
+ or identical-id handling aren't comparable, and the gate refuses them.
195
+
196
+ The same check runs as a GitHub Action. Commit a small BEIR-format evaluation set and a
197
+ baseline run, then add a workflow:
198
+
199
+ ```bash
200
+ ragbench run --data eval/my-set --retriever my_app.search:Retriever --out eval/baseline.json
201
+ ```
202
+
203
+ ```yaml
204
+ # .github/workflows/retrieval.yml
205
+ on: pull_request
206
+ jobs:
207
+ retrieval:
208
+ runs-on: ubuntu-latest
209
+ steps:
210
+ - uses: actions/checkout@v4
211
+ - uses: HarshitGadge/ragbench@v1.1.0
212
+ with:
213
+ install: pip install -e . # so the action can import my_app
214
+ data: eval/my-set
215
+ retriever: my_app.search:Retriever
216
+ baseline: eval/baseline.json
217
+ metrics: ndcg@10,recall@100
218
+ max-drop: "0.01"
219
+ ```
220
+
221
+ The job summary shows a table of baseline, candidate and change with its interval.
222
+ A retriever given as `path/to/file.py:Name` needs no `install`. Inputs `params` (one
223
+ `KEY=VALUE` per line), `mode`, `split`, `depth`, `extras` and `python-version` are
224
+ optional too; see [`action.yml`](action.yml). Re-run the baseline
225
+ command and commit the file when you mean to change the baseline.
226
+
227
+ ## Make a results table
228
+
229
+ ```bash
230
+ ragbench report results/*.json
231
+ ```
232
+
233
+ ## How the metrics are computed
234
+
235
+ | metric | definition |
236
+ |---|---|
237
+ | nDCG@10 | DCG with linear gains (the judgement grade) and log2 discounts, divided by the ideal DCG; the `ndcg_cut.10` that `trec_eval` and BEIR report |
238
+ | Recall@k | relevant documents in the top k, over all relevant documents |
239
+ | MRR@10 | 1 / rank of the first relevant document in the top 10, else 0 |
240
+
241
+ Judgements of 0 count as not relevant, and queries without a relevant document are
242
+ skipped, as in BEIR.
243
+
244
+ ## Development
245
+
246
+ ```bash
247
+ pip install -e '.[dev,stem]' numpy pytrec-eval-terrier
248
+ ruff check . && ruff format --check . && pytest
249
+ ```
250
+
251
+ ## Origin
252
+
253
+ The loader, metrics and bootstrap started as the retrieval evaluation in
254
+ [agentic-rag-service](https://github.com/HarshitGadge/agentic-rag-service) and were
255
+ generalised here so they are not tied to one service.
256
+
257
+ ## License
258
+
259
+ MIT