Introduction
Retrieval-augmented generation, or RAG, combines an information retrieval system with a generative model. The model receives relevant external context before answering. This often makes organization-specific questions more useful, but retrieval does not guarantee that an answer is correct.
This is a practical, documentation-led guide. Features, costs and compatibility can change; validate vendor documentation and test with a non-sensitive example before adopting a tool.
RAG in one example
Imagine a customer-support agent answering a question about an online store’s return policy. Instead of guessing, the system searches approved policy pages, returns the matching passages and asks the language model to answer only from those passages. The assistant should link to the correct policy version and say when it cannot find evidence.
How a basic RAG pipeline works
Ingestion prepares trusted documents; indexing stores searchable representations; retrieval selects candidate passages; optionally reranking improves relevance; generation drafts an answer using the retrieved context; and evaluation checks correctness and citations.
- Collect authorized documents and record their owner and version.
- Extract text and split documents into useful chunks.
- Create keyword and/or embedding-based search indexes.
- Retrieve candidate passages for a user query.
- Rerank or filter the results for relevance and permissions.
- Generate a response that cites retrieved source passages.
- Log failures and evaluate the result against known answers.
Keyword search, vectors and hybrid search
Keyword search is valuable for exact identifiers such as order numbers or product SKUs. Embedding-based retrieval is useful for semantically similar wording. Hybrid retrieval combines signals and is often more robust than choosing only one approach. Evaluate each against representative user questions.
Why chunking and metadata matter
A chunk that is too short may lose surrounding conditions; a chunk that is too long can mix unrelated policies and consume the model’s context window. Useful metadata includes document title, section, updated date, language, owner, permissions and canonical URL.
- Preserve headings with their paragraphs.
- Do not merge unrelated policy versions.
- Store source links and last-updated timestamps.
- Measure retrieval quality before tuning prompts.
Security: filter before retrieval
A RAG index is not an authorization system. If a user cannot read a confidential document in the source application, the retrieval service should not expose it through search snippets or model context. Enforce tenant isolation and permission-aware filtering server-side.
Evaluate evidence instead of fluent answers
Create a test set of real, anonymized questions with expected evidence. Measure whether the correct passage appears in the retrieved results, whether citations support the answer, whether the system appropriately refuses unsupported claims and how latency changes under load.
| Signal | Question |
|---|---|
| Retrieval relevance | Was the right document retrieved? |
| Groundedness | Do statements follow the passages? |
| Citation quality | Can a reader verify each important claim? |
| Coverage | Are common questions answerable? |
| Permission safety | Were unauthorized documents excluded? |
| Latency and cost | Can the service respond economically? |
Common failure modes
RAG can fail when source documents are outdated, a chunk loses its context, retrieval favors the wrong version, cited material does not prove an assertion, or adversarial instructions inside documents are treated as commands. Treat retrieved documents as untrusted reference data, not system instructions.
When RAG is not necessary
For a tiny set of stable rules, ordinary application logic or a structured database query may be more reliable. RAG is suited to questions requiring information from changing or numerous documents, not transactional tasks where exact database records and authorization are central.
FAQs
Does RAG train the model on my files? Not necessarily; retrieval can provide information at request time without model fine-tuning. Does RAG eliminate hallucinations? No. Can RAG use PDFs? Yes after appropriate parsing and validation. Is a vector database mandatory? No; lexical, hybrid and other search architectures are possible.
Research methodology and disclosure
This guide was prepared with reference to the official documentation linked below and reviewed on October 9, 2026. It does not claim hands-on comparative benchmarks, sponsored rankings or independent laboratory testing. Verify current versions, policies and prices before relying on them. Editorial image rights and attribution require owner confirmation.
Build the retrieval path deliberately
A useful RAG design usually has four separate concerns: ingest approved documents, split and index them, retrieve and rank candidates for a question, and generate an answer that identifies the evidence used. Microsoft describes chunking and embeddings as common indexing steps; the exact implementation depends on the data, query patterns, and access model.
- Attach source, version, owner, and permission metadata to each chunk.
- Test retrieval independently from answer writing.
- Return a source link or passage identifier when the product can safely do so.
- Set a fallback for weak evidence instead of forcing an answer.
Evaluate with questions that have known answers
Create a small evaluation set from current approved documents. Include answerable questions, ambiguous questions, questions that should be refused for access reasons, and questions where the material is missing. Review retrieved passages as well as the final response; a fluent answer is not evidence that retrieval worked.
Related reading: Comparing AI assistants without a universal winner, How AI affects software design work


