Large language models know a lot about the world, but nothing about your company’s internal processes, products or private documents. When asked about things outside their training data, they may produce answers that sound convincing but are made up. RAG (Retrieval-Augmented Generation) is the most common technique for addressing this.

The core idea

Instead of letting the model answer from memory, we first search for the most relevant document passages, put them into the context, and ask the model to answer only from those passages, citing its sources.

Basic architecture

  1. Ingest – collect documents (PDF, Word, wikis, email, databases…).
  2. Chunk – split documents into meaningful passages, usually a few hundred words.
  3. Embed – turn each passage into a vector that captures its meaning and store it in a vector database.
  4. Retrieve – for each question, find the closest passages (often combining keyword and semantic search).
  5. Generate – pass the question and retrieved passages to the LLM and ask for an answer with citations.
Question ──► Retrieve (vector + keyword) ──► Top-k passages
                                                  │
                                                  ▼
                       LLM: "Use only the information below…" ──► Answer + sources

Common mistakes

  • Careless chunking – splitting in the middle of tables or sentences loses context. Chunk along the document’s structure (headings, sections).
  • Relying on vector search alone – product codes, contract numbers and names are often found better by keywords. Combine both (hybrid search).
  • Ignoring permissions – users should only get answers from documents they are allowed to see.
  • No evaluation – keep a set of sample questions with expected answers to measure accuracy after every change.
  • Stale data – set up a process to re-index documents when they change.

When is RAG a good fit?

RAG fits when the knowledge you need lives in documents and changes often: internal policies, product guides, technical records, FAQs… If you need the model to change its output style or format, better prompting or fine-tuning may be more appropriate.

A good RAG system is more than “plugging an LLM into a document store”. Quality comes from clean data, the right retrieval strategy and continuous evaluation.