Guide 3 of 6RAG: answering from your documents
  1. Anatomy of an automation
  2. How AI agents work
  3. RAG: answering from your documents
    1. The problem RAG solves
    2. Try the retrieval step
    3. Chunking decides quality
    4. Embeddings in plain English
    5. Making answers reliable
  4. MCP: connecting AI to tools
  5. Guardrails, review and evals
  6. How a project runs

Core concept3 min readUpdated

RAG: how AI answers from your documents

Chunking, embeddings, retrieval and citations, with a retrieval demo you can tune.

Includes an interactive demo: Live retrieval

The problem RAG solves

A model only knows what it was trained on. It has never seen your refund policy, your price list or last week’s meeting notes. Retrieval-augmented generation (RAG) fixes that: before answering, the system finds the relevant passages in your documents and puts them in the prompt, so the model answers from your facts and can cite them.

Try the retrieval step

This demo runs the retrieval step on a short billing policy, in your browser. Change the chunk size and ask something: the top two chunks are what would be sent to the model.

InteractiveChunk a document and retrievePick a chunk size, then a question

Refunds are available within 30 days of purchase for annual plans. Monthly plans can be cancelled anytime, but the current month is not refunded. To request a refund, email billing with your invoice number. Refunds are processed within 5 business days to the original payment method. Enterprise contracts follow the terms in the signed order form. Plan upgrades take effect immediately and are prorated. Downgrades take effect at the next renewal date. Invoices are emailed on the first day of each billing cycle. Failed payments are retried three times over seven days. After the final failed retry the account is paused, not deleted.

This demo scores chunks by shared words (TF-IDF). Production systems use embeddings, which also match meaning: “money back” finds “refund”. The RAG Simulator goes further.

Chunking decides quality

Chunk size trade-offs
Chunk sizeGood atRisk
Small (1 sentence)Precise matches, cheap promptsLoses context: “it” and “this” lose their meaning
Medium (a paragraph)The usual sweet spotNeeds tuning per document type
Large (a page)Keeps context togetherDilutes relevance, costs more tokens

Overlap, carrying the last sentence of one chunk into the next, protects answers that sit on a boundary. Splitting on real structure (headings, list items, table rows) beats splitting every N characters.

Embeddings in plain English

An embedding model turns text into a long list of numbers, a point in space, where similar meaning lands close together. “Refund” and “money back” end up near each other even though they share no words. Search then becomes “find the nearest points to the question”, measured with cosine similarity.

Illustrative similarity scorestext
similarity("How do I get my money back?", "Refunds are available within 30 days")  ->  0.82
similarity("How do I get my money back?", "Invoices are emailed on the first day")   ->  0.31

Making answers reliable

  1. Cite sourcesEvery answer links the chunks it used, so people can check.
  2. Say “I don’t know”If nothing scores high enough, the assistant says so instead of guessing.
  3. Hybrid searchCombine keyword and embedding search: exact terms like invoice numbers still match.
  4. RerankA second, slower model re-orders the top 20 results before the best few reach the prompt.
  5. EvaluateKeep a set of real questions with known answers and test after every change.