rag-benchmarking 1.0.0__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 (55) hide show
  1. rag_benchmarking-1.0.0/LICENSE +202 -0
  2. rag_benchmarking-1.0.0/NOTICE +17 -0
  3. rag_benchmarking-1.0.0/PKG-INFO +407 -0
  4. rag_benchmarking-1.0.0/README.md +360 -0
  5. rag_benchmarking-1.0.0/pyproject.toml +116 -0
  6. rag_benchmarking-1.0.0/setup.cfg +4 -0
  7. rag_benchmarking-1.0.0/src/app/__init__.py +5 -0
  8. rag_benchmarking-1.0.0/src/app/api/evaluate.py +173 -0
  9. rag_benchmarking-1.0.0/src/app/api/query.py +67 -0
  10. rag_benchmarking-1.0.0/src/app/api/security.py +23 -0
  11. rag_benchmarking-1.0.0/src/app/config/__init__.py +1 -0
  12. rag_benchmarking-1.0.0/src/app/config/settings.py +72 -0
  13. rag_benchmarking-1.0.0/src/app/engine/__init__.py +0 -0
  14. rag_benchmarking-1.0.0/src/app/engine/rag_engine.py +176 -0
  15. rag_benchmarking-1.0.0/src/app/eval/agentic_llm_metrics.py +146 -0
  16. rag_benchmarking-1.0.0/src/app/eval/agentic_metrics.py +44 -0
  17. rag_benchmarking-1.0.0/src/app/eval/faithfulness.py +79 -0
  18. rag_benchmarking-1.0.0/src/app/eval/ragas_runner.py +194 -0
  19. rag_benchmarking-1.0.0/src/app/eval/reporting.py +30 -0
  20. rag_benchmarking-1.0.0/src/app/eval/result_store.py +265 -0
  21. rag_benchmarking-1.0.0/src/app/eval/retrieval_metrics.py +38 -0
  22. rag_benchmarking-1.0.0/src/app/exceptions.py +22 -0
  23. rag_benchmarking-1.0.0/src/app/llm/client.py +175 -0
  24. rag_benchmarking-1.0.0/src/app/logging/__init__.py +1 -0
  25. rag_benchmarking-1.0.0/src/app/logging/json_logger.py +51 -0
  26. rag_benchmarking-1.0.0/src/app/main.py +89 -0
  27. rag_benchmarking-1.0.0/src/app/quality/self_check.py +13 -0
  28. rag_benchmarking-1.0.0/src/app/retrieval/chunking.py +49 -0
  29. rag_benchmarking-1.0.0/src/app/retrieval/embeddings.py +18 -0
  30. rag_benchmarking-1.0.0/src/app/retrieval/ingest_cli.py +69 -0
  31. rag_benchmarking-1.0.0/src/app/retrieval/qdrant_store.py +149 -0
  32. rag_benchmarking-1.0.0/src/app/retrieval/reranker.py +25 -0
  33. rag_benchmarking-1.0.0/src/app/retrieval/service.py +55 -0
  34. rag_benchmarking-1.0.0/src/app/sdk/__init__.py +0 -0
  35. rag_benchmarking-1.0.0/src/app/sdk/client.py +184 -0
  36. rag_benchmarking-1.0.0/src/app/utils/timing.py +17 -0
  37. rag_benchmarking-1.0.0/src/harness/__init__.py +34 -0
  38. rag_benchmarking-1.0.0/src/harness/protocol.py +68 -0
  39. rag_benchmarking-1.0.0/src/harness/result_store.py +96 -0
  40. rag_benchmarking-1.0.0/src/harness/runner.py +160 -0
  41. rag_benchmarking-1.0.0/src/harness/schemas.py +193 -0
  42. rag_benchmarking-1.0.0/src/rag_benchmarking.egg-info/PKG-INFO +407 -0
  43. rag_benchmarking-1.0.0/src/rag_benchmarking.egg-info/SOURCES.txt +53 -0
  44. rag_benchmarking-1.0.0/src/rag_benchmarking.egg-info/dependency_links.txt +1 -0
  45. rag_benchmarking-1.0.0/src/rag_benchmarking.egg-info/requires.txt +23 -0
  46. rag_benchmarking-1.0.0/src/rag_benchmarking.egg-info/top_level.txt +2 -0
  47. rag_benchmarking-1.0.0/tests/test_chunking.py +12 -0
  48. rag_benchmarking-1.0.0/tests/test_config_and_logging.py +18 -0
  49. rag_benchmarking-1.0.0/tests/test_embeddings.py +14 -0
  50. rag_benchmarking-1.0.0/tests/test_eval_pipeline.py +453 -0
  51. rag_benchmarking-1.0.0/tests/test_evaluate_api.py +39 -0
  52. rag_benchmarking-1.0.0/tests/test_health.py +18 -0
  53. rag_benchmarking-1.0.0/tests/test_query_api.py +44 -0
  54. rag_benchmarking-1.0.0/tests/test_rerank_integration.py +44 -0
  55. rag_benchmarking-1.0.0/tests/test_security.py +56 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,17 @@
1
+ RAG Benchmarking
2
+ Copyright 2026 AI Exponent LLC
3
+
4
+ This product includes software developed at AI Exponent LLC
5
+ (https://aiexponent.com).
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
@@ -0,0 +1,407 @@
1
+ Metadata-Version: 2.4
2
+ Name: rag-benchmarking
3
+ Version: 1.0.0
4
+ Summary: Framework-agnostic evaluation harness for RAG and agentic AI systems
5
+ Author: Ajay Pundhir
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://aiexponent.com
8
+ Project-URL: Repository, https://github.com/aiexponenthq/rag-benchmarking
9
+ Project-URL: Documentation, https://github.com/aiexponenthq/rag-benchmarking#readme
10
+ Project-URL: Bug Tracker, https://github.com/aiexponenthq/rag-benchmarking/issues
11
+ Keywords: rag,evaluation,benchmarking,llm,ai-governance,eu-ai-act,agentic-ai
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Testing
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ License-File: NOTICE
25
+ Requires-Dist: fastapi>=0.110
26
+ Requires-Dist: uvicorn>=0.30
27
+ Requires-Dist: pydantic>=2.6
28
+ Requires-Dist: pydantic-settings>=2.2
29
+ Requires-Dist: python-json-logger>=2.0.7
30
+ Requires-Dist: qdrant-client>=1.9
31
+ Requires-Dist: sentence-transformers>=3.0
32
+ Requires-Dist: numpy>=1.26
33
+ Requires-Dist: tqdm>=4.66
34
+ Requires-Dist: requests>=2.31
35
+ Requires-Dist: ragas>=0.1.9
36
+ Requires-Dist: langchain-google-genai>=2.0.9
37
+ Requires-Dist: FlagEmbedding>=1.2.11
38
+ Provides-Extra: test
39
+ Requires-Dist: pytest>=8.2; extra == "test"
40
+ Requires-Dist: pytest-asyncio>=0.23; extra == "test"
41
+ Requires-Dist: pytest-cov>=5.0; extra == "test"
42
+ Requires-Dist: httpx>=0.27; extra == "test"
43
+ Provides-Extra: lint
44
+ Requires-Dist: ruff==0.15.12; extra == "lint"
45
+ Requires-Dist: mypy>=1.10; extra == "lint"
46
+ Dynamic: license-file
47
+
48
+ <p align="center">
49
+ <a href="https://aiexponent.com"><img src=".github/brand/logo-full-light.png" alt="AiExponent — Building AI that deserves to be trusted" width="560"></a>
50
+ </p>
51
+
52
+ <h1 align="center">RAG Benchmarking</h1>
53
+ <p align="center"><em>Prove your RAG system works — before you ship.</em></p>
54
+
55
+ <p align="center">
56
+ <a href="https://pypi.org/project/rag-benchmarking/"><img src="https://img.shields.io/pypi/v/rag-benchmarking.svg" alt="PyPI"></a>
57
+ <a href="https://github.com/aiexponenthq/rag-benchmarking/actions"><img src="https://github.com/aiexponenthq/rag-benchmarking/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
58
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-0D5463.svg" alt="License: Apache 2.0"></a>
59
+ <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11%2B-0D5463.svg" alt="Python 3.11+"></a>
60
+ <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32024R1689"><img src="https://img.shields.io/badge/EU%20AI%20Act-Article%2015-0D5463.svg" alt="EU AI Act Article 15"></a>
61
+ <a href="#privacy"><img src="https://img.shields.io/badge/telemetry-zero-0B7A4B.svg" alt="Zero telemetry"></a>
62
+ </p>
63
+
64
+ ---
65
+
66
+ **A framework-agnostic evaluation harness for RAG and agentic AI systems.**
67
+
68
+ Bring your own RAG pipeline — LangChain, LlamaIndex, or custom — and benchmark it against classic and agentic-era metrics. Built for teams who need to prove their AI systems work before they ship.
69
+
70
+ Built by [AI Exponent LLC](https://aiexponent.com). Provides **partial Art. 15(1) accuracy input** for high-risk AI systems — not Art. 15 robustness, not cybersecurity, not conformity evidence (see [scope panel](#eu-ai-act-article-15--partial-input-not-conformity-evidence)).
71
+
72
+ ---
73
+
74
+ ## Quick Start
75
+
76
+ ```bash
77
+ pip install rag-benchmarking
78
+ ```
79
+
80
+ ```python
81
+ from app.sdk.client import RagEval
82
+
83
+ client = RagEval(api_url="http://localhost:5001", api_key="your-key")
84
+
85
+ # Works with LangChain
86
+ result = my_chain.invoke({"query": "What is RAG?"})
87
+ sample = RagEval.from_langchain(result)
88
+
89
+ # Or any dict with question / contexts / answer
90
+ sample = {
91
+ "question": "What is RAG?",
92
+ "contexts": ["RAG stands for Retrieval-Augmented Generation."],
93
+ "answer": "RAG combines retrieval with LLM generation.",
94
+ }
95
+
96
+ report = client.evaluate([sample], metrics=["faithfulness", "answer_relevancy"])
97
+ print(report["metrics"])
98
+ # {"faithfulness": 0.958, "answer_relevancy": 0.810}
99
+ ```
100
+
101
+ ```bash
102
+ # Start the evaluation server
103
+ docker compose up
104
+ # API docs: http://localhost:5001/docs
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Architecture
110
+
111
+ ```mermaid
112
+ graph TD
113
+ RAG["Your RAG System\nLangChain · LlamaIndex · Custom"]
114
+ SDK["SDK Adapters\nRagEval.from_langchain()\nRagEval.from_llamaindex()"]
115
+ SCHEMA["EvalSample / AgentTrace\nharness/schemas.py"]
116
+ RUNNER["EvaluationRunner\nharness/runner.py"]
117
+
118
+ CLASSIC["Classic Metrics\nfaithfulness · answer_relevancy\ncontext_precision · context_recall"]
119
+ RETRIEVAL["Retrieval Metrics\nPrecision@K · Recall@K\nMRR · NDCG"]
120
+ AGENTIC["Agentic Metrics\nagent_faithfulness · tool_call_accuracy\nretrieval_necessity · source_attribution"]
121
+
122
+ REPORT["BenchmarkReport"]
123
+ STORE["SQLite ResultStore\nRun history + comparison"]
124
+ API["REST API\n/v1/evaluate · /v1/evaluate/agent\n/v1/runs · /v1/runs/compare"]
125
+
126
+ RAG --> SDK --> SCHEMA --> RUNNER
127
+ RUNNER --> CLASSIC
128
+ RUNNER --> RETRIEVAL
129
+ RUNNER --> AGENTIC
130
+ CLASSIC --> REPORT
131
+ RETRIEVAL --> REPORT
132
+ AGENTIC --> REPORT
133
+ REPORT --> STORE --> API
134
+
135
+ style RAG fill:#2d5a2d,color:#fff
136
+ style SDK fill:#1e3a5f,color:#fff
137
+ style SCHEMA fill:#1e3a5f,color:#fff
138
+ style RUNNER fill:#1e3a5f,color:#fff
139
+ style CLASSIC fill:#c9a84c,color:#000
140
+ style RETRIEVAL fill:#c9a84c,color:#000
141
+ style AGENTIC fill:#c9a84c,color:#000
142
+ style REPORT fill:#1e3a5f,color:#fff
143
+ style STORE fill:#1e3a5f,color:#fff
144
+ style API fill:#2d5a2d,color:#fff
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Metrics
150
+
151
+ ### Classic RAG Metrics
152
+
153
+ ```mermaid
154
+ graph LR
155
+ Q["question\ncontexts\nanswer"]
156
+
157
+ FAITH["faithfulness\nAre all claims in the\nanswer supported by context?"]
158
+ RELEV["answer_relevancy\nDoes the answer\naddress the question?"]
159
+ CPREC["context_precision\nAre retrieved chunks\nrelevant to the query?"]
160
+ CREC["context_recall\nDoes context contain\nenough to answer?"]
161
+
162
+ Q --> FAITH
163
+ Q --> RELEV
164
+ Q --> CPREC
165
+ Q --> CREC
166
+
167
+ style Q fill:#1e3a5f,color:#fff
168
+ style FAITH fill:#c9a84c,color:#000
169
+ style RELEV fill:#c9a84c,color:#000
170
+ style CPREC fill:#c9a84c,color:#000
171
+ style CREC fill:#c9a84c,color:#000
172
+ ```
173
+
174
+ | Metric | What it measures | LLM judge |
175
+ |---|---|---|
176
+ | `faithfulness` | Are all claims in the answer supported by context? | Yes |
177
+ | `answer_relevancy` | Does the answer address the question? | Yes |
178
+ | `context_precision` | Are retrieved chunks relevant to the query? | Yes |
179
+ | `context_recall` | Does context contain enough to answer correctly? | Yes |
180
+ | `precision_at_k` | Fraction of top-K retrieved docs that are relevant | No |
181
+ | `recall_at_k` | Fraction of relevant docs found in top-K | No |
182
+ | `mrr` | Reciprocal rank of first relevant doc | No |
183
+ | `ndcg_at_k` | Rank-weighted retrieval quality | No |
184
+
185
+ ### Agentic-Era Metrics
186
+
187
+ For multi-step agents, tool-using systems, and autonomous RAG pipelines:
188
+
189
+ | Metric | What it measures | LLM judge |
190
+ |---|---|---|
191
+ | `source_attribution_accuracy` | Did the agent cite sources it actually retrieved? | No — deterministic |
192
+ | `agent_faithfulness` | Is every reasoning step faithful to retrieved sources? | Yes |
193
+ | `tool_call_accuracy` | Did the agent choose the right tool at the right time? | Yes |
194
+ | `retrieval_necessity` | Was retrieval actually needed for this query? | Yes |
195
+
196
+ ### Metric Groups
197
+
198
+ ```python
199
+ # Use pre-defined groups
200
+ report = client.evaluate(samples, metric_group="classic")
201
+ report = client.evaluate(samples, metric_group="retrieval")
202
+ report = client.evaluate(samples, metric_group="agentic_v1")
203
+ report = client.evaluate(samples, metric_group="full") # all metrics
204
+ ```
205
+
206
+ ---
207
+
208
+ ## Benchmarks
209
+
210
+ Measured on the built-in 50-sample golden dataset (10 domains):
211
+
212
+ | Metric | Score | Label |
213
+ |---|---|---|
214
+ | faithfulness | **0.958** | Excellent |
215
+ | answer_relevancy | **0.810** | Good |
216
+
217
+ ---
218
+
219
+ ## LLM Backend
220
+
221
+ Several metrics use an LLM as a judge. Supported providers:
222
+
223
+ ```bash
224
+ # .env
225
+ LLM_PROVIDER=gemini # recommended
226
+ GEMINI_API_KEY=your-key
227
+
228
+ # Or OpenAI
229
+ LLM_PROVIDER=openai
230
+ OPENAI_API_KEY=your-key
231
+ ```
232
+
233
+ **Cost guidance:** A full classic-metrics pass on 50 samples costs ~$0.05–$0.15 with Gemini Flash or GPT-4o-mini. Source attribution accuracy is deterministic and costs nothing.
234
+
235
+ **Determinism:** Judge calls run at `temperature=0.0`. For CI/CD, flag changes beyond ±0.05 rather than asserting exact scores.
236
+
237
+ ---
238
+
239
+ ## API Reference
240
+
241
+ ```bash
242
+ # Evaluate a RAG sample
243
+ curl -X POST http://localhost:5001/v1/evaluate \
244
+ -H "X-API-Key: your-key" \
245
+ -H "Content-Type: application/json" \
246
+ -d '{
247
+ "samples": [{"question": "What is RAG?",
248
+ "contexts": ["RAG is Retrieval-Augmented Generation."],
249
+ "answer": "RAG combines retrieval with generation."}],
250
+ "metrics": ["faithfulness", "answer_relevancy"]
251
+ }'
252
+
253
+ # Evaluate an agentic trace
254
+ curl -X POST http://localhost:5001/v1/evaluate/agent \
255
+ -H "X-API-Key: your-key" \
256
+ -H "Content-Type: application/json" \
257
+ -d '{
258
+ "trace": {
259
+ "question": "What is the GPAI deadline?",
260
+ "final_answer": "GPAI obligations apply from August 2025.",
261
+ "tool_calls": [{"tool_name": "retrieve",
262
+ "tool_input": {"query": "GPAI deadline"},
263
+ "tool_output": "Article 53 obligations apply from August 2025.",
264
+ "step_index": 0}]
265
+ },
266
+ "metrics": ["source_attribution_accuracy", "tool_call_accuracy"]
267
+ }'
268
+
269
+ # Compare runs
270
+ curl -X POST http://localhost:5001/v1/runs/compare \
271
+ -H "X-API-Key: your-key" \
272
+ -d '["run-id-a", "run-id-b"]'
273
+ ```
274
+
275
+ ---
276
+
277
+ ## EU AI Act Article 15 — partial input, not conformity evidence
278
+
279
+ `rag-benchmarking` is an **evaluation harness** that measures **accuracy and faithfulness** for RAG and agentic systems. Those two metrics are *one* input among many that an Article 15 conformity assessment will draw on. They are **not** the conformity assessment itself, and the harness does **not** discharge an Article 15 obligation.
280
+
281
+ ```mermaid
282
+ graph LR
283
+ RAG["rag-benchmarking\nevaluation harness"]
284
+ FAITH2["Faithfulness measurement\n(LLM-judge)"]
285
+ ANS["Answer-relevancy + retrieval metrics\n(deterministic)"]
286
+ AGENT2["Agentic-trace metrics\n(tool_call_accuracy, source_attribution)"]
287
+ REPORT2["BenchmarkReport\n→ telemetry input for\nArticle 15(1) accuracy claims"]
288
+
289
+ RAG --> FAITH2 --> REPORT2
290
+ RAG --> ANS --> REPORT2
291
+ RAG --> AGENT2 --> REPORT2
292
+
293
+ style RAG fill:#c9a84c,color:#000
294
+ style REPORT2 fill:#2d5a2d,color:#fff
295
+ ```
296
+
297
+ ### What this tool covers, honestly
298
+
299
+ - **Article 15(1) — accuracy declared in instructions for use.** The harness produces faithfulness, answer-relevancy and retrieval-quality metrics that a provider can cite as the empirical basis for the accuracy figures they declare on the system label. The tool does not declare for you, and it does not certify the figures.
300
+
301
+ ### What this tool does NOT cover
302
+
303
+ - **Article 15 robustness in the regulatory sense.** Robustness under Art. 15 means resilience to errors, faults and inconsistencies — including adversarial-input resilience. This harness has no perturbation generator, no out-of-distribution detector, no adversarial-passage suite. **If a tool tells you it does Art. 15 robustness with a faithfulness scorer, it is overclaiming.**
304
+ - **Article 15 cybersecurity.** Adversarial prompt injection, jailbreak resistance, model-integrity controls. Out of scope. Pair with a runtime AI security control (e.g. AgentShield) for that leg.
305
+ - **Conformity assessment.** Article 15 requires a notified-body conformity assessment for high-risk systems. A benchmark report is not a substitute for that process.
306
+ - **Real-world testing under Art. 60.** The Art. 60 sandboxed-testing regime is a separate procedure with its own supervisory notifications. Out of scope.
307
+
308
+ > **Penalty band, contextually.** Art. 15 obligations route through the Art. 16 provider-obligation chain to **Art. 99(4)** — up to **€15M or 3% of total worldwide annual turnover, whichever is higher** ([EUR-Lex](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32024R1689)). This number is here for context, not as a sales hook. The compliance pathway is broader than this tool.
309
+
310
+ ---
311
+
312
+ ## AiExponent Toolchain
313
+
314
+ rag-benchmarking feeds accuracy evidence into RiskForge for Article 9 risk management:
315
+
316
+ ```mermaid
317
+ graph LR
318
+ LCC["LCC\n(Art. 53 licenses)"]
319
+ RAG["rag-benchmarking\n(Art. 15 accuracy)"]
320
+ RF["RiskForge\n(Art. 9 risk management)"]
321
+ TD["TransparencyDeck\n(Art. 13 docs)"]
322
+
323
+ LCC -->|"license evidence"| RF
324
+ RAG -->|"benchmark_report.json\naccuracy evidence"| RF
325
+ RF -->|"rmf.json"| TD
326
+
327
+ style RAG fill:#c9a84c,color:#000
328
+ style LCC fill:#1e3a5f,color:#fff
329
+ style RF fill:#1e3a5f,color:#fff
330
+ style TD fill:#1e3a5f,color:#fff
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Configuration
336
+
337
+ ```bash
338
+ # .env
339
+ LLM_PROVIDER=gemini
340
+ GEMINI_API_KEY=...
341
+ OPENAI_API_KEY=...
342
+
343
+ # Vector store (built-in RAG pipeline only)
344
+ QDRANT_URL=https://your-cluster.qdrant.io
345
+ QDRANT_API_KEY=...
346
+
347
+ # API authentication
348
+ API_KEY=your-secret-key
349
+ ENFORCE_API_KEY=true
350
+ ```
351
+
352
+ ---
353
+
354
+ ## Project Structure
355
+
356
+ ```
357
+ src/
358
+ harness/ # Framework-agnostic evaluation harness
359
+ schemas.py # EvalSample, AgentTrace, BenchmarkReport
360
+ protocol.py # RAGEvaluable Protocol — the plug-in contract
361
+ runner.py # EvaluationRunner — orchestrates metrics
362
+ result_store.py # SQLite persistence
363
+ app/
364
+ api/ # FastAPI endpoints
365
+ eval/ # Metric implementations
366
+ sdk/ # Python SDK (RagEval client)
367
+ data/
368
+ golden/qa.jsonl # 50-sample golden dataset (10 domains)
369
+ ```
370
+
371
+ ---
372
+
373
+ ## Known Limitations
374
+
375
+ - English-only benchmark datasets; no multilingual evaluation.
376
+ - Custom dataset integration requires manual formatting to the JSONL schema.
377
+ - Accuracy metrics only — latency and throughput are not measured.
378
+ - LLM-as-judge quality depends on the configured judge model.
379
+ - Rate limiting is in-memory and resets on server restart.
380
+
381
+ ---
382
+
383
+ ## Contributing
384
+
385
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Issues and PRs welcome.
386
+
387
+ ```bash
388
+ git clone https://github.com/aiexponenthq/rag-benchmarking
389
+ cd rag-benchmarking
390
+ pip install -e ".[test]"
391
+ pytest
392
+ ```
393
+
394
+ ---
395
+
396
+ ## License
397
+
398
+ [Apache 2.0](LICENSE) — free to use, modify, and distribute.
399
+
400
+ Built by [AI Exponent LLC](https://aiexponent.com) — `hello@aiexponent.com`
401
+
402
+ ---
403
+
404
+ *Part of the AiExponent open-source AI governance toolchain:
405
+ [license-compliance-checker](https://github.com/aiexponenthq/license-compliance-checker) ·
406
+ **rag-benchmarking** ·
407
+ [RiskForge](https://github.com/aiexponenthq/riskforge)*