Skip to main content

AI DIAL RAG EVAL

PyPI version

Overview

Library designed for RAG (Retrieval-Augmented Generation) evaluation, where retrieval and generation metrics are calculated.

Usage

Install the library using pip:

pip install aidial-rag-eval

spaCy language model

The generation metrics require the English language model for spaCy. Download it after installation:

python -m spacy download en_core_web_sm

Alternatively, you can install the model directly via URL:

pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl

Or as a Poetry dependency:

en-core-web-sm = {url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl"}

Example

The example of how to get retrieval metrics along with answer inference based on the context.

import pandas as pd
from langchain_openai import AzureChatOpenAI
from aidial_rag_eval import create_rag_eval_metrics_report
from aidial_rag_eval.metric_binds import CONTEXT_TO_ANSWER_INFERENCE,\
    ANSWER_TO_GROUND_TRUTH_INFERENCE, GROUND_TRUTH_TO_ANSWER_INFERENCE,\
    ANSWER_TO_FACTS_INFERENCE, FACTS_TO_ANSWER_INFERENCE

llm = AzureChatOpenAI(model="gemini-2.5-flash-lite")

df_ground_truth = pd.DataFrame([
    {
        "question": "What is the diameter of the Earth and the name of the biggest ocean?",
        "documents": ["earth.pdf"],
        "facts": ["The diameter of the Earth is approximately 12,742 kilometers.", "The biggest ocean on Earth is the Pacific Ocean."],
        "answer": "The Earth's diameter measures about 12,742 kilometers, and the Pacific Ocean is the largest ocean on our planet."
    },])
df_answer = pd.DataFrame([
    {
        "question": "What is the diameter of the Earth and the name of the biggest ocean?",
        "documents": ["earth.pdf"],
        "context":  [
            "The Earth, our home planet, is the third planet from the sun. It's the only planet known to have an atmosphere containing free oxygen and oceans of liquid water on its surface. The diameter of the Earth is approximately 12,742 kilometers.",
            "The Pacific Ocean is the largest and deepest of Earth's oceanic divisions, extending from the Arctic Ocean in the north to the Southern Ocean in the south."
        ],
        "answer": "The Earth has a diameter of approximately 12,742 kilometers."
    },
])

df_metrics = create_rag_eval_metrics_report(
    df_ground_truth,
    df_answer,
    llm=llm,
    metric_binds=[
        CONTEXT_TO_ANSWER_INFERENCE,
        ANSWER_TO_GROUND_TRUTH_INFERENCE,
        GROUND_TRUTH_TO_ANSWER_INFERENCE,
        ANSWER_TO_FACTS_INFERENCE,
        FACTS_TO_ANSWER_INFERENCE,
    ],
)
print(df_metrics[["facts_ranks", "recall", 'precision', 'mrr', 'f1', 'ctx_ans_inference', 'ans_gt_inference', 'gt_ans_inference', 'ans_fct_inference', 'fct_ans_inference']])

It is expected to see the following results:

recall precision mrr f1 ctx_ans_inference ans_gt_inference gt_ans_inference ans_fct_inference fct_ans_inference
0.5 0.5 0.5 0.5 1.0 0.5 1.0 0.5 1.0

In this table:

  • "recall" of 0.5 indicates that only 1 out of 2 ground truth facts were found in the context.
  • "precision" of 0.5 reflects that just 1 context chunk out of 2 includes any ground truth facts.
  • The prefix of the inference metrics signifies the premise and hypothesis in the following format: premise_hypothesis_inference.
    • "ctx" refers to 'context'
    • "ans" refers to 'answer'
    • "gt" refers to 'ground truth answer'
    • "fct" refers to 'facts'
  • "ctx_ans_inference" of 1.0 means our answer can be fully derived from the context.
  • "ans_gt_inference" of 0.5 means the ground truth answer is only partially entailed by our answer.
  • "gt_ans_inference" of 1.0 means our answer can be fully derived from the ground truth answer.
  • "ans_fct_inference" of 0.5 means only half of the ground truth facts are entailed by our answer (the Pacific Ocean fact is missing).
  • "fct_ans_inference" of 1.0 means our answer can be fully derived from the ground truth facts.

The algorithm is token-intensive. Considering the balance between quality and price, the following models are recommended:

  • gemini-3.1-flash-lite
  • gemini-2.5-flash-lite
  • gpt-5-mini
  • gpt-5-nano
  • gpt-5.4-mini

Developer environment

This project uses Python>=3.11 and Poetry>=2.2.1 as a dependency manager.

Check out Poetry's documentation on how to install it on your system before proceeding.

To install requirements:

poetry install

This will install all requirements for running the package, linting, formatting and tests.

Lint

Run the linting before committing:

make lint

To auto-fix formatting issues run:

make format

Test

Run unit tests locally for available python versions:

make test

Run unit tests for the specific python version:

make test PYTHON=3.11

The generation evaluation requires an access to the LLM. The generation evaluation tests (located in tests/llm_tests directory) use cached LLM responses by default. To run the tests with real LLM responses, you need add --llm-mode=real argument to the test command:

make test PYTHON=3.11 ARGS="--llm-mode=real"

The test run with real LLM responses requires the following environment variables to be set:

Variable Description
DIAL_URL The URL of the DIAL server.
DIAL_API_KEY The API key for the DIAL server.

Copy .env.example to .env and customize it for your environment.

Clean

To remove the virtual environment and build artifacts run:

make clean

Build

To build the package run:

make build

Metadata

Release files for aidial-rag-eval 0.7.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 aidial-rag-eval 0.7.0
File Size Uploaded Provenance Actions
aidial_rag_eval-0.7.0.tar.gz 30.6 kB Without provenance Details for aidial_rag_eval-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aidial-rag-eval 0.7.0
File Interpreter ABI Platform Actions
aidial_rag_eval-0.7.0-py3-none-any.whl Python 3 none any Details for aidial_rag_eval-0.7.0-py3-none-any.whl

Total release size: 76.4 kB

Release files / aidial_rag_eval-0.7.0.tar.gz

Download URL aidial_rag_eval-0.7.0.tar.gz
Size 30.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b91f1d0178f3528ce3b9c4e5ccffe922925dbca704becfa24b6a6dbda7fe0be9
BLAKE2b-256 checksum
How to use checksums
4f46a544b65e43b5760ee99942994ea394184d24af53514235042b6f4ba22303
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.11.17 Linux/7.0.0-1017-azure

Release files / aidial_rag_eval-0.7.0-py3-none-any.whl

Download URL aidial_rag_eval-0.7.0-py3-none-any.whl
Size 45.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d76d0f5c5574c5fb4fa5d3faa6e83a075ad957b2815833ce360149728771e6ca
BLAKE2b-256 checksum
How to use checksums
8c69382e3d0c9487d128120372d5a71bb743e44208071bd0bcc96deed7c038aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.11.17 Linux/7.0.0-1017-azure

Security for aidial-rag-eval 0.7.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.7.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