Personal project — 2026

AI Act RAG Lab

An assistant that answers questions on the EU AI Act citing the articles, built on open-source LLMs and evaluated with metrics and confidence intervals.

Why this project

In my first AI Act prototypes the answers looked good, but I had no way to know how good they were. In the legal domain answering is not enough: the system must cite the right provision and say "not in the text" instead of inventing a rule.

AI Act RAG Lab rebuilds the pipeline from scratch and measures every choice on a 63-question gold set that validates itself against the text of the regulation.

How it works

1

Structure-aware parser

Rebuilds articles, paragraphs and points: 113 articles and 13 annexes become 856 passages, each with its own citation.

→
2

Hybrid retrieval

BM25 with Italian stemming and multilingual e5 embeddings, fused with Reciprocal Rank Fusion and reranked by a cross-encoder.

→
3

Verifiable answers

Llama 3, Mistral or Qwen (via Ollama or Hugging Face) answer only from the context, cite [Art. N] or abstain.

What I measured

Retrieval on 55 questions answerable from the regulation, relevance judged at article level.

+0.21

recall at equal context size: paragraph passages vs whole articles

+0.19

MRR over fixed-length text windows

+0.09

MRR from Italian stemming in BM25

Retriever / chunkingHit@1Recall@5MRR@10Recall at 6k chars
BM25 + stemming / by paragraph0.710.840.780.86
BM25 no stemming / by paragraph0.580.750.690.85
BM25 + stemming / whole articles0.620.880.720.66
BM25 + stemming / 1000-char windows0.640.820.590.82

The differences in the boxes come from a paired bootstrap on the same questions (95% confidence interval above zero). With 55 questions intervals are wide: the code reports them for every metric.

The most useful finding

Looking at Recall@5 alone, whole articles seem the best choice (0.88). But five articles can take 40,000 characters: at the same prompt size far fewer fit, and recall drops to 0.66 against 0.86. A badly chosen metric would have led to the wrong design.

Technical choices

RAFT fine-tuning with LoRA

Each training example holds the right passage plus three distractors chosen by BM25; in 20% of the examples the right passage is missing and the expected answer is an abstention. The model learns a behaviour (read, cite, abstain) rather than facts, which is why the provisions used for evaluation are kept out of training.

Training uses LoRA and QLoRA with PEFT and TRL, with the loss computed on the answer only. It is designed for a free Colab T4 GPU: 7B models such as Mistral are trained quantised to 4 bits (QLoRA).

Earlier prototypes

Flask · BM25 · spaCy · Llama 3

AI Act HR Auditor

Multi-step compliance analysis for recruiting systems, which the AI Act classifies as high-risk (Annex III, point 4).

Reflex · ChromaDB · Llama 3

AI Auditor

Audit report generated with RAG over a vector database: risk classification, GDPR profile and compliance action plan.