Retrieval-Augmented Generation (RAG) in depth
How a RAG system works, step by step
RAG has two halves: preparing your knowledge so it can be searched, and using it at question time.
Indexing (done ahead of time):
- Collect sources: PDFs, wiki pages, help articles, tickets, database records.
- Extract clean text, including tables, using OCR for scans.
- Split into passages through chunking, keeping headings and metadata such as source, date and access group.
- Convert each passage to embeddings and store them in a vector database, often alongside a keyword index.
Answering (at request time):
- Rewrite the user's question if needed, for example to resolve "it" from earlier turns.
- Retrieve candidates with hybrid search, filtered to what this user may see.
- Apply reranking and keep the best few passages.
- Ask the LLM to answer only from those passages and cite them.
- Return the answer with links to sources, or say the information is not available.
Example: a dealer support assistant
Example: an equipment manufacturer's dealers ask about warranty terms, spare part numbers and service procedures, in English and Hindi. Manuals, bulletins and the warranty policy are indexed, each passage tagged with product line and validity dates. When a dealer asks whether a pump model's seal is covered after 14 months, the assistant retrieves the current warranty clause and the model's bulletin, answers with the relevant clause cited, and notes any condition, such as proof of installation date. If the documents do not cover the question, it says so and offers to raise a ticket. Superseded bulletins are excluded by date filters, so old answers do not resurface.
Evaluating RAG
Evaluate retrieval and generation separately, then together:
| Layer | Measures |
|---|
| Retrieval | Recall at k: is the right passage retrieved for each test question? |
| Generation | Faithfulness: is every claim supported by the passages? Relevance: does it answer the question? |
| End to end | Correct, complete answers on a labeled question set; correct "not found" responses |
| Operations | Latency, tokens per answer, index freshness |
Build the question set from real user questions, including ones the documents cannot answer. Faithfulness can be scored at scale with an LLM judge validated against people. Our document Q&A tool shows grounded answers with sources on sample files.
Common mistakes
- Ignoring permissions, so the assistant shows content a user could not open directly.
- Poor text extraction from PDFs and tables, which no model can fix later.
- Stale indexes after documents change, and no date or version metadata.
- Only vector search, which misses part numbers and codes that keyword search finds.
- No "I don't know" path, which pushes the model toward hallucination.
RAG versus fine-tuning, and what comes next
RAG supplies facts at request time and keeps them current; fine-tuning changes behavior, style or format. Most knowledge assistants need RAG, and some add fine-tuning later. Variants include agentic RAG, where an agent decides which sources to search and when, and graph-based retrieval using a knowledge graph. RAG is the main technique behind grounding. Gepton builds RAG systems in AI-powered search and knowledge management agents; see also the knowledge management solution.