Skip to main content

rag-lens

An open-source, pip-installable Python library for quantitatively evaluating RAG pipelines using LLM-as-a-Judge.

"I don't just build RAG systems — I built the tool that measures whether RAG systems work."

CI PyPI version Python 3.11+ License: MIT


Why This Exists

RAG systems are easy to prototype and hard to trust. Most teams evaluate them by manually reading a handful of outputs and eyeballing whether the answers "look right." This breaks down at scale, doesn't catch regressions, and can't tell you why a pipeline underperforms.

RAG-Eval Framework replaces vibes-based evaluation with a scored, reproducible pipeline that separates retrieval quality from generation quality.


Quickstart

pip install ram-rag-lens
cp .env.example .env  # Add your GROQ_API_KEY
from rag_lens.evaluators import Faithfulness, AnswerRelevance
from rag_lens.judge import GroqJudge
from rag_lens.ingestion import QAItem, RAGOutput

judge = GroqJudge()

output = RAGOutput(
    item_id="test_001",
    question="What is RAG?",
    retrieved_context=["RAG combines retrieval with generation to reduce hallucinations."],
    generated_answer="RAG is a technique that retrieves documents before generating an answer.",
)

score = Faithfulness(judge=judge).score(output)
print(score.score)      # → 0.95
print(score.rationale)  # → "The answer is fully grounded in the retrieved context."

The 4 Metrics

Metric What it measures
Faithfulness Are all claims in the answer grounded in the retrieved context? (anti-hallucination)
Answer Relevance Does the answer directly address the question?
Context Precision Of the retrieved chunks, what fraction were actually relevant? (signal-to-noise)
Context Recall Did retrieval surface the information needed to answer the question?

All scores in [0.0, 1.0]. All scored by an LLM judge (Llama-3 via Groq).


CLI Usage

# Evaluate a single RAG output log
rag-lens evaluate --dataset data/qa_dataset.json --outputs my_rag_outputs.jsonl

# Run the full 18-configuration benchmark sweep
rag-lens benchmark --matrix data/configs/benchmark_matrix.yaml

# Regenerate leaderboard + charts from existing results (no API calls)
rag-lens report --results results/raw/

18-Configuration Benchmark

The framework ships a benchmark that tests 18 RAG configurations against a 100-question dataset:

Dimension Options
Chunking Sentence / Paragraph / Semantic
Embedding ada-002 (OpenAI) / BGE-large (local) / E5-large (local)
Retrieval Dense (ChromaDB) / Hybrid (Dense + BM25 via RRF)

Run it:

python benchmarks/run_18_config_benchmark.py

Judge Validation

LLM-as-a-judge scores are estimates, not ground truth. Before trusting benchmark conclusions, we validate the judge against human labels on a 20–30 item subset. See docs/qa-testing.md §4 for the methodology. Agreement rates are documented honestly — not hidden.

⚠️ Data notice: This tool sends dataset and RAG output text to the Groq API to power the judge. Do not use with sensitive or confidential data.


Project Structure

See docs/project-structure.md for a full annotated layout.

src/rag_lens/
├── judge/        → BaseJudge + GroqJudge (swappable LLM backend)
├── evaluators/   → Faithfulness, AnswerRelevance, ContextPrecision, ContextRecall
├── ingestion/    → Pydantic schemas + dataset loader
├── retrieval/    → 3 chunkers + 3 embedding wrappers + 2 retrievers
├── pipeline/     → RunConfig + benchmark runner (with resume support)
└── reporting/    → Leaderboard CSV + 4 matplotlib charts

Installation (from source)

git clone https://github.com/shriram1206/rag-lens-framework.git
cd rag-lens-framework
pip install -e ".[dev]"
cp .env.example .env  # Fill in GROQ_API_KEY
pytest tests/unit tests/integration  # All tests use mocked judge — free to run

Tech Stack

Python 3.11+ · Groq (Llama-3.1-70B) · ChromaDB · sentence-transformers · rank_bm25 · Pydantic v2 · pandas · matplotlib · typer · tenacity


Author

Shriram M · GitHub · LinkedIn · shriram.coder@gmail.com

MIT License

Metadata

Release files for ram-rag-lens 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ram-rag-lens 0.1.0
File Size Uploaded Provenance Actions
ram_rag_lens-0.1.0.tar.gz 65.8 kB Without provenance Details for ram_rag_lens-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ram-rag-lens 0.1.0
File Interpreter ABI Platform Actions
ram_rag_lens-0.1.0-py3-none-any.whl Python 3 none any Details for ram_rag_lens-0.1.0-py3-none-any.whl

Total release size: 107.6 kB

Release files / ram_rag_lens-0.1.0.tar.gz

Download URL ram_rag_lens-0.1.0.tar.gz
Size 65.8 kB
Tags Source
SHA-256 checksum
How to use checksums
28a00ac5cc429f3085f5d0803d5ac99425b264a0103693f04e78dfd376927512
BLAKE2b-256 checksum
How to use checksums
324e3323a455cd53a3d0257233669b68764d066c4e757c661dd084382911330a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / ram_rag_lens-0.1.0-py3-none-any.whl

Download URL ram_rag_lens-0.1.0-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08bddb2f76cf9e6bb898c1b255018111d5983957792a8c760ae2595a523f0c9d
BLAKE2b-256 checksum
How to use checksums
40d418af1cf9ea9e026237f0b08011ab7a4e922cf444d9d4a97e3cecec0ec192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for ram-rag-lens 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page