Skip to content
BrightGist

What Is RAG? How AI Tools Look Things Up Before They Answer

Retrieval-augmented generation lets a chatbot answer from your documents instead of from memory. Here is how it works, where you have already used it, and where it still fails.

Mubarak Ali · · 3 min read

Illustration of a robotic hand pulling glowing books from library shelves into a chat answer

Ask a general chatbot how many days of annual leave your company gives and it can't know. Your HR policy wasn't in its training data, and even if a similar policy was, the model would be guessing. Companies that want an AI assistant to answer from their own documents have three options.

They can train the model on those documents, which is slow and expensive and has to be repeated every time a document changes. They can paste every document into the conversation, which runs into the size limit of the model's context window and gets slow and costly. Or they can have the system find the few passages that matter for each question and paste in only those. That third approach is called retrieval-augmented generation, or RAG.

The term comes from a 2020 research paper by Patrick Lewis and colleagues at Facebook AI Research, University College London and New York University. The idea has since become the standard way to connect language models to company knowledge.

How it works

RAG has a preparation step and an answering step.

During preparation, the documents are split into chunks of a few paragraphs each. Every chunk is converted into an embedding, which is a long list of numbers that represents what the text means. Chunks about similar things end up with similar numbers. The embeddings are stored in a search index, often called a vector database.

When someone asks a question:

  1. The question is converted into an embedding the same way.
  2. The system finds the chunks whose embeddings are closest to the question's. "How many days off do I get?" can match a paragraph that says "annual leave entitlement is 20 working days," even though the two share almost no words.
  3. The best-matching chunks are added to the prompt with an instruction along the lines of "Answer using only the sources below, and cite them."
  4. The language model writes an answer from those sources, often with links or references to them.

Many systems also run an ordinary keyword search alongside the meaning-based one, and then rerank the combined results before passing them to the model. Keyword search is better at exact things like product codes and names.

Where you've already seen it

AI search tools work on the same principle: they search the web, pull in the top results and write an answer from them. So do the "chat with your PDF" tools, customer support bots that answer from a help center, and the projects or knowledge features in chat apps where you upload your own files.

Why companies like it

Updating knowledge is easy. When the leave policy changes, you replace the document and the next answer uses the new one, with no retraining.

Answers can be checked. Because the model is pointed at specific passages, the app can show you which ones it used.

Access control is possible. The system can retrieve only documents the person asking is allowed to see.

Where it fails

RAG reduces made-up answers. It doesn't remove them, and it adds a few failure modes of its own.

If retrieval brings back the wrong passages, the model writes a confident answer from the wrong material. This is the most common failure, and it's easy to miss because the answer comes with citations that look trustworthy.

Splitting documents into chunks can break things apart. A table cut in half, or a rule in one paragraph with its exception in the next, can lead to an answer that is technically sourced and still wrong.

Old and new versions of a document can both sit in the index, and the system may retrieve the outdated one.

The model can ignore its sources. Sometimes it mixes what it retrieved with what it remembers from training, especially when the sources don't fully answer the question.

How to use RAG tools well

Ask for citations and open them, at least for anything important. Check that the quoted passage actually says what the answer claims. We covered more ways to check AI answers in why AI makes things up.

Ask specific questions. "What is the notice period for resigning after probation?" retrieves better passages than "tell me about leaving the company."

If you manage the documents, keep them clean. Delete outdated versions, give files clear titles and avoid putting important rules only inside images or scanned PDFs, which many systems can't read well.

Share this article
  • RAG
  • LLM
  • AI search
  • chatbots
  • explainer

Keep reading