8000 GitHub - OoFa99/ArRAG-Eval: Research-grade Arabic Retrieval-Augmented Generation evaluation framework with BM25, dense/hybrid retrieval, agentic query decomposition, LLM-as-judge evaluation, and MLFlow experiment tracking. · GitHub
[go: up one dir, main page]

Skip to content

About

Research-grade Arabic Retrieval-Augmented Generation evaluation framework with BM25, dense/hybrid retrieval, agentic query decomposition, LLM-as-judge evaluation, and MLFlow experiment tracking.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ArRAG-Eval

ArRAG-Eval evaluates Arabic retrieval-augmented generation using Arabic Wikipedia as the retrieval corpus and questions from the ARCD validation split. The main ablation compares dense retrieval, hybrid retrieval, and hybrid retrieval with query decomposition.

The project TODO tracks benchmark fixes, implementation work, and follow-up experiments.

How it works

  1. The corpus loader fetches ARCD and a subset of Arabic Wikipedia. The experiment runners split each article using the configured chunking strategy and normalize the searchable text. Corpus loader · Wikipedia chunking
  2. The retrieval store embeds chunks with intfloat/multilingual-e5-small and stores them in Qdrant for dense search. BM25 normalizes questions and passages the same way and ranks passages that share a token with the question. It rebuilds from all Qdrant pages on reopen and orders ties by chunk ID. Hybrid search combines the dense and keyword rankings with reciprocal rank fusion. Retrieval store · Restart regression test
  3. The LangGraph pipeline retrieves passages and deduplicates them before sending context to Ollama. It keeps the first copy of each chunk ID or exact text and drops spans already covered by earlier passages from the same source. If at least 80% of a later span is already covered, it trims repeated text at the edges and keeps source offsets for the remaining passage. In agentic mode, the pipeline can retrieve for separate sub-queries and check context sufficiency before generation. Pipeline · Evidence deduplication
  4. The scored runners use RAGEvaluator with the Ollama judge, then write per-question outputs and log aggregate metrics and artifacts to MLflow. Metrics · Judge

The scored runners use the ARCD questions without using the reference answers. The pipeline's evaluation_scores field contains placeholder zeros. Use the evaluator output or the MLflow metrics for scored results. Experiment presets

New Qdrant points use deterministic UUIDs derived from the chunk ID, which comes from the document ID and chunk position. Existing collections with integer point IDs are still readable. Point ID regression test

Wikipedia results include a provenance object with the article ID, title, URL, dataset snapshot, and original passage. The offsets are zero-based character positions in the dataset article's text, with an exclusive end. Sections and article revision IDs are recorded when available. The result's text field holds the normalized passage used for search. Wikipedia chunking

Run locally

Use Python 3.12 and run these commands from the repository root. The default installation includes the experiment pipeline. Tests and notebooks are opt-in. uv dependency groups

What you need Setup
Run experiments uv sync --locked
Run experiments and tests uv sync --locked --group test
Run experiments and notebooks uv sync --locked --group notebook
Use both optional groups uv sync --locked --group test --group notebook

Run the offline tests with uv run --locked --group test python -m pytest -q -m "not integration" and lint with uv run --locked --group test ruff check. GitHub Actions runs these checks on pushes and pull requests. Open the notebook with uv run --locked --group notebook jupyter lab.

If you use pip, install the exported core requirements in a fresh environment.

python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
python -m pip check

To update dependencies, edit pyproject.toml, refresh the shared lock, and regenerate the core pip export. Use uv lock --upgrade when refreshing every pin. uv export reference

uv lock
uv export --locked --no-default-groups --no-emit-project --no-hashes --output-file requirements.txt

The default Windows setup was verified with CPU PyTorch. The optional GPU setup uses a separate environment for CUDA embeddings.

Run Qdrant at http://localhost:6333. In a separate terminal, start Ollama at http://localhost:11434 if it is not running, then pull the default generation and judge model with ollama pull qwen3:4b.

The experiment config’s ollama_host and llm_model settings are used for query decomposition, context sufficiency checks, answer generation, and judge requests.

docker run -p 6333:6333 qdrant/qdrant:latest

The first run may download the embedding model and any missing datasets. The corpus loader defaults to data_store/ in the repository, with arcd/ and wiki_ar/ subdirectories. Set ARRAG_DATA_DIR in your shell or project .env to choose a different cache. An absolute path is used as given. A relative path is resolved from the repository root.

With the default setting, the loader checks ./~/arrag-eval/data/ for each dataset that is missing from data_store/. The ~ here is the literal folder inside the repository. To migrate an old cache, copy each dataset directory into data_store/ if its destination is absent, then run the startup check before removing the old copy. New downloads go into data_store/, or into ARRAG_DATA_DIR when it is set.

Run uv run --locked python -m scripts.check_startup before starting an experiment. With an activated pip environment, use python -m scripts.check_startup.

The check reads the Ollama model list, discovers fingerprinted Qdrant collections, and checks local dataset cache metadata. Pass --collection <name> to verify the schema of the exact collection printed by an experiment. A missing cache or collection is a first-run warning. An unreachable service, a missing Ollama model, or an incompatible collection returns exit code 1. For the default E5 model, the collection should have a single unnamed 384-dimensional dense vector with Cosine distance.

When an experiment opens an index, it creates a collection only if Qdrant reports that the collection is missing. Connection and credential failures report separate errors. The store checks the vector configuration before loading BM25. If a page fails to load, the error includes the collection name, page number, and number of chunks read so far.

Command What it does
python -m experiments.run_baseline Runs hybrid retrieval for 20 questions and writes outputs/baseline_outputs.json.
python -m experiments.run_baseline_mlflow Writes the same baseline output file and logs it as an MLflow artifact.
python -m experiments.run_baseline_metrics Reuses matching cached answers when available and writes outputs/detailed_scores.json.
python -m experiments.run_semantic_metrics Builds or reuses a semantic passage index and writes outputs/semantic_detailed_scores.json.
python -m experiments.run_ablation Shares one index across three retrieval configurations, writes per-configuration outputs in outputs/, and logs three MLflow runs.
python -m scripts.create_ablation_table Reads the experiment configured in the script and writes outputs/ablation_table.md.

The baseline and semantic metrics runners look for an answer cache matching the index fingerprint and evidence format in outputs/ first, then for the same filename at the repository root. To rerun generation for that combination, remove matching cache files from both locations. Git ignores outputs/.

New per-question outputs include retrieval_stats. candidates_per_sub_query counts the returned passages before deduplication, in the same order as sub_queries. context_passages counts the passages included in the answer prompt. prompt_tokens is Ollama's reported token count for that prompt, or null if no count was available. Older cached answers may lack these fields.

candidates_before_fusion records the dense and bm25 counts for each sub-query, in the same order. A count of 0 means that search ran and returned no candidates. A count of null means it was skipped or the backend did not report it.

Live pipeline smoke test

Start Qdrant and Ollama, then run the smoke test explicitly. The test requires successful HTTP responses from both services and uses a small Arabic corpus from the repository. It creates a temporary Qdrant collection and removes it when the test finishes.

uv run --locked --group test python -m pytest -q -m integration --run-integration

On GitHub, run Live pipeline smoke test manually from the Actions tab. That workflow starts both services and pulls the smaller qwen3:0.6b model for the CPU runner.

Optional NVIDIA GPU setup on Windows

Verified on a GeForce GTX 1650 Ti with 4 GB of VRAM, NVIDIA driver 621.14, and Python 3.12.3. The default embedding model, intfloat/multilingual-e5-small, encoded two Arabic texts as 384-dimensional vectors on cuda:0. PyTorch reported 450 MiB of peak allocated GPU memory for this check.

Check your card and driver with nvidia-smi. The commands below use Python 3.12 and the PyTorch 2.15.0 wheel built with CUDA 13.2. The CUDA version shown by nvidia-smi is the driver's supported version. torch.version.cuda reports the version used to build the wheel. PyTorch Windows CUDA wheels · NVIDIA CUDA driver compatibility

uv venv .venv-gpu --python 3.12
uv pip install --python .venv-gpu/Scripts/python.exe --index-url https://download.pytorch.org/whl/cu132 --no-deps "torch==2.15.0+cu132"
uv pip install --python .venv-gpu/Scripts/python.exe -r requirements.txt
uv pip check --python .venv-gpu/Scripts/python.exe

Test the same embedding model used by the default pipeline. The first run may download its weights.

@'
import torch
from sentence_transformers import SentenceTransformer

assert torch.cuda.is_available(), f"CUDA unavailable in PyTorch {torch.__version__}"
model = SentenceTransformer("intfloat/multilingual-e5-small")
embedding = model.encode(["query: Cairo"], convert_to_tensor=True)
assert embedding.device.type == "cuda", f"Embedding is on {embedding.device}"
print(torch.__version__, torch.version.cuda, torch.cuda.get_device_name(0))
print(embedding.shape, embedding.device)
'@ | .\.venv-gpu\Scripts\python.exe -

Use the GPU environment's Python for commands that should use this PyTorch build.

Reading the results

Metric What the implementation measures
Faithfulness Fraction of generated claims the judge finds fully supported by retrieved context.
Answer relevance Mean embedding similarity between the original question and questions generated from the answer.
Context precision Mean precision across all retrieval cutoffs. The judge labels chunks by whether they contributed to the generated answer.

The historical ablation report records three completed runs from ArRAG-Eval-Full with 20 questions per configuration and a logged corpus size of 500. Dense retrieval led on context precision and answer relevance, and agentic retrieval led on faithfulness in this run. Regenerating the table writes to outputs/.

Configuration Context precision Faithfulness Answer relevance
Dense 0.374 0.580 0.812
Hybrid 0.362 0.516 0.799
Agentic hybrid 0.316 0.594 0.797

Caveats for new comparisons

  • The current ablation runner is set to 100 questions and logs to ArRAG-Eval-Full 2. The table generator and analysis notebook point at ArRAG-Eval-Full.
  • chu 5CB5 nk_strategy selects fixed overlapping word windows, sentence passages, or semantic groups of adjacent sentences. Sentence and semantic chunks stay within paragraphs and sections. chunk_size is a word limit. The sentence-based strategies apply word overlap when splitting a sentence that exceeds that limit. Semantic grouping uses the configured embedding model and a cosine similarity threshold of 0.72. Chunking strategies
  • The Wikipedia index also checks the loaded model’s token limit, including prompts and special tokens. It splits oversized passages at source boundaries and preserves the original offsets. Dense search reports an error for a query that exceeds the model’s limit. Embedding input handling
  • The model's declared prompts and sequence limit are used by default. The bundled multilingual E5 small preset supplies query: and passage: and reads the model's 512-token limit. Set embedding_query_prompt, embedding_passage_prompt, or embedding_max_tokens in an experiment config when the model needs an override. E5 model card
  • The Wikipedia presets use arrag-eval-wikipedia as a collection name prefix. The fingerprint includes the model revision or local files, the resolved prompts and token limit, and the prepared passages and provenance. The new embedding format selects a fresh collection automatically. Index preparation
  • If indexing is interrupted, rerun the same experiment with the same inputs. It embeds and uploads only the missing Wikipedia chunks. The runner reports Wikipedia index ready after verifying the vector configuration, point IDs, and exact point count in Qdrant.
  • Agentic retrieval can supply more chunks than the other configurations because top_k applies per sub-query. The existing ablation compares the end-to-end configurations at their current settings.

About

Research-grade Arabic Retrieval-Augmented Generation evaluation framework with BM25, dense/hybrid retrieval, agentic query decomposition, LLM-as-judge evaluation, and MLFlow experiment tracking.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0