RAG & Data Pipelines · 90 minutes
Explain retrieval vs. generation
Explain how documents become evidence for a generated answer, and why an answer can be wrong even when it cites a real document.
1.5 h
Used in interview rounds:
Technical Screen (Easy)Debugging & Evaluation (Easy)AI System Design (Easy)Overview
Understand how external documents become evidence for a generated answer.
Study time: 90 minutes
Interview format: Conceptual screen with a source-grounding exercise
By the end you can
- Distinguish retrieval from generation
- Explain the ingestion and query paths
- Identify the purpose of chunks and metadata
- Recognize unsupported answers even when they contain citations
This topic covers ingestion, grounding, citations, and the document lifecycle. Embeddings & Retrieval covers how candidates are found and ranked.
What RAG does
Retrieval-augmented generation supplies selected external information to a model while it answers a request. For example, a support assistant can search a company's current policy documents and include relevant passages in the model's context.
The retrieval component selects evidence. The generation component produces an answer using its instructions and available context. Either component can fail independently. Relevant evidence can be missing, or a generator can misinterpret evidence that was correctly retrieved.
Adding a document to a retrieval index normally does not update the language model's weights. It changes the material available to the application at inference time. This makes document updates possible without retraining the generator, provided the ingestion pipeline actually processes those updates.
Two paths through the system
| Path | Typical stages | Result |
|---|---|---|
| Ingestion | Collect, parse, normalize, chunk, attach metadata, index, publish | Searchable document representations |
| Query | Authenticate, retrieve eligible evidence, assemble context, generate, validate, display | Answer with supporting references or a defined no-answer result |
Ingestion often runs asynchronously. A successful upload does not necessarily mean the document is searchable. The application should distinguish accepted, processing, failed, and published states.
At query time, the current user and access scope influence which documents are eligible. The model should receive only evidence the application is authorized to use for that request.
Parsing and normalization
Parsing extracts usable content from formats such as HTML, Markdown, PDFs, or office documents. Some PDFs contain selectable text, while scanned pages may require OCR. Extraction quality matters because missing rows or reordered text can change meaning before retrieval begins.
Normalization can remove repeated navigation and headers or standardize whitespace. It should preserve meaningful structure such as headings, table labels, units, and exceptions. Keep a reference to the original source so a generated claim can be checked against it.
For example, extracting a pricing table without its column headers can turn an accurate source into ambiguous text. The retrieval system cannot reliably recover structure that the parser discarded.
Chunking preserves useful units
A chunk is a searchable portion of a document. Splitting long sources can make retrieval more precise and keep model inputs within limits. Useful boundaries often follow sections, paragraphs, tables, or code blocks.
Very small chunks may lose the subject or exception that gives a sentence meaning. Very large chunks can mix several topics and consume context capacity. Overlap can preserve continuity across boundaries, but increases duplicate content and indexing work.
There is no universal chunk size that works best for every corpus. Compare strategies using the questions the application should answer. A policy exception should remain connected to the rule it qualifies, or be recoverable through linked neighboring content.
Metadata and provenance
| Field | Purpose |
|---|---|
| tenant_id | Identify the organization that owns the content |
| document_id | Identify the logical source across revisions |
| revision_id | Identify the specific source version |
| chunk_id | Identify a searchable passage |
| title and section | Help retrieval and readers interpret the passage |
| locator | Resolve a page, section, or source position |
| access metadata | Restrict eligible users or groups |
| processing state | Distinguish staged, published, and retired content |
Provenance describes where a piece of information came from and how it was derived. A chunk should resolve to a particular source revision, not merely a title that may later refer to different text.
Metadata errors can make a correct passage invisible or expose it to the wrong audience. Metadata is part of the pipeline's correctness, not decoration for the UI.
Assemble context deliberately
After retrieval, the application selects passages for the prompt. It may deduplicate overlapping text, include neighboring context, and assign short source labels such as S1 and S2. It must reserve room for instructions, the question, and the response under the model's accounting rules.
The highest-ranked passage alone may not answer every part of a question. A refund question may require both a standard window and an exception clause. Context selection should preserve the facts needed to answer the whole request.
Retrieved text is source data. A document containing “ignore all previous instructions” does not gain authority to change application policy. Security & Privacy covers these attacks in greater depth.
Grounding and citations
A grounded answer is supported by the evidence used for the task. Citations help readers locate that evidence. A valid-looking citation does not establish that the cited passage supports the claim.
Check three separate properties. Does the citation identify a source actually supplied to the model? Does the source resolve to the right revision and location? Does its content support the associated claim?
The application should build citation links from trusted source mappings rather than trust arbitrary model-generated URLs. Citation access should obey the same permission rules as the source itself.
Worked policy example: two excerpts
Worked example
The following excerpts are fictional.
S1: Returns policy, revision 3, section 1
Unused standard products may be returned within 30 days of delivery.
S2: Returns policy, revision 3, section 2
Custom-printed products are excluded from the standard return window. Report manufacturing defects within 7 days of delivery for review.
Answer a question from the excerpts
Worked example
Question Can I return a custom-printed product after 20 days because I changed my mind?
Supported answer The supplied policy excludes custom-printed products from the standard return window, so it does not support a change-of-mind return after 20 days. The defect-reporting provision concerns manufacturing defects reported within 7 days. Cite S2 for both statements.
Unsupported answer You can return any product within 30 days. This generalizes S1 while ignoring the exception in S2.
Unanswerable follow-up How much does return shipping cost? Neither excerpt gives that information. The assistant should state that the supplied policy does not specify it and offer the application's supported next step.
Updates and deletion
A source may change after it is indexed. The system needs a way to associate new chunks with the new revision and stop using obsolete chunks for current-policy questions.
Deleting a source also affects derived chunks, embeddings, caches, and citation links. Hiding the upload from a list does not necessarily remove its content from retrieval. The Hard guide develops a lifecycle that handles these relationships explicitly.
Evaluate stages separately
If a response is wrong, first inspect whether the necessary evidence was available to the generator. If S2 was never parsed or retrieved, improve the data or retrieval path. If S2 was present but ignored, investigate context construction and generation behavior.
A useful small evaluation set includes directly answerable questions, questions requiring multiple passages, conflicting versions, and questions whose answers are absent. Measure evidence availability and answer support separately.
Completion checklist
- Trace a source from upload to answer evidence.
- Explain why upload acceptance differs from publication.
- Identify which excerpt supports each policy claim.
- Recognize an unanswerable question without inventing a policy.
- Explain why revisions, metadata, and deletion affect correctness.
Sources
- Microsoft RAG overview Describes combining retrieval with generation.
- Microsoft RAG design and evaluation guide Provides architecture and evaluation background.
- Azure document chunking guidance Discusses dividing documents into searchable units.
- Azure document-level access overview Describes access-aware retrieval patterns.
- Anthropic contextual retrieval Discusses supplying document context to otherwise isolated chunks.
The policy excerpts, traces, implementation exercises, targets, and rubrics are original synthetic teaching material. They describe a fictional application. Study times and readiness thresholds are editorial estimates. Provider-specific implementations must be checked against the selected service's current documentation.
Related on CodeSnatch
Lessons, problems, and articles that build the skills this question uses.
Community article
Draws the full pipeline and shows how chunk boundaries and unchecked citations go wrong once real users arrive.
AI Engineering
Builds on this question: use a trace to tell whether retrieval, packing, or generation caused a wrong answer.
AI Engineering
Contrasts retrieval with prompting and fine-tuning, so you can explain when new documents call for RAG instead.
System Design
Introduces raw and staging layers and repeatable ingestion, a frame for the path from upload to searchable chunks.
Practice the interview question
Answer it in your own words before you look at the reference answer.
