CyberFreezeDev Loading
  1. Home
  2. AI glossary
  3. Retrieval-augmented generation (RAG)

What is retrieval-augmented generation (RAG)?

Search your own documents first, then the model answers from what was found, with sources.

3D render of a paper stack and a scanner bed whose light bar reads fields into a record card

The plain definition

Retrieval finds the relevant passages in your content; generation hands them to a model to answer and cite, with no retraining needed.

Read more about The plain definition

Retrieval-augmented generation (RAG) combines two steps. Retrieval: find the passages in your own content that relate to a question. Generation: hand those passages to a large language model with an instruction like "answer using only the text below and cite it".

The term comes from a 2020 research paper by Lewis and colleagues. Today it is the standard way to build a chatbot or assistant over company policies, manuals, contracts or a product catalogue, without retraining any model.

How it works

  1. 01 Ingest

    Documents are converted to text and split into chunks of a few hundred words.

    Read more about Ingest

    Documents (PDF, DOCX, HTML, spreadsheets, scanned files after OCR) are converted to text and split into chunks of a few hundred words.

  2. 02 Index

    Each chunk becomes an embedding in a vector database, with source, date and access group.

    Read more about Index

    Each chunk is turned into an embedding and stored in a vector database, usually with metadata such as source file, date and access group.

  3. 03 Retrieve

    The question is embedded the same way and the closest chunks are fetched.

    Read more about Retrieve

    A user question is embedded the same way, and the closest chunks are fetched. Many systems also run keyword search and merge the two result lists.

  4. 04 Generate

    The model answers from the top chunks and points to the ones it used.

    Read more about Generate

    The top chunks go into the prompt with the question. The model writes the answer and points to the chunks it used.

Where it matters in business

Internal knowledge assistants

Staff ask a policy question and get the answer with a link to the clause.

Read more about Internal knowledge assistants

Staff ask "what is our refund policy for B2B orders?" and get the answer with a link to the exact clause.

Customer support

An assistant answers from current product documents and hands over when it finds nothing.

Read more about Customer support

A website or WhatsApp assistant that answers from current product documents, and hands over to a person when it finds nothing.

Content that changes often

Edit a document and the answers change at the next re-index, with no retraining.

Read more about Content that changes often

Updating a document updates the answers on the next re-index. With fine-tuning you would have to train again.

A practical example

A clinic's assistant answers aftercare questions by quoting its own PDFs with file names, and follows edits after the nightly re-index.

Read more about A practical example

A clinic keeps treatment guides, price lists and aftercare sheets as PDFs. A RAG assistant indexes them. When the front desk asks "what aftercare do we give after a root canal?", the system retrieves the two relevant sections and the model writes a short answer quoting them, with file names. When the clinic edits a PDF, the index is rebuilt overnight and answers follow the new version.

Common mistakes

Bad chunking

Chunks that split tables or clauses hide the full fact. Chunk along headings.

Read more about Bad chunking

Splitting tables or clauses in half means the model never sees the full fact. Chunk along headings and keep tables whole.

No access control

Filter by user permissions at retrieval, or anyone can pull HR files.

Read more about No access control

If HR files share an index with sales notes, anyone can retrieve them. Filter by user permissions at retrieval time.

No evaluation set

Without real questions and correct answers, you cannot tell if a change helped.

Read more about No evaluation set

Without a fixed list of real questions and correct answers you cannot tell whether a change helped. See model evaluation.

Questions

Does RAG stop hallucination?

It reduces it a lot when retrieval finds the right passages, but it does not remove it. Ask the model to cite sources, tell it to say "not found" when the context is empty, and test with questions that have no answer in your documents.

RAG or fine-tuning: which do we need?

Use RAG when the model needs facts from your documents. Use fine-tuning when it needs a consistent style, format or narrow skill. Many production systems use RAG alone.

Can a RAG system run without sending documents to a cloud API?

Yes. The embedding model, vector database and LLM can all run on your own hardware. See private AI deployment.

Last updated