Observed since 21 Oct, 10:30 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
aidial-rag-eval
Library for RAG evaluation
Library designed for RAG (Retrieval-Augmented Generation) evaluation, where retrieval and generation metrics are calculated.
Install the library using pip:
pip install aidial-rag-eval
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"}
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:
The algorithm is token-intensive. Considering the balance between quality and price, the following models are recommended:
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.
Run the linting before committing:
make lint
To auto-fix formatting issues run:
make format
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.
To remove the virtual environment and build artifacts run:
make clean
To build the package run:
make build
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
numpyEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | numpy<3,>=1.26.4 | runtime |
pandasEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | pandas<3.0.0,>=2.2.2 | runtime |
fsspecEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | fsspec<2025.0.0,>=2024.3.1 | runtime |
s3fsEnvironment{
"extras": "",
"marker": "extra == \"s3fs\"",
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | s3fs<2025.0.0,>=2024.3.1; extra == "s3fs" | runtime |
pydanticEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | pydantic>=2.7.1 | runtime |
spacyEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | spacy<4,>=3.8.9 | runtime |
tqdmEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | tqdm<5.0.0,>=4.66.4 | runtime |
langchain-coreEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | langchain-core<2,>=0.3.85 | runtime |
more-itertoolsEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | more-itertools<11.0.0,>=10.5.0 | runtime |
pyarrowEnvironment{
"extras": "",
"marker": null,
"requires_python": "<3.15,>=3.11",
"evaluation": "NOT_EVALUATED"
} | pyarrow>=20.0.0 | runtime |
bdist_wheel · 44.73 KB · Python py3
sdist · 29.84 KB · Python source
Observed since 21 Oct, 10:30 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:1f3d4e128cdc04073cf39dfb09e81c6bd59a26aab68abd7ce8c26c616eb51fd1