Skip to main content

ragval

The complete RAG evaluation library. Scores, diagnoses, and domain-aware.

PyPI version Python versions License: MIT Downloads

ragval covers every metric category in the RAG evaluation literature — 50 metrics across retrieval, generation, safety, agentic, conversation, and custom — behind one async-native API. It then does two things most evaluation tools don't:

  1. Pipeline-layer diagnosis. When a score is low, ragval tells you which layer failed — knowledge base, retrieval, fusion/ranking, generation, or prompt — the likely root cause, and a concrete fix.
  2. Domain-specific metrics. First-class profiles for clinical, legal, and financial RAG, with metrics like drug_name_precision, dosing_accuracy, jurisdiction_specificity, citation_accuracy, and numerical_accuracy.

One provider integration: LiteLLM. Point a model string at OpenAI, Anthropic, Groq, Azure, Ollama, or any of 100+ providers.


Install

pip install ragval
pip install "ragval[pandas]"   # for BatchEvaluationResult.to_dataframe()

Quick start

from ragval import evaluate

result = await evaluate(
    question="What is the first-line treatment for Type 2 diabetes?",
    answer="Metformin, typically started at 500mg twice daily.",
    contexts=["ADA guidelines recommend metformin as first-line therapy..."],
)

print(result.verdict)                    # PASS | WARN | FAIL
print(result.diagnosis.failed_layer)     # e.g. "retrieval"
print(result.diagnosis.suggested_fix)

Every metric has async compute() and sync compute_sync(). The evaluator has evaluate() / evaluate_sync(). FastAPI-compatible out of the box.

Reusable evaluator

from ragval import RAGEvaluator

evaluator = RAGEvaluator(
    model="groq/llama-3.3-70b-versatile",
    domain="clinical",
)

result = await evaluator.evaluate(
    question=question,
    answer=answer,
    contexts=contexts,
    ground_truth=ground_truth,   # optional
)

print(result.domain_metrics["drug_name_precision"].score)
print(result.domain_metrics["dosing_accuracy"].score)

Run only the metrics you want:

RAGEvaluator(
    model="groq/llama-3.3-70b-versatile",
    metrics=["faithfulness", "context_precision", "hallucination"],
)

Metrics coverage

40 registered metrics + 10 domain metrics = 50, plus 3 custom-metric builders.

Category Metric Ground truth LLM
retrieval context_precision – ✅
retrieval context_recall ✅ ✅
retrieval context_relevance – ✅
retrieval context_entity_recall ✅ ✅
retrieval context_utilization – ✅
retrieval context_sufficiency – ✅
retrieval retrieval_diversity – –
retrieval noise_sensitivity – ✅
retrieval mrr – ✅
retrieval ndcg – ✅
retrieval hit_rate – ✅
generation faithfulness – ✅
generation answer_relevance – ✅
generation answer_correctness ✅ ✅
generation hallucination – ✅
generation factual_correctness ✅ ✅
generation answer_semantic_similarity ✅ –
generation answer_completeness – ✅
generation summarization – ✅
generation coherence – ✅
generation fluency – ✅
generation conciseness – ✅
generation refusal_appropriateness – ✅
generation citation_support – ✅
safety bias – ✅
safety toxicity – ✅
safety topic_adherence – ✅
safety pii_leakage – ✅
safety tone_professionalism – ✅
agentic tool_correctness – –
agentic argument_correctness – ✅
agentic task_completion – ✅
agentic step_efficiency – ✅
agentic plan_adherence – ✅
agentic plan_quality – ✅
agentic agent_goal_accuracy ✅ ✅
conversation conversation_completeness – ✅
conversation knowledge_retention – ✅
conversation role_adherence – ✅
conversation conversation_relevancy – ✅
custom GEval, RubricEval, AspectCritic – ✅

ragval list-metrics prints this table from the live registry.

Domain profiles

Domain Extra metrics
clinical drug_name_precision, dosing_accuracy, contraindication_coverage, authority_score
legal jurisdiction_specificity, citation_accuracy, statute_currency
financial numerical_accuracy, regulatory_compliance_mention, temporal_accuracy

Supported providers

Model string Provider API key env var
groq/llama-3.3-70b-versatile Groq GROQ_API_KEY
openai/gpt-4o-mini OpenAI OPENAI_API_KEY
anthropic/claude-3-haiku Anthropic ANTHROPIC_API_KEY
azure/gpt-4o Azure OpenAI AZURE_API_KEY
ollama/llama3 Ollama (local) – (api_base)
together_ai/... Together TOGETHERAI_API_KEY

Full pipeline evaluation

result = await evaluator.evaluate_pipeline(
    question=question,
    answer=answer,
    retrieved_chunks=chunks,
    ground_truth=ground_truth,
    expected_chunks=expected,
    k=5,
)

Batch evaluation

batch = await evaluator.batch_evaluate(qa_pairs=rows, concurrency=3)
print(batch.report())          # markdown table + diagnosis summary
df = batch.to_dataframe()       # needs ragval[pandas]
worst = batch.worst_cases(5)

Diagnosis

result.diagnosis.failed_layer      # "retrieval"
result.diagnosis.root_cause        # "More than half of retrieved chunks are irrelevant..."
result.diagnosis.suggested_fix     # "Improve chunking granularity. Add a reranking step..."
result.diagnosis.confidence        # 0.82
result.diagnosis.secondary_issues  # ["[noise_sensitive] possible fusion_ranking issue: ..."]

Custom metrics

from ragval.metrics.custom import GEval

metric = GEval(
    name="Dosing Specificity",
    criteria="The answer must include exact dose amounts with units for every drug mentioned.",
    model="groq/llama-3.3-70b-versatile",
)
score = await metric.compute(question, answer, contexts, provider)

Agentic and conversation

result = await evaluator.evaluate_agent(
    question=question, answer=answer,
    tool_calls=actual, expected_tools=expected,
    action_trace=steps, declared_plan=plan,
)

conv = await evaluator.evaluate_conversation(
    turns=turns, system_role="clinical decision support assistant",
)

CLI

ragval evaluate -q "..." -a "..." -c "chunk 1" -c "chunk 2" --domain clinical
ragval batch --file rows.json --concurrency 3 --output markdown
ragval list-metrics --category retrieval
ragval version

Why ragval

Most evaluation tools score your pipeline. They don't tell you what to fix. ragval's diagnosis engine walks an ordered decision tree over the metric results and isolates the failing layer, so a 0.42 faithfulness score becomes "retrieval is fine, generation is hallucinating — tighten the grounding instruction."

Generic metrics miss domain-critical failures. A clinically wrong dose can be perfectly "faithful" to a bad chunk. ragval's clinical profile checks drug names, doses, and contraindications against the retrieved context specifically, and flags patient-safety concerns even when the generic scores look fine. The same applies to jurisdiction and citation currency for legal RAG, and figure traceability for financial RAG.

One integration, async-native, no model downloads. LiteLLM gives you every provider through a model string. Text metrics use pure-Python TF-IDF — no sentence-transformers, no torch, fast pip install.

Contributing

git clone https://github.com/shivamraghav779/ragval
cd ragval
pip install -e ".[dev]"
pytest tests/ -v

Issues and PRs welcome at https://github.com/shivamraghav779/ragval.

License

MIT © Shivam Raghav

Metadata

Release files for ragval 0.0.1

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

Source distribution (sdist)

Source distribution for ragval 0.0.1
File Size Uploaded Provenance Actions
ragval-0.0.1.tar.gz 79.4 kB Without provenance Details for ragval-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ragval 0.0.1
File Interpreter ABI Platform Actions
ragval-0.0.1-py3-none-any.whl Python 3 none any Details for ragval-0.0.1-py3-none-any.whl

Total release size: 181.3 kB

Release files / ragval-0.0.1.tar.gz

Download URL ragval-0.0.1.tar.gz
Size 79.4 kB
Tags Source
SHA-256 checksum
How to use checksums
378f03ec8c48c10bc007f99b97ee6855bc7dc04e64ac5e8f845bb018b5bf5ae5
BLAKE2b-256 checksum
How to use checksums
8cfe30a92aa29d721000d4325f368a5d47dde6e5b2a9e2a230b3c206565a0fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / ragval-0.0.1-py3-none-any.whl

Download URL ragval-0.0.1-py3-none-any.whl
Size 101.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e615cd86c8777b0394e66b2dc5376748a552e6d4a187a98d536694c41501567
BLAKE2b-256 checksum
How to use checksums
d1496675162103d38d82d02a224d890d6816fd830adb7568f8fcc918550dbc6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for ragval 0.0.1

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.0.1 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