rag-benchmarking 1.0.0rc1__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. rag_benchmarking-1.0.0rc1/LICENSE +192 -0
  2. rag_benchmarking-1.0.0rc1/PKG-INFO +386 -0
  3. rag_benchmarking-1.0.0rc1/README.md +343 -0
  4. rag_benchmarking-1.0.0rc1/pyproject.toml +104 -0
  5. rag_benchmarking-1.0.0rc1/setup.cfg +4 -0
  6. rag_benchmarking-1.0.0rc1/src/app/__init__.py +5 -0
  7. rag_benchmarking-1.0.0rc1/src/app/api/evaluate.py +170 -0
  8. rag_benchmarking-1.0.0rc1/src/app/api/query.py +72 -0
  9. rag_benchmarking-1.0.0rc1/src/app/api/security.py +23 -0
  10. rag_benchmarking-1.0.0rc1/src/app/config/__init__.py +1 -0
  11. rag_benchmarking-1.0.0rc1/src/app/config/settings.py +74 -0
  12. rag_benchmarking-1.0.0rc1/src/app/engine/__init__.py +0 -0
  13. rag_benchmarking-1.0.0rc1/src/app/engine/rag_engine.py +189 -0
  14. rag_benchmarking-1.0.0rc1/src/app/eval/agentic_llm_metrics.py +151 -0
  15. rag_benchmarking-1.0.0rc1/src/app/eval/agentic_metrics.py +45 -0
  16. rag_benchmarking-1.0.0rc1/src/app/eval/faithfulness.py +79 -0
  17. rag_benchmarking-1.0.0rc1/src/app/eval/ragas_runner.py +204 -0
  18. rag_benchmarking-1.0.0rc1/src/app/eval/reporting.py +30 -0
  19. rag_benchmarking-1.0.0rc1/src/app/eval/result_store.py +269 -0
  20. rag_benchmarking-1.0.0rc1/src/app/eval/retrieval_metrics.py +42 -0
  21. rag_benchmarking-1.0.0rc1/src/app/exceptions.py +22 -0
  22. rag_benchmarking-1.0.0rc1/src/app/llm/client.py +175 -0
  23. rag_benchmarking-1.0.0rc1/src/app/logging/__init__.py +1 -0
  24. rag_benchmarking-1.0.0rc1/src/app/logging/json_logger.py +53 -0
  25. rag_benchmarking-1.0.0rc1/src/app/main.py +89 -0
  26. rag_benchmarking-1.0.0rc1/src/app/quality/self_check.py +13 -0
  27. rag_benchmarking-1.0.0rc1/src/app/retrieval/chunking.py +49 -0
  28. rag_benchmarking-1.0.0rc1/src/app/retrieval/embeddings.py +20 -0
  29. rag_benchmarking-1.0.0rc1/src/app/retrieval/ingest_cli.py +75 -0
  30. rag_benchmarking-1.0.0rc1/src/app/retrieval/qdrant_store.py +155 -0
  31. rag_benchmarking-1.0.0rc1/src/app/retrieval/reranker.py +25 -0
  32. rag_benchmarking-1.0.0rc1/src/app/retrieval/service.py +55 -0
  33. rag_benchmarking-1.0.0rc1/src/app/sdk/__init__.py +0 -0
  34. rag_benchmarking-1.0.0rc1/src/app/sdk/client.py +192 -0
  35. rag_benchmarking-1.0.0rc1/src/app/utils/timing.py +17 -0
  36. rag_benchmarking-1.0.0rc1/src/harness/__init__.py +25 -0
  37. rag_benchmarking-1.0.0rc1/src/harness/protocol.py +68 -0
  38. rag_benchmarking-1.0.0rc1/src/harness/result_store.py +101 -0
  39. rag_benchmarking-1.0.0rc1/src/harness/runner.py +154 -0
  40. rag_benchmarking-1.0.0rc1/src/harness/schemas.py +132 -0
  41. rag_benchmarking-1.0.0rc1/src/rag_benchmarking.egg-info/PKG-INFO +386 -0
  42. rag_benchmarking-1.0.0rc1/src/rag_benchmarking.egg-info/SOURCES.txt +52 -0
  43. rag_benchmarking-1.0.0rc1/src/rag_benchmarking.egg-info/dependency_links.txt +1 -0
  44. rag_benchmarking-1.0.0rc1/src/rag_benchmarking.egg-info/requires.txt +19 -0
  45. rag_benchmarking-1.0.0rc1/src/rag_benchmarking.egg-info/top_level.txt +2 -0
  46. rag_benchmarking-1.0.0rc1/tests/test_chunking.py +12 -0
  47. rag_benchmarking-1.0.0rc1/tests/test_config_and_logging.py +18 -0
  48. rag_benchmarking-1.0.0rc1/tests/test_embeddings.py +14 -0
  49. rag_benchmarking-1.0.0rc1/tests/test_eval_pipeline.py +459 -0
  50. rag_benchmarking-1.0.0rc1/tests/test_evaluate_api.py +39 -0
  51. rag_benchmarking-1.0.0rc1/tests/test_health.py +18 -0
  52. rag_benchmarking-1.0.0rc1/tests/test_query_api.py +44 -0
  53. rag_benchmarking-1.0.0rc1/tests/test_rerank_integration.py +44 -0
  54. rag_benchmarking-1.0.0rc1/tests/test_security.py +58 -0
@@ -0,0 +1,192 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Ajay Pundhir
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
191
+
192
+
@@ -0,0 +1,386 @@
1
+ Metadata-Version: 2.4
2
+ Name: rag-benchmarking
3
+ Version: 1.0.0rc1
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 :: 4 - Beta
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
+ Requires-Dist: fastapi>=0.110
25
+ Requires-Dist: uvicorn>=0.30
26
+ Requires-Dist: pydantic>=2.6
27
+ Requires-Dist: pydantic-settings>=2.2
28
+ Requires-Dist: python-json-logger>=2.0.7
29
+ Requires-Dist: qdrant-client>=1.9
30
+ Requires-Dist: sentence-transformers>=3.0
31
+ Requires-Dist: numpy>=1.26
32
+ Requires-Dist: tqdm>=4.66
33
+ Requires-Dist: requests>=2.31
34
+ Requires-Dist: ragas>=0.1.9
35
+ Requires-Dist: langchain-google-genai>=2.0.9
36
+ Requires-Dist: FlagEmbedding>=1.2.11
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest>=8.2; extra == "test"
39
+ Requires-Dist: pytest-asyncio>=0.23; extra == "test"
40
+ Requires-Dist: pytest-cov>=5.0; extra == "test"
41
+ Requires-Dist: httpx>=0.27; extra == "test"
42
+ Dynamic: license-file
43
+
44
+ # RAG Benchmarking
45
+
46
+ ![Python](https://img.shields.io/badge/python-3.11+-blue.svg)
47
+ ![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)
48
+ ![Status](https://img.shields.io/badge/status-v1.0.0--rc1-orange.svg)
49
+ ![EU AI Act](https://img.shields.io/badge/EU%20AI%20Act-Article%2015-gold.svg)
50
+ [![PyPI](https://img.shields.io/pypi/v/rag-benchmarking.svg)](https://pypi.org/project/rag-benchmarking/)
51
+
52
+ **A framework-agnostic evaluation harness for RAG and agentic AI systems.**
53
+
54
+ Bring your own RAG pipeline — LangChain, LlamaIndex, or custom — and benchmark it against standard classic and agentic-era metrics. Built for teams who need to prove their AI systems work before they ship, not hope they do.
55
+
56
+ > Part of the [AiExponent](https://aiexponent.com) open source portfolio. Maps to EU AI Act Article 15 (accuracy requirements).
57
+
58
+ ---
59
+
60
+ ## Quick Start
61
+
62
+ ### Install
63
+
64
+ ```bash
65
+ # Install from PyPI (recommended)
66
+ pip install rag-benchmarking
67
+
68
+ # Or install from source
69
+ git clone https://github.com/aiexponenthq/rag-benchmarking.git
70
+ cd rag-benchmarking
71
+ pip install -e ".[test]"
72
+ ```
73
+
74
+ ### Evaluate your existing RAG system in 5 minutes
75
+
76
+ ```python
77
+ from app.sdk.client import RagEval
78
+
79
+ client = RagEval(api_url="http://localhost:5001", api_key="your-key")
80
+
81
+ # LangChain integration
82
+ from langchain.chains import RetrievalQA
83
+ chain = RetrievalQA.from_chain_type(...)
84
+ result = chain.invoke({"query": "What is RAG?"})
85
+ sample = RagEval.from_langchain(result)
86
+
87
+ # LlamaIndex integration
88
+ engine = index.as_query_engine()
89
+ response = engine.query("What is RAG?")
90
+ sample = RagEval.from_llamaindex(response, "What is RAG?")
91
+
92
+ # Or any dict with question / contexts / answer
93
+ sample = {
94
+ "question": "What is RAG?",
95
+ "contexts": ["RAG stands for Retrieval-Augmented Generation."],
96
+ "answer": "RAG combines retrieval with LLM generation.",
97
+ }
98
+
99
+ report = client.evaluate([sample], metrics=["faithfulness", "answer_relevancy"])
100
+ print(report["scores"])
101
+ # {"faithfulness": 0.92, "answer_relevancy": 0.88}
102
+ ```
103
+
104
+ ### Start the evaluation server
105
+
106
+ ```bash
107
+ # With Docker Compose
108
+ docker compose up
109
+
110
+ # Or directly
111
+ uvicorn app.main:app --port 5001
112
+ ```
113
+
114
+ ### Interactive API docs
115
+
116
+ Once the server is running, the full OpenAPI reference is available at:
117
+
118
+ ```
119
+ http://localhost:5001/docs
120
+ ```
121
+
122
+ ---
123
+
124
+ ## LLM Backend for Evaluation
125
+
126
+ Several metrics (faithfulness, context_precision, context_recall, agent_faithfulness, tool_call_accuracy, retrieval_necessity) use an LLM as a judge. The harness supports **Gemini** (recommended) and **OpenAI**.
127
+
128
+ ```bash
129
+ # Set in .env:
130
+ LLM_PROVIDER=gemini
131
+ GEMINI_API_KEY=your-gemini-key
132
+
133
+ # Or OpenAI:
134
+ LLM_PROVIDER=openai
135
+ OPENAI_API_KEY=your-openai-key
136
+ ```
137
+
138
+ **Determinism:** Judge calls run at `temperature=0.0` to minimise variance across evaluation runs. For CI/CD integration, run evaluations at least twice and flag changes beyond a ±0.05 threshold rather than asserting exact scores.
139
+
140
+ **Cost guidance:** A full evaluation pass (all classic metrics) on 50 samples costs approximately $0.05–$0.15 with Gemini Flash or GPT-4o-mini. Source attribution accuracy is deterministic and costs nothing.
141
+
142
+ ---
143
+
144
+ ## Metrics
145
+
146
+ ### Classic RAG Metrics
147
+
148
+ | Metric | What it measures | Requires |
149
+ |---|---|---|
150
+ | `faithfulness` | Are all claims in the answer supported by context? | question, contexts, answer |
151
+ | `answer_relevancy` | Does the answer address the question? | question, answer |
152
+ | `context_precision` | Are retrieved chunks relevant to the query? | + ground_truth |
153
+ | `context_recall` | Does context contain enough to answer correctly? | + ground_truth |
154
+ | `precision_at_k` | Fraction of top-K retrieved docs that are relevant | + retrieved_doc_ids, relevant_doc_ids |
155
+ | `recall_at_k` | Fraction of relevant docs found in top-K | + retrieved_doc_ids, relevant_doc_ids |
156
+ | `mrr` | Reciprocal rank of first relevant doc | + retrieved_doc_ids, relevant_doc_ids |
157
+ | `ndcg_at_k` | Rank-weighted retrieval quality | + retrieved_doc_ids, relevant_doc_ids |
158
+
159
+ ### Agentic-Era Metrics
160
+
161
+ For multi-step agents, tool-using systems, and autonomous RAG pipelines:
162
+
163
+ | Metric | What it measures | LLM needed? |
164
+ |---|---|---|
165
+ | `source_attribution_accuracy` | Did the agent cite sources it actually retrieved? | No (deterministic) |
166
+ | `agent_faithfulness` | Is every reasoning step faithful to retrieved sources? | Yes |
167
+ | `tool_call_accuracy` | Did the agent choose the right tool at the right time? | Yes |
168
+ | `retrieval_necessity` | Was retrieval actually needed for this query? | Yes |
169
+
170
+ ### Metric Groups
171
+
172
+ | Group | Metrics included |
173
+ |---|---|
174
+ | `classic` | faithfulness, answer_relevancy |
175
+ | `retrieval` | precision_at_k, recall_at_k, mrr, ndcg_at_k |
176
+ | `agentic_v1` | source_attribution_accuracy, retrieval_necessity, agent_faithfulness, tool_call_accuracy |
177
+ | `agentic_v2` | multihop_faithfulness, agent_trajectory_efficiency, reasoning_hallucination, context_coherence_across_turns |
178
+ | `full` | all classic + retrieval + agentic_v1 metrics |
179
+
180
+ ```python
181
+ # Use a pre-defined group instead of listing metrics individually
182
+ report = client.evaluate(samples, metric_group="classic")
183
+ ```
184
+
185
+ ---
186
+
187
+ ## API Reference
188
+
189
+ ### REST API
190
+
191
+ ```bash
192
+ # Classic RAG evaluation
193
+ curl -X POST http://localhost:5001/v1/evaluate \
194
+ -H "X-API-Key: your-key" \
195
+ -H "Content-Type: application/json" \
196
+ -d '{
197
+ "samples": [{
198
+ "question": "What is RAG?",
199
+ "contexts": ["RAG is Retrieval-Augmented Generation."],
200
+ "answer": "RAG combines retrieval with LLM generation."
201
+ }],
202
+ "metrics": ["faithfulness", "answer_relevancy"]
203
+ }'
204
+
205
+ # Agentic trace evaluation
206
+ curl -X POST http://localhost:5001/v1/evaluate/agent \
207
+ -H "X-API-Key: your-key" \
208
+ -H "Content-Type: application/json" \
209
+ -d '{
210
+ "trace": {
211
+ "question": "What is the GPAI deadline?",
212
+ "final_answer": "GPAI obligations apply from August 2025.",
213
+ "tool_calls": [{
214
+ "tool_name": "retrieve",
215
+ "tool_input": {"query": "GPAI deadline"},
216
+ "tool_output": "Article 53 obligations apply from August 2025.",
217
+ "step_index": 0
218
+ }]
219
+ },
220
+ "metrics": ["source_attribution_accuracy", "tool_call_accuracy"]
221
+ }'
222
+
223
+ # List and compare runs
224
+ curl http://localhost:5001/v1/runs -H "X-API-Key: your-key"
225
+ curl -X POST http://localhost:5001/v1/runs/compare \
226
+ -H "X-API-Key: your-key" \
227
+ -d '["run-id-a", "run-id-b"]'
228
+ ```
229
+
230
+ ### Python SDK
231
+
232
+ ```python
233
+ from app.sdk.client import RagEval
234
+
235
+ client = RagEval(api_url="http://localhost:5001", api_key="your-key")
236
+
237
+ # Classic evaluation
238
+ report = client.evaluate(samples, metrics=["faithfulness"])
239
+ report = client.evaluate(samples, metric_group="agentic_v1")
240
+
241
+ # Agentic trace
242
+ report = client.evaluate_agent(trace_dict, metrics=["agent_faithfulness"])
243
+
244
+ # Run history and comparison
245
+ runs = client.list_runs()
246
+ comparison = client.compare_runs(["run-a", "run-b"])
247
+ ```
248
+
249
+ ---
250
+
251
+ ## Architecture
252
+
253
+ ```mermaid
254
+ flowchart TD
255
+ A["Your RAG System\n(LangChain / LlamaIndex / Custom)"]
256
+ B["SDK Adapters\nRagEval.from_langchain()\nRagEval.from_llamaindex()"]
257
+ C["EvalSample / AgentTrace\nharness/schemas.py"]
258
+ D["EvaluationRunner\nharness/runner.py"]
259
+ E["RAGAS Metrics\nfaithfulness · answer_relevancy\ncontext_precision · context_recall"]
260
+ F["Retrieval Metrics\nPrecision@K · Recall@K · MRR · NDCG"]
261
+ G["Agentic Metrics\nagent_faithfulness · tool_call_accuracy\nretrieval_necessity · source_attribution"]
262
+ H["BenchmarkReport"]
263
+ I["SQLite ResultStore\nharness/result_store.py"]
264
+ J["REST API\n/v1/evaluate · /v1/evaluate/agent\n/v1/runs · /v1/runs/compare"]
265
+
266
+ A --> B --> C --> D
267
+ D --> E
268
+ D --> F
269
+ D --> G
270
+ E --> H
271
+ F --> H
272
+ G --> H
273
+ H --> I --> J
274
+ ```
275
+
276
+ ### Plug-in contract
277
+
278
+ Any RAG system implements one method to integrate:
279
+
280
+ ```python
281
+ class MyRAG:
282
+ def run(self, question: str, contexts_override=None) -> dict:
283
+ result = self.chain.invoke({"query": question})
284
+ return {
285
+ "answer": result["result"],
286
+ "contexts": [d.page_content for d in result["source_documents"]],
287
+ "retrieved_doc_ids": [d.metadata.get("id") for d in result["source_documents"]],
288
+ }
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Configuration
294
+
295
+ Copy `.env.example` to `.env` and set:
296
+
297
+ ```bash
298
+ # LLM provider for faithfulness judge
299
+ LLM_PROVIDER=gemini # or openai
300
+ GEMINI_API_KEY=...
301
+ OPENAI_API_KEY=...
302
+
303
+ # Vector store (built-in RAG pipeline only)
304
+ QDRANT_URL=https://your-cluster.qdrant.io
305
+ QDRANT_API_KEY=...
306
+
307
+ # API authentication
308
+ API_KEY=your-secret-key
309
+ ENFORCE_API_KEY=true
310
+ ```
311
+
312
+ ---
313
+
314
+ ## Project Structure
315
+
316
+ ```
317
+ src/
318
+ harness/ # Framework-agnostic evaluation harness
319
+ schemas.py # EvalSample, AgentTrace, BenchmarkReport, RunConfig
320
+ protocol.py # RAGEvaluable Protocol — the plug-in contract
321
+ runner.py # EvaluationRunner — orchestrates metrics
322
+ result_store.py # SQLite persistence for BenchmarkReport
323
+ app/
324
+ api/ # FastAPI endpoints
325
+ eval/
326
+ ragas_runner.py # RAGAS classic metrics
327
+ retrieval_metrics.py # Precision@K, Recall@K, MRR, NDCG
328
+ faithfulness.py # Claim-decomposition faithfulness (LLM-as-judge)
329
+ agentic_metrics.py # source_attribution_accuracy (deterministic)
330
+ agentic_llm_metrics.py # LLM-as-judge agentic metrics
331
+ sdk/ # Python SDK (RagEval client)
332
+ engine/ # Built-in RAG pipeline (optional)
333
+
334
+ data/
335
+ golden/qa.jsonl # 50-sample golden dataset (10 domains)
336
+
337
+ tests/
338
+ unit/ # Unit tests (no LLM, no network)
339
+ integration/ # SDK integration tests
340
+ e2e/ # Full API endpoint tests
341
+ ```
342
+
343
+ ---
344
+
345
+ ## EU AI Act Context
346
+
347
+ Maps to **Article 15** — Accuracy, Robustness and Cybersecurity for High-Risk AI Systems. Systematic RAG evaluation implements the technical testing requirements for demonstrating accuracy under Article 15.
348
+
349
+ ---
350
+
351
+ ## Known Limitations
352
+
353
+ - Benchmark datasets are English-only; no multilingual evaluation support.
354
+ - Custom dataset integration requires manual formatting to the JSONL schema.
355
+ - Accuracy metrics only — latency and throughput are not measured.
356
+ - LLM-as-judge metrics depend on the quality of the configured judge model.
357
+ - Rate limiting is in-memory and resets on server restart.
358
+
359
+ ---
360
+
361
+ ## Version Compatibility
362
+
363
+ | Dependency | Tested version |
364
+ |---|---|
365
+ | Python | 3.11, 3.12 |
366
+ | RAGAS | 0.4.x |
367
+ | LangChain | ≥ 0.1 |
368
+ | LlamaIndex | ≥ 0.10 |
369
+ | FastAPI | ≥ 0.110 |
370
+
371
+ ---
372
+
373
+ ## Further Reading
374
+
375
+ - [DEPLOYMENT.md](DEPLOYMENT.md) — Docker, Kubernetes, security configuration
376
+ - [CONTRIBUTING.md](CONTRIBUTING.md) — how to contribute, commit conventions, test guidelines
377
+ - [SECURITY.md](SECURITY.md) — vulnerability reporting policy
378
+ - [CHANGELOG.md](CHANGELOG.md) — version history
379
+
380
+ ---
381
+
382
+ ## Contributing
383
+
384
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Apache 2.0 licensed.
385
+
386
+ Built by [AiExponent](https://aiexponent.com) — Building AI that deserves to be trusted.