This is a shorter version of a lesson from the AI Engineering course on Aced. The full lesson adds diagrams and a deeper walkthrough of each step.
A large language model answers from whatever it learned during training. That works for general questions, but it breaks down when you ask about something the model never saw, like your company's refund policy or a document that changed last week. Retrieval-augmented generation, or RAG, looks up the relevant information first and puts it in the prompt, so the model answers from the source instead of from memory.
A useful way to picture it is a chef. Without RAG, the chef cooks from memory and sometimes gets a dish confidently wrong. With RAG, you hand the chef the recipe card before they start cooking.
To keep this concrete, we use one running example: a chat agent that answers your company's support-policy questions, such as "Can I return an item after 30 days?"
The two paths
Every RAG system has two halves that run at different times.
The retrieval path runs when a user asks a question. The system searches your knowledge base for passages related to the question, adds the best matches to the prompt, and asks the model to answer using them.
The storage path runs ahead of time, whenever your documents change. It prepares the knowledge base so the retrieval path has something fast and relevant to search, which is like stocking the pantry before service starts.
The retrieval path: traditional vs. agentic
In traditional RAG, retrieval happens once. The user's question goes to the search step, the top few passages come back, and the model writes its answer from them. This is simple and predictable, and it handles most single-fact questions well.
In agentic RAG, the model decides what to look up, and it can search more than once. If the first results mention a "holiday return window" without defining it, the model can run a second search for that term before it answers. In the kitchen analogy, this is sending the chef to the grocery store, where they can find a substitute when an ingredient is missing. You get better answers on multi-part questions, at the cost of more latency, more tokens and behavior that is harder to predict.
The storage path, step by step
- Chunk. Split each document into passages small enough that several fit in one prompt, but large enough to keep their meaning. A whole policy handbook is too big for a chunk, and a single sentence usually loses its context.
- Embed. Run each chunk through an embedding model, which turns text into a vector of numbers so that passages with similar meanings end up close together.
- Index. Store those vectors in a vector index, so you can find the nearest neighbors of a question's vector quickly, even across millions of chunks.
- Retrieve with hybrid search. Vector search alone can miss exact terms like product SKUs or policy codes, so most production systems combine it with keyword search and merge the two result lists.
Semantic caching
Many users ask the same question in different words. A semantic cache stores past questions with their answers and returns a cached answer when a new question's embedding is close enough to an old one, which saves a model call. The tradeoff is freshness: when the return policy changes, you need to clear the cached answers along with the index.
What it means for you
If you build products, RAG is often the cheapest way to make a model accurate about your own data without fine-tuning, and your main decisions are what goes into the knowledge base and how fresh it needs to be. If you build agents, the interesting choices are on the retrieval path: when to search once versus letting the model search repeatedly, and how to measure whether the retrieved passages actually support the answer.
The full RAG lesson on Aced walks through each step with diagrams, and the course continues with lessons on evaluating generative AI and MCP.

