INSEI
sovereign RAG assistant, in production
It answers staff questions from the institute's intranet, cites its sources and declines when it finds nothing. Everything runs on the institute's servers.
- 300
users
In production, open to the whole institute.
- 96%
of off-topic questions refused
Compared with 12% for V1, on the same questions.
- 89%
of the right documents retrieved
Compared with 46% for V1, on 325 answerable questions.
ChapterProblemContents
Problem
Answers buried in the intranet
Staff look for information that already exists: a procedure, a contact, an HR document. Everything is on the intranet, and everything is hard to find there. The need: an assistant that answers in natural language, cites its sources and makes nothing up.
The first version, my final-year project built as a team of two, never knew when to stay silent: it had no refusal threshold. It read neither scanned PDFs nor tables. I took over the project on my own and rebuilt the assistant from scratch, ingestion included.
Constraints
Nothing leaves the institute
- Everything stays on the institute's servers. No hosted AI service, no telemetry.
- No license budget. Open models, self-hosted.
- Mixed content. Web pages, directory entries, PDFs that are sometimes scanned, tables, office files.
- One person to run it. Everything must stay readable by that person, from the code to the server commands.
Architecture
The path of a question
A LangGraph graph whose path is set by the code: no model chooses its tools. Follow one example.
Where is the expense claim form?
Answer written, with its sources.
Questionin the browser
A staff member asks a question in plain language, in the browser.
Routebge-m3 + logistic regression
Before any search, the question is classified: a document, a person in the directory, or small talk. When in doubt, documents.
Example written for the illustration.
PassagesQdrant
The intranet is read, split into passages and stored ahead of time; each night, only what changed is read again.
WordsBM25
Finds the passages that share the same words, reduced to their stem.
Example written for the illustration.
Meaningbge-m3
Finds the passages with the same meaning, even without a word in common.
Example written for the illustration.
Rerankbge-reranker-v2-m3
A second model rereads each passage together with the question and puts them back in order.
Example written for the illustration.
Sure enough?reranker score
The reranker's best score decides: high enough, it writes; too low, it refuses without calling the model.
Example written for the illustration.
WriteGemma 4 E4B, vLLM
Gemma 4 E4B streams its answer from the passages alone; a link or contact missing from the passages is replaced.
Example written for the illustration.
Answersource cards
Each reference becomes a source card, to check in one click.
Example written for the illustration.
Refusalnearby pages
With no passage it is sure enough of, the assistant says so, then suggests nearby pages.
Example written for the illustration.
Reading the intranet
- Read Web pages, PDFs, tables and office files through Docling; scanned pages through an OCR model.
- Reread Every night, only what has changed. A page leaves the index only if the intranet confirms it was deleted.
- Switch methods A new collection is built alongside, measured, then put into production with a switch that can be rolled back.
Decisions
Choices settled by measurement
| Decision | Option ruled out | What settled it |
|---|---|---|
| A path set by the code, a learned router | An agent that chooses its tools; GraphRAG; RAGFlow, tried | At this model size, an agent is unreliable, and RAGFlow did worse. Fixing an error means adding an example. |
| Gemma 4 E4B to write | Qwen 3.5 9B | Just as accurate and twice as fast, measured on the same machine. |
| A reranker, bge-reranker-v2-m3 | No reranker; Qwen3-Reranker-0.6B | With it, the right passage rises from 80% to 88%, on 260 questions. Qwen3-Reranker, just as good, is five times slower. |
| A refusal threshold on the reranker score | The prompt alone | Without a threshold, V1 answered more than half of the trap questions. |
| Contacts displayed by the code | A contact copied out by the model | A copied contact can be wrong. The profile comes from the directory, with a choice between people who share a name. |
| An evaluation written for the project | DeepEval, Ragas, promptfoo | These tools send telemetry, which the project's policy rules out. |
Results
V2 vs. V1: same days, same judge
Before retiring V1, I measured both versions with the same questions.
Trap questions refused: 89% (V2, in production) vs. 47% (V1), almost twice as many.
False refusals: 6% (V2, in production) vs. 28% (V1), five times fewer, lower is better.
Right passage passed to the model: 89% (V2, in production) vs. 46% (V1), almost twice as often.
All the other metrics
Correct answers, answerable questions325 test questions
Correct answers, answerable questions: 69% (V2) vs. 36% (V1), almost twice as many, a gain.
69%vs. 36% (V1)Answers judged correct, on answerable questions.
The same judge grades both versions' answers, on the same days, on the same machine. The gap stays positive across the whole 95% confidence interval.
325 test questions
Almost twice as many correct answers as with the first version (36%).
The judge is there to compare two versions, not to state an absolute rate. The ratio between the versions is the measurement; the rate is only indicative.
Sealed held-out set, answerable questions65 questions never seen during tuning
Sealed held-out set, answerable questions: 71% (V2) vs. 38% (V1), almost twice as many, a gain.
71%vs. 38% (V1)Correct answers on the held-out set.
A judge model, distinct from the models under evaluation, grades each answer. V2 was never tuned on these questions: it is the most conservative measurement.
65 questions never seen during tuning
Almost twice as many correct answers as V1 (38%), on questions never used to tune V2.
Replayed conversations531 messages, working split
Replayed conversations: 75% (V2) vs. 39% (V1), ×1.9, a gain.
75%vs. 39% (V1)Successful messages, replayed conversations.
Working split of the replayed conversations, on November 12, 2026: the same judge grades both versions' messages.
531 messages, working split
Conversations, held-out split141 messages, a split never opened before the measurement
Conversations, held-out split: 74% (V2) vs. 48% (V1), one and a half times as many, a gain.
74%vs. 48% (V1)Successful messages, held-out split of the conversations.
Replayed against the real API, each message checked by code; only aggregate counts are extracted from this split. V2 had already been run on it once, on October 22, 2026.
141 messages, a split never opened before the measurement
V2 had already been run on this split once, on October 22, 2026: only aggregate counts came out of it.
Contact questionsprofile taken from the directory
Contact questions: 100% (V2) vs. 84% (V1), all correct, a gain.
100%vs. 84% (V1)Contact questions answered correctly.
The profile is displayed by code, never copied by the model. On this sample, a full score does not prove that no error will ever happen in production.
profile taken from the directory
Fifty questions: a full score on this sample does not prove that no error will ever happen in production.
Off-topic questions refused25 questions
Off-topic questions refused: 96% (V2) vs. 12% (V1), ×8, a gain.
96%vs. 12% (V1)Off-topic questions refused.
Same judge for both versions, comparison of November 12 and 13, 2026. A sample too small for a precise rate.
25 questions
Twenty-five questions: too small a sample for a fine-grained rate.
Expected document among the cited sources325 answerable questions
Expected document among the cited sources: 83% (V2) vs. 50% (V1), ×1.7, a gain.
83%vs. 50% (V1)Expected document among the cited sources.
The expected document must be among the sources shown to the user; same judge, comparison of November 12 and 13, 2026.
325 answerable questions
Correct answers39 questions on 13 documents
Correct answers: 72% (V2) vs. 26% (V1), almost three times as many, a gain.
72%vs. 26% (V1)Correct answers, scanned PDFs.
Questions whose quotation sits on a page read by OCR. For most of them, the document was missing from V1's collection: the gap comes first from reading.
39 questions on 13 documents
Almost three times as many correct answers as V1 on scanned documents (26%).
For 31 of these questions, the document was missing from V1's collection: the gap comes first from reading.
Right passage passed to the modelsame questions
Right passage passed to the model: 92% (V2) vs. 8% (V1), ×12, a gain.
92%vs. 8% (V1)Right passage passed on, scanned PDFs.
Same questions, measured with the OCR model reading the scanned documents.
same questions
Examples correctly classified983 examples
Examples correctly classified: 79% (V2).
79%Routing examples correctly classified in cross-validation.
Each example is classified by a model trained on the others, on a PC, on November 19, 2026. These are the training examples, not real use.
983 examples
These are the training examples, not real usage. Thresholds are cautious: an uncertain message falls back to document search, which lowers some intents' scores without harming the answers.
Document questions sent elsewherelower is better
Document questions sent elsewhere: 2% (V2).
2%Document messages sent elsewhere by the router.
Messages aimed at a document that routing sends to another branch. An uncertain message falls back to document search.
lower is better
Product code coverageby the automated tests
Product code coverage: 91% (V2).
91%Product code statements covered by the tests.
pytest-cov on the assistant, the deployment and the readers, on a PC, on November 19, 2026, branches not counted. Coverage says where tests run, not what they prove.
by the automated tests
A statement run by a test is not a statement checked: coverage says where the tests go, not what they prove.
- The set. 500 test questions, 325 to answer and 175 to refuse. The trap questions fall into five kinds: missing information, off-topic, false premise, dangerous, or incomprehensible. Across the whole set, 100 form a sealed held-out set, never used for tuning.
- The judge. An LLM distinct from the models under evaluation, with a frozen prompt. Each version read the intranet with its own code.
- The uncertainty. A 95% confidence interval on each gap, resampled by whole document. The decision rule is written down before each measurement.
- The conditions. Both versions, on November 12 and 13, 2026, on the same machine, under Ollama, with the same judge. This set is harder than V1's, which had no trap questions or scanned PDFs, so their rates are not comparable.
Limitations and lessons learned
What I would measure earlier
I measured each component after the comparison, not when it was added. This late measurement shows that BM25 adds nothing once the reranker is in place: without BM25, the right passage does not move. Done earlier, it would have raised the question of keeping BM25.
The time saved by staff was never measured. That would have required timing a request handled the old way, before the first version. The test questions were written from the documents as V2 reads them; the held-out set and the held-out conversations therefore give the most conservative figures. Next measurement: response time and load handling, on the production server.