Skip to main content
Back to Blog

RAG, the retrieve-then-write workflow

Ria can search permitted records in the archive. Lex can draft from material assembled on the desk.

Fernando Torres

CEO & Cofounder, Memori · Stanford GSB MSx ’26 ·

Ria can search permitted records in the archive. Lex can draft from material assembled on the desk. Put those product stages together and you get retrieval-augmented generation: retrieve candidate evidence, assemble selected excerpts into the request, then generate. The evidence can ground an answer, but it cannot guarantee that the answer is correct.

Retrieval systems search permitted sources and return candidates for the application to rank and select. The selected evidence must enter the context window, the bounded input assembled for one model call. Relevance scoring estimates how well each candidate matches the request, but a high score is not proof.

Ava is at the desk with Lex. She has her coffee mug ("again?") and a serious expression. The desk has a few sticky notes from the current conversation but no reference documents. Lex looks ready to work but has nothing to reference. Emotional beat: a task that needs more than what is on the desk.
Panel 1 transcript: Ava: "Write me a summary of the Q3 results and compare them to the targets we set. I need it grounded in the actual numbers."
Lex looks at his desk. Only the current question is on it. He does not have the Q3 results or the original targets. Emotional beat: honest limitation and a useful abstention.
Panel 2 transcript: Lex: "Those sources are not in this request. Without them, I should not invent the comparison."
Ria stays at the archive wall and reviews an authorized candidate set: "Q3 Results," "Q3 Targets," and a dimmed "Q3 Targets , prior year." She selects the two current records, attaches source and date labels, and sends them through a retrieval tray. Multiple curved orange arrows trace the route toward the desk. Emotional beat: retrieval is selection, not certainty.
Panel 3 transcript: Ria: "Candidate set found. Sending the two current sources with labels and dates."
Back at the desk, Lex and Ava receive the labeled excerpts through the retrieval tray. Ria remains in the archive. Lex now has the question, two source cards, and their excerpts in the current request. The desk meter stays moderate. Emotional beat: evidence is available, with provenance intact.
Panel 4 transcript: Lex: "I have the labeled excerpts. I will compare them, cite them, and flag any conflict."
Lex slides a cited comparison to Ava. Ava follows both citations back to the source cards and checks the figures. The desk shows the question, retrieved excerpts, citations, and draft. Emotional beat: earned confidence after validation.
Panel 5 transcript: Ava: "The citations check out against both reports." Lex: "Retrieval gave me evidence, not a guarantee. We still verified it."

Problem: The current model request lacks the records needed for a grounded comparison.

Resolution: The product's retrieval layer searches permitted sources, assembles labeled excerpts into the request, and lets Lex draft with citations or abstain when evidence is insufficient. Ava still verifies the result.

Module B: Retrieval Route (complete). Show a five-stage teaching model from left to right. Stage 1: "Permitted sources" shows the archive with access marks.

RAG can ground a model response in retrieved evidence. It does not guarantee relevance, safety, or correctness, so production workflows preserve provenance, enforce access, support abstention, and verify important claims.

Section 1: The problem with writing from nothing

For one model call, Lex can use only the material assembled on the desk plus learned patterns from training. If the current request lacks the Q3 records, a response cannot cite or compare those records faithfully. Depending on the model, instructions, and product behavior, Lex might answer from learned patterns, state that the evidence is missing, ask for a source, or abstain. None of those behaviors should be assumed automatically.

This is the boundary between a generation model and the application around it. The model does not independently browse a product's files. An application can add tools, retrieval, source labels, and validation before and after a model call. The desk represents that assembled request, not every piece of information stored by the product.

Retrieval matters because it can put task-specific evidence into that request. But "retrieved" does not mean "true." A wrong, stale, incomplete, conflicting, or malicious source can still produce a fluent, well-grounded-looking error.

Section 2: Retrieve first, then write

RAG stands for retrieval-augmented generation. A typical workflow searches permitted sources, returns a candidate set, orders candidates, selects excerpts, and assembles them with the task for generation. Implementations differ, and many combine several search signals, metadata filters, and closer review.

Scores estimate relevance. They do not prove it. A robust context builder therefore keeps source identity, date, version, and access metadata attached to selected excerpts. Lex can cite that evidence while drafting, flag conflicts, or abstain when the candidate set does not support the requested claim. Ava can then follow the citations and validate the important numbers.

Ria and Lex represent separate application responsibilities. Ria stays at the archive and sends an authorized, labeled selection through the retrieval route. Lex receives only what the product puts into the current request. Retrieval augments generation. It does not merge the model with the archive or give the model unrestricted storage access.

Section 3: The pipeline has limits

Every stage can fail. Access filters can be too broad. Search can miss the needed record. Ranking can favor a stale or merely similar candidate. Context assembly can cut away a qualifier. Generation can misread or contradict good evidence. Even a citation can point to a source that does not support the sentence beside it. Important workflows need evaluation and claim-level verification, not just a retrieval success signal.

Retrieved text is also untrusted data. A document can contain hostile instructions intended to redirect the model. The application should separate task instructions from retrieved content, constrain tool permissions, preserve provenance, and treat source text as evidence rather than authority. RAG is not a prompt-injection defense.

For the next lesson, our deliberately simple search compares shared words. It may rank "marketing budget" for "marketing brief" because the word "marketing" overlaps. The mismatch exposes the central question: can a search compare meaning as well as words?

Glossary

RAG
Retrieval-augmented generation: a family of workflows that retrieves candidate evidence and includes selected material in a model request before or during generation. It can improve grounding but does not guarantee correctness. | Office analogy: Ria sends labeled evidence through the route. Lex drafts and cites it. | Example: A support product retrieves permitted knowledge-base passages before drafting a reply.
Retrieval + generation pipeline
This lesson's five-stage model: (1) permitted sources, (2) candidate search, (3) rank and select, (4) context assembly, and (5) draft and check. Production pipelines vary. | Office analogy: The Retrieval Route connects the archive to the desk without moving either worker. | Example: A research tool searches a corpus, reranks passages, attaches source labels, drafts an answer, and exposes citations for review.
Retrieval systems
Product mechanisms that search permitted sources and return candidates for context assembly. | (origin: P03-E02)
Relevance scoring
Estimating and ranking how well candidates match a request. A high score is not proof of truth, recency, or sufficiency. | (origin: P03-E02)
Context window
The bounded input and generated sequence available to a model call, represented here by the desk. Product storage remains outside it. | (origin: P01-E01)

Try it yourself

  1. When an AI product cites external material, follow one claim to its source. Does the cited passage actually support the claim, and is its date and version visible?
  2. Compare an answer with and without a supplied source. A source may make the answer more specific, but check whether it also makes the answer correct. Presence in context is not validation.
  3. When retrieval fails, locate the stage: permissions, search, ranking, excerpt selection, context assembly, generation, or citation. "RAG failed" is less useful than naming the failed stage.

Next episode

At the archive, Ria says, "Marketing budget. The shared word pushed it to the top." Ava replies, "It found a candidate. Just not the source I meant." Next phase: how can retrieval compare meaning as well as words?