ragarena 0.2.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.
ragarena-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RAGEval contributors
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,387 @@
1
+ Metadata-Version: 2.4
2
+ Name: ragarena
3
+ Version: 0.2.0
4
+ Summary: ⚡ Evaluate & benchmark RAG strategies, LLMs and embedding models across every popular provider — 18 strategies (incl. graph + multimodal), 100+ models, built-in dashboard.
5
+ Author: RagArena contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/sagar4ahirrao/ragarena
8
+ Project-URL: Repository, https://github.com/sagar4ahirrao/ragarena
9
+ Project-URL: Issues, https://github.com/sagar4ahirrao/ragarena/issues
10
+ Keywords: rag,retrieval,llm,evaluation,benchmark,ragas,embeddings,vector-search,ai,nlp
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: openai>=1.0.0
25
+ Requires-Dist: pydantic>=2.0.0
26
+ Requires-Dist: numpy>=1.24.0
27
+ Requires-Dist: fastapi>=0.104.0
28
+ Requires-Dist: uvicorn>=0.24.0
29
+ Requires-Dist: jinja2>=3.1.0
30
+ Requires-Dist: httpx>=0.24.0
31
+ Provides-Extra: retrieval
32
+ Requires-Dist: faiss-cpu>=1.7.4; extra == "retrieval"
33
+ Requires-Dist: rank-bm25>=0.2.2; extra == "retrieval"
34
+ Provides-Extra: local
35
+ Requires-Dist: sentence-transformers>=2.2.2; extra == "local"
36
+ Requires-Dist: torch>=2.1.0; extra == "local"
37
+ Provides-Extra: providers
38
+ Requires-Dist: anthropic>=0.30.0; extra == "providers"
39
+ Requires-Dist: cohere>=5.0.0; extra == "providers"
40
+ Requires-Dist: voyageai>=0.2.0; extra == "providers"
41
+ Requires-Dist: boto3>=1.34.0; extra == "providers"
42
+ Requires-Dist: google-generativeai>=0.5.0; extra == "providers"
43
+ Provides-Extra: all
44
+ Requires-Dist: ragarena[local,providers,retrieval]; extra == "all"
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest>=7.4; extra == "dev"
47
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
48
+ Requires-Dist: black>=24.0; extra == "dev"
49
+ Requires-Dist: ruff>=0.4; extra == "dev"
50
+ Requires-Dist: mypy>=1.8; extra == "dev"
51
+ Dynamic: license-file
52
+
53
+ <div align="center">
54
+
55
+ # ⚡ RagArena
56
+
57
+ ### Evaluate & benchmark every RAG strategy × LLM × embedding model — with one unified API
58
+
59
+ **18 strategies · 100+ models · 25+ providers · 10 metrics · built-in web dashboard**
60
+
61
+ [![PyPI](https://img.shields.io/pypi/v/ragarena?color=blue&logo=pypi)](https://pypi.org/project/ragarena/)
62
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue?logo=python)](https://www.python.org/)
63
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
64
+ [![Tests](https://img.shields.io/badge/tests-passing-brightgreen?logo=githubactions)]()
65
+
66
+ *One unified API across **every RAG strategy, LLM and embedding model**:*
67
+
68
+ ```python
69
+ from ragarena import evaluate
70
+
71
+ evaluate(questions=[...], documents=[...],
72
+ strategy="hybrid", # any of 18 strategies
73
+ model="openai/gpt-4o-mini", # swap with claude/gemini/llama/...
74
+ embedding_model="voyage/voyage-3", # swap with openai/cohere/jina/...
75
+ metrics="quality").print_summary()
76
+ ```
77
+
78
+ </div>
79
+
80
+ ---
81
+
82
+ ## Why RagArena?
83
+
84
+ Choosing a RAG stack is guesswork today. *"Is hybrid retrieval actually better than naive for
85
+ my data? Is GPT-4o worth 17× the price of GPT-4o-mini for answer faithfulness? Do Voyage-3
86
+ embeddings beat OpenAI's on my legal corpus?"*
87
+
88
+ **RagArena turns those guesses into a leaderboard.**
89
+
90
+ | | Ragas | DeepEval | TruLens | **RagArena** |
91
+ |---|---|---|---|---|
92
+ | Score *your existing* pipeline | ✅ | ✅ | ✅ | ✅ |
93
+ | **Run the pipelines themselves** (18 strategies) | ❌ | ❌ | ❌ | ✅ |
94
+ | **Swap LLM/embedding providers per run** (`provider/model` syntax) | partial | partial | partial | ✅ 100+ models |
95
+ | Built-in cost + latency accounting per strategy | ❌ | ❌ | partial | ✅ |
96
+ | Head-to-head leaderboard w/ shared index | ❌ | ❌ | ❌ | ✅ |
97
+ | Zero-config web dashboard | ❌ | ❌ | ❌ | ✅ |
98
+
99
+ ## Install
100
+
101
+ ```bash
102
+ pip install ragarena # core
103
+ pip install "ragarena[all]" # + all provider SDKs
104
+ export OPENAI_API_KEY=sk-... # only the providers you use
105
+ ```
106
+
107
+ ## 60-second quickstart
108
+
109
+ ```python
110
+ from ragarena import evaluate
111
+
112
+ docs = [
113
+ {"text": "Retrieval-Augmented Generation (RAG) grounds LLM answers in your documents."},
114
+ {"text": "Hybrid retrieval combines dense vector search with BM25 keyword search."},
115
+ {"text": "Cross-encoder rerankers like bge-reranker significantly improve precision."},
116
+ ]
117
+
118
+ report = evaluate(
119
+ questions=["What is RAG?", "How does hybrid retrieval work?"],
120
+ documents=docs,
121
+ reference_answers=["RAG grounds LLMs in docs", "It fuses dense + BM25 search"],
122
+ strategy="hybrid", # naive|hybrid|multi_query|hyde|rerank|
123
+ # rag_fusion|compression|crag|self_rag|
124
+ # decomposition|step_back|agentic|flare
125
+ model="openai/gpt-4o-mini",
126
+ embedding_model="openai/text-embedding-3-small",
127
+ metrics="quality", # quick|quality|full|production
128
+ )
129
+
130
+ report.print_summary()
131
+ report.save("report.json")
132
+ ```
133
+
134
+ ```
135
+ ╭─ RagArena · hybrid · openai/gpt-4o-mini
136
+ ├─ embedding : openai/text-embedding-3-small
137
+ ├─ samples : 2 wall time 6.4s
138
+ ├──────────────────────────────────────────────────────────
139
+ │ faithfulness : 0.92 answer relevance : 0.95
140
+ │ context precision : 0.83 context recall : 0.88
141
+ │ hit rate : 1.0 mrr : 0.75
142
+ │ avg latency : 3.1s total cost : $0.00214
143
+ ╰──────────────────────────────────────────────────────────
144
+ ```
145
+
146
+ ## 🏆 Find the best strategy/model in one call
147
+
148
+ ```python
149
+ from ragarena import compare
150
+
151
+ result = compare(
152
+ questions=my_questions,
153
+ documents=my_docs,
154
+ reference_answers=ground_truth,
155
+ configs=[
156
+ {"strategy": "naive", "model": "openai/gpt-4o-mini"},
157
+ {"strategy": "hybrid", "model": "openai/gpt-4o-mini"},
158
+ {"strategy": "hyde", "model": "openai/gpt-4o-mini"},
159
+ {"strategy": "agentic", "model": "groq/llama-3.1-70b-versatile"},
160
+ {"strategy": "hybrid", "model": "anthropic/claude-3-haiku-20240307"},
161
+ ],
162
+ )
163
+ result.print_leaderboard(sort_by="faithfulness")
164
+ print("WINNER:", result.best("faithfulness"))
165
+ ```
166
+
167
+ The document index is embedded **once** and shared across all configs — comparisons are fast and cheap.
168
+
169
+ ## 🖥 Web dashboard
170
+
171
+ ```bash
172
+ RagArena serve # → http://localhost:4000
173
+ ```
174
+
175
+ - **Overview** — run history & framework stats
176
+ - **New Evaluation** — pick strategy/models from dropdowns, paste corpus, score instantly
177
+ - **Compare** — build config matrices, get leaderboards + Chart.js visualizations
178
+ - **Runs** — drill into every sample: answer, chunks, metric reasoning
179
+ - **Catalog** — browse all 100+ models with pricing/context windows
180
+
181
+ ## 🔀 Every popular provider, one syntax
182
+
183
+ Models are addressed as `provider/name`:
184
+
185
+ ```python
186
+ from ragarena import completion
187
+
188
+ completion(model="openai/gpt-4o-mini", ...) # OpenAI
189
+ completion(model="anthropic/claude-3-5-sonnet-20240620", ...)
190
+ completion(model="google/gemini-1.5-flash", ...)
191
+ completion(model="deepseek/deepseek-chat", ...) # 97% cheaper than gpt-4o
192
+ completion(model="groq/llama-3.1-8b-instant", ...) # sub-second inference
193
+ completion(model="ollama/llama3.1", ...) # local & free
194
+ completion(model="bedrock/meta.llama3-1-405b-instruct-v1:0", ...)
195
+ ```
196
+
197
+ <details>
198
+ <summary><b>📋 Full provider support matrix (click to expand)</b></summary>
199
+
200
+ **LLM Providers** — `provider/` prefix:
201
+
202
+ | Provider | Example models | Notes |
203
+ |---|---|---|
204
+ | `openai/` | gpt-4o, gpt-4o-mini, o1-preview | flagship quality |
205
+ | `anthropic/` | claude-3-5-sonnet, opus, haiku | best coding/agentic |
206
+ | `google/`, `vertex/` | gemini-1.5-pro (2M ctx), flash | huge context |
207
+ | `azure/` | any OpenAI model on Azure | enterprise compliance |
208
+ | `bedrock/` | claude/llama/titan on AWS | VPC deployments |
209
+ | `cohere/` | command-r-plus | native RAG features |
210
+ | `mistral/` | large, nemo, codestral | EU-hosted options |
211
+ | `xai/` | grok-beta | real-time knowledge |
212
+ | `deepseek/` | deepseek-chat, coder | extreme $/quality |
213
+ | `groq/` | llama-3.1-70b @300tok/s | fastest hosted |
214
+ | `together/`, `fireworks/`, `deepinfra/` | llama, qwen, mixtral | open-model hosts |
215
+ | `perplexity/` | sonar-online | search-grounded |
216
+ | `openrouter/` | 100+ gateway models | one key, all models |
217
+ | `nvidia_nim/`, `anyscale/`, `ai21/`, `databricks/` | … | … |
218
+ | `ollama/`, `vllm/`, `lmstudio/` | local llama/qwen/gemma/phi | free, private |
219
+
220
+ **Embedding Providers:**
221
+ `openai/text-embedding-3-*` · `cohere/embed-*` · `voyage/voyage-3(-large|-code|-law|-finance)` ·
222
+ `jina/jina-embeddings-v3` · `mistral/mistral-embed` · `google/text-embedding-004` ·
223
+ `bedrock/amazon.titan-embed-text-v2` · `huggingface/BAAI/bge-m3` (+MiniLM, E5, GTE) · `ollama/nomic-embed-text`
224
+
225
+ **Rerankers:** `cohere/rerank-v3.5` · `voyage/rerank-2` · `huggingface/BAAI/bge-reranker-v2-m3`
226
+
227
+ **Vector stores:** FAISS (built-in) · Chroma · Pinecone · Qdrant · Weaviate · Milvus · LanceDB · pgvector · Elasticsearch · Redis · OpenSearch · MongoDB
228
+
229
+ </details>
230
+
231
+ Browse everything from the CLI:
232
+
233
+ ```bash
234
+ RagArena models list # all 100+
235
+ RagArena models list --modality embedding # embeddings only
236
+ RagArena models providers # provider summary
237
+ RagArena strategies # the 18 strategies
238
+ ```
239
+
240
+ ## 🧪 The 18 built-in strategies
241
+
242
+ | Strategy | What it does | Best for |
243
+ |---|---|---|
244
+ | `naive` | dense top-k → generate | baseline / simple corpora |
245
+ | `hybrid` | dense + BM25 weighted fusion (α-tunable) | keyword-heavy domains |
246
+ | `multi_query` | LLM rewrites N queries, merges results | vague questions |
247
+ | `rag_fusion` | multi-query + Reciprocal Rank Fusion | robustness over multi_query |
248
+ | `hyde` | retrieve using an imagined answer's embedding | vocabulary mismatch |
249
+ | `rerank` | wide recall → cross-encoder refine | precision-critical |
250
+ | `compression` | LLM strips irrelevant spans pre-generation | long noisy chunks |
251
+ | `crag` | grades retrieval; rewrites query if weak | production guardrails |
252
+ | `self_rag` | model decides *if* retrieval is needed | mixed easy/hard traffic |
253
+ | `decomposition` | splits complex Q → sub-Qs → synthesis | multi-hop questions |
254
+ | `step_back` | abstract principle question first | conceptual/domain Qs |
255
+ | `agentic` | iterative search→reflect→search loop | hard research tasks |
256
+ | `flare` | flags uncertain draft claims → re-retrieves | hallucination-prone domains |
257
+ | `graph_local` | entity-precise retrieval over a knowledge graph | "who/what" factual lookups |
258
+ | `graph_global` | macro-theme retrieval across entity communities | "how/why" analytical Qs |
259
+ | `graph_hybrid` | combines local entities + global themes | general-purpose graph RAG |
260
+ | `graph_mix` | local + global fused in one synthesis pass | best-of-both retrieval |
261
+ | `multimodal` | retrieves typed chunks (text/table/image/equation) | mixed-content documents |
262
+
263
+ ## 🕸️ Graph RAG (dual-level retrieval)
264
+
265
+ `graph_*` strategies layer a lightweight knowledge graph over your index — entities
266
+ are extracted per chunk, chunks that share entities form *communities*, and queries
267
+ are answered at two levels:
268
+
269
+ - **local** (`graph_local`) — match the query's entities to graph nodes and pull the
270
+ connected chunks. Best for precise "who/what" factual lookups.
271
+ - **global** (`graph_global`) — summarise each community, rank communities by relevance
272
+ to the query, then synthesise a cross-document answer. Best for "how/why" analysis.
273
+ - **hybrid** / **mix** (`graph_hybrid`, `graph_mix`) — combine both levels.
274
+
275
+ The graph is built lazily and cached on a shared index, so `compare()` only builds it
276
+ once. Entity extraction falls back to a deterministic keyword extractor if the LLM is
277
+ unavailable.
278
+
279
+ ```python
280
+ from ragarena import compare
281
+
282
+ result = compare(
283
+ questions=["Who builds Pinecone?", "How do retrieval systems relate?"],
284
+ documents=my_docs,
285
+ configs=[
286
+ {"strategy": "graph_local", "model": "openai/gpt-4o-mini"},
287
+ {"strategy": "graph_global", "model": "openai/gpt-4o-mini"},
288
+ {"strategy": "graph_hybrid", "model": "anthropic/claude-3-haiku-20240307"},
289
+ ],
290
+ )
291
+ ```
292
+
293
+ Build a graph index directly for inspection:
294
+
295
+ ```python
296
+ from ragarena import VectorIndex, GraphIndex
297
+
298
+ vi = VectorIndex(embedding_model="openai/text-embedding-3-small")
299
+ vi.add_documents(my_docs)
300
+ g = GraphIndex(vi).build("openai/gpt-4o-mini") # cache on the index
301
+ local = g.local_search("What is Pinecone?", k=5, llm_model="openai/gpt-4o-mini")
302
+ chunks, theme = g.global_search("How do vector DBs compare?", k=5, llm_model="openai/gpt-4o-mini")
303
+ ```
304
+
305
+ ## 🖼️ Multimodal RAG
306
+
307
+ Tables, images and equations are kept **intact** (not sentence-split) and tagged with a
308
+ `doc_type` so retrieval and generation can treat them differently:
309
+
310
+ ```python
311
+ from ragarena import MultimodalDocument, evaluate
312
+
313
+ docs = [
314
+ MultimodalDocument(content="| model | params |", doc_type="table"),
315
+ MultimodalDocument(content="E = mc^2", doc_type="equation"),
316
+ {"text": "RAG grounds LLMs in retrieved context.", "metadata": {"doc_type": "text"}},
317
+ ]
318
+ evaluate(questions=["..."], documents=docs, strategy="multimodal",
319
+ model="openai/gpt-4o-mini")
320
+ ```
321
+
322
+ ## 📐 Metrics
323
+
324
+ Presets: `quick` · `quality` · `full` · `production` — or cherry-pick:
325
+
326
+ ```python
327
+ metrics=["context_precision", "context_recall", "hit_rate", "mrr", # retrieval
328
+ "faithfulness", "answer_relevance", "answer_correctness", # generation (LLM-judge)
329
+ "latency_s", "cost_usd", "total_tokens"] # operational
330
+ ```
331
+
332
+ Any model can be the judge: `judge_model="anthropic/claude-3-haiku-20240307"`.
333
+
334
+ ## 📦 Use inside your existing pipeline
335
+
336
+ Already have a RAG system? Score it directly:
337
+
338
+ ```python
339
+ from ragarena import VectorIndex
340
+ from ragarena.engine import EvalSample, MetricContext
341
+ from ragarena.metrics import resolve_metrics
342
+
343
+ # ...run YOUR pipeline to get answer + chunks...
344
+ sample = EvalSample(question=q, reference_answer=gt,
345
+ generated_answer=your_answer,
346
+ retrieved_chunks=[{"text": c} for c in your_chunks],
347
+ context="...", usage={...}, latency_s=..., intermediate={})
348
+ for m in resolve_metrics("full"):
349
+ print(m.name, m.compute(sample, MetricContext(judge_model="openai/gpt-4o-mini")).score)
350
+ ```
351
+
352
+ ## HTTP API
353
+
354
+ ```bash
355
+ curl -X POST localhost:4000/api/evaluate -H 'Content-Type: application/json' -d '{
356
+ "questions": ["What is RAG?"],
357
+ "documents": [{"text": "RAG grounds LLM answers in documents."}],
358
+ "strategy": "hybrid",
359
+ "model": "openai/gpt-4o-mini",
360
+ "embedding_model": "voyage/voyage-3"
361
+ }'
362
+ ```
363
+
364
+ Also available: `POST /api/compare` · `GET /api/catalog` · `GET /api/runs/{id}` · `GET /health`
365
+
366
+ ## Roadmap
367
+
368
+ - [ ] Async batch runner + checkpoint/resume
369
+ - [ ] Statistical significance tests (paired bootstrap) between configs
370
+ - [ ] Chroma/Pinecone/Qdrant backends for `VectorIndex`
371
+ - [ ] Graph RAG incremental updates + community-aware re-indexing
372
+ - [ ] Multimodal parsing (PDF/images via MinerU) feeding `MultimodalDocument`
373
+ - [ ] Prompt-optimization loop (DSPy-style)
374
+ - [ ] Team features: API keys, budgets, RBAC
375
+ - [ ] CI mode: `ragarena ci --threshold faithfulness>=0.8` (fails PRs on regressions)
376
+
377
+ ## Contributing
378
+
379
+ PRs welcome! `pip install -e ".[dev]" && pytest`. Please read `CONTRIBUTING.md`.
380
+
381
+ ## License
382
+
383
+ MIT © RagArena contributors
384
+
385
+ <div align="center">
386
+ <sub>Built for developers tired of guessing. Star ⭐ if it saved you a benchmark week.</sub>
387
+ </div>