Buildoto
All articles
RAG chatbotReliability

RAG: how to keep the AI from inventing (and citing its sources)

15 mai 20263 min read

In short

  • An AI "invents" when you ask it for an answer it doesn't have: without reliable context, it fills the void.
  • RAG drastically reduces this risk by confining the model to your documents, but doesn't eliminate it by magic: everything hinges on the quality of the search and the guardrails.
  • The levers that really matter: semantic chunking, hybrid search, reranking, the "no proof, no answer" clause, and the systematic citation of the source.
  • A smaller model, well fed and confined, hallucinates less than a big model poorly fed.

The problem, concretely

On BeForBuild.com, my B2B SaaS, I have an assistant that answers on the business documentation. The first prototype "worked"… until it answered, with total confidence, a contract clause that didn't exist. In a company, that's a deal-breaker: a confidently wrong answer is worse than no answer at all.

The classic trap: you plug an LLM into a documentary base, the demo impresses, and you discover in production that 5 to 10% of the answers are subtly wrong. Too many to trust.

Why an AI invents

A language model "knows" nothing: it predicts the most likely word. If the question is about information absent from the context provided to it, it generates a plausible continuation anyway, that is, a hallucination. RAG (Retrieval-Augmented Generation) consists of providing it the right passages of YOUR documents before it answers. But if the search pulls up the wrong passages, the model answers from a wrong context: it "hallucinates" on faulty foundations. In other words, most of a RAG's hallucinations are really search failures, not model flaws.

How you prevent it, concretely

1. Semantic chunking

Cutting documents every 500 tokens separates a definition from its example, or a statement from its source. Instead, we chop by units of meaning (sections, lists, tables) and we repeat the headers/titles in each chunk, so the passage stays understandable on its own.

2. Hybrid search

Purely "semantic" search (vectors) sometimes misses an exact term (an article number, a reference). We combine dense search (embeddings) and keyword search (BM25): we get the best of both worlds.

3. Reranking

We retrieve broadly (20-30 passages), then a reranking model re-sorts to keep only the most relevant ones in the context window. An ACL 2025 study shows that evaluating several candidate answers and keeping the most faithful one ("best-of-N" approach) clearly reduces the error rate, without retraining the model.

4. The "no proof, no answer" clause

The instruction given to the model is strict: answer only from the provided passages, and say "I don't know" (or refer to a human) if the information isn't there. It's the most profitable guardrail, and the most neglected.

5. Systematic citation

Every answer points to the document and the page of origin. The user verifies in one click. Trust is earned through traceability, not through confidence, and it also makes it possible to detect drifts.

Why it works, and where the limits are

Done well, this setup moves an assistant from "impressive but risky" to "reliable in production." But let's be honest: no technique guarantees 0% hallucination. The realistic goal is to make errors rare and detectable (citation + "I don't know"). For high-stakes domains (health, legal), we add an automatic verification of the statements and we measure: you have to separate what breaks (the search or the generation) to fix it in the right place.

And no, you don't necessarily need the biggest model: the quality of the retrieval and the rigor of the prompt weigh more than the size of the LLM. A lighter European model, well confined, is often the best cost/reliability/sovereignty compromise (see RAG & GDPR).

In practice

This is exactly what runs on BeForBuild.com and what I adapt to your documents: chunking tailored to your content, hybrid search, reranking, strict guardrails and citations. We start on a measurable scope (one corpus, one case), we evaluate the rate of sourced answers, then we expand.

Sources

Related feature

Want this feature in your product?

See « Chatbot on your documents »

Frequently asked questions

Have a feature in mind? Let's talk.

30 minutes to scope your need and quote the fixed price. Reply within 24h.

Book my free audit · 30 min