RAG over French Wikipedia

Question answering over 1,000 French Wikipedia articles: recursive chunking, hybrid TF-IDF and dense retrieval (MRR 0.95 on 56 test questions) and short cited answers generated by Qwen2.5-1.5B-Instruct.

2026 · Shipped

A retrieval-augmented generation (RAG) system built for the Data Embedding and Learning course of the M2 MLSD at Université Paris Cité. It answers questions about 1,000 French Wikipedia articles of 200 to 900 words, and the language model may only use the passages returned by the search.

Explore before tuning. Before any chunking, I explored the corpus, and that step set most of the later choices: the dump extraction had erased birth or death dates in 11% of the articles, 48 disambiguation pages passed the length filter, and the encoder silently ignores everything past 128 tokens, which affected 74% of the 500-character windows suggested by the assignment.

Chunking. A recursive splitter measured in encoder tokens (110 tokens at most), written by hand and checked against LangChain's RecursiveCharacterTextSplitter: the chunks are identical. Small fragments are merged with their neighbour, which gives 10,926 chunks, none of them truncated by the encoder. Each chunk is indexed with its article title as a prefix, so a passage such as “He succeeded the linguist Auguste Carrière” still knows who it is about.

Retrieval. TF-IDF, dense embeddings (paraphrase-multilingual-MiniLM-L12-v2) and a hybrid score after min-max normalisation. On 56 test questions (one lexical and one paraphrased per article), the hybrid search reaches an MRR of 0.95, against 0.94 for TF-IDF, 0.75 for dense search alone and 0.87 for Reciprocal Rank Fusion.

Grounded generation. Qwen2.5-1.5B-Instruct receives the 5 best chunks, numbered, with strict rules: documents only, an exact refusal sentence, a [n] citation, one to three sentences. Every answer is checked automatically. With the basic prompt, 7 answers out of 10 were as expected and 3 gave a date found in no document. Tracing it back to the data showed that these dates lived in the article categories, which my cleaning step had removed. Adding them back as a short fact sheet per article brought the score to 10 out of 10, with no invented number.

The notebook runs end to end, locally from requirements.txt or on Google Colab with a T4 GPU. The README also states the limits: the test questions were written while reading the articles, which favours TF-IDF, and with 56 and 10 questions small gaps are not significant.

The Problem

Asked about Wikipedia facts, a small language model invents answers with confidence, and a naive search misses passages that do not name their subject or that go past the encoder's 128-token limit.

The Solution

A pipeline measured at every step: corpus exploration first, token-aware recursive chunking with title prefixes, hybrid TF-IDF and dense retrieval tuned on 56 questions, then a strict prompt with citations and automatic checks for refusals and invented numbers.

Results at a glance: MRR of four retrieval methods, and expected answers without and with RAG
Results at a glance: MRR of four retrieval methods, and expected answers without and with RAG
Full pipeline: offline indexing and online answering
Full pipeline: offline indexing and online answering
Part 2: lexical, dense and hybrid retrieval
Part 2: lexical, dense and hybrid retrieval
Part 3: prompt, generation and automatic checks
Part 3: prompt, generation and automatic checks
Part 1: fixed-size versus recursive chunking
Part 1: fixed-size versus recursive chunking
Comparison of the three chunking strategies
Comparison of the three chunking strategies
MRR as a function of α in the hybrid search
MRR as a function of α in the hybrid search
Topic map of the corpus (TF-IDF, SVD, k-means, t-SNE)
Topic map of the corpus (TF-IDF, SVD, k-means, t-SNE)
Year
2026
Role
Sole author: corpus exploration, chunking, indexing, evaluation, prompt design, diagrams and documentation (M2 coursework).
Tech Stack

RAG · Python · Hugging Face · Sentence-Transformers · scikit-learn · Qwen2.5 · TF-IDF · Embeddings · NLP