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.
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 | Good at | Risk |
|---|---|---|
| Small (1 sentence) | Precise matches, cheap prompts | Loses context: “it” and “this” lose their meaning |
| Medium (a paragraph) | The usual sweet spot | Needs tuning per document type |
| Large (a page) | Keeps context together | Dilutes 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.
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.31Making answers reliable
- Cite sourcesEvery answer links the chunks it used, so people can check.
- Say “I don’t know”If nothing scores high enough, the assistant says so instead of guessing.
- Hybrid searchCombine keyword and embedding search: exact terms like invoice numbers still match.
- RerankA second, slower model re-orders the top 20 results before the best few reach the prompt.
- EvaluateKeep a set of real questions with known answers and test after every change.