Building Agentic RAG Applications
Build a documentation assistant that answers from permitted, versioned sources. Learn retrieval, bounded agent decisions, service integration and evaluation through runnable examples.
How does the agent decide what to retrieve next?
A fixed RAG pipeline retrieves once before answering. A retrieval agent can inspect tool results and choose another search, read a passage, propose an answer, or stop. The model proposes actions; application code controls which tools may run and enforces the limits.
Agentic RAG: inspect passages, then choose the next action
When the run stops
These are alternative exits from the components above, not additional steps after the answer.
- 8Gemini agentStop without an answer when chosen.Stop or refuse
- 9Admit the actionRefuse invalid actions or exhausted budgets.Stop or refuse
- 10Search / read toolsStop on tool failure.Stop or refuse
- 11Check the answerReject invalid source IDs or quotes.Stop or refuse
- Assess the question and available observations.
- Propose a search or read action.
- Execute only an admitted tool call.
- Return the real tool result.
- Assess the retrieved passages before choosing again.
- Propose an answer when ready.
- Return an answer with valid source references.
- Stop without an answer when chosen.
- Refuse invalid actions or exhausted budgets.
- Stop on tool failure.
- Reject invalid source IDs or quotes.
The course separates fixed pipelines, scripted query policies and model-selected actions. Hybrid retrieval combines keyword and vector rankings; it is a retrieval method, not an agent by itself.
What you'll learn
- Trace RAG requests, replay saved replies and consume a real Gemini provider stream.
- Ingest and version documentation, then compare lexical, vector and hybrid retrieval.
- Choose source windows and fit them into a token-bounded request.
- Compare fixed, scripted and Gemini-selected retrieval policies, then expose search and read through HTTP and MCP.
- Apply collection permissions, caching, tracing and concurrency limits, then use task evaluations to control a local release.
Lessons
Module 1 · 2 lessons · about 31 minRAG fundamentals
Follow a question through retrieval, context assembly and an answer before adding agent decisions.
How RAG worksRead
Learn how an application searches documents, supplies relevant passages to a language model and links its answer to sources.
Trace a RAG request from search to answerRead
Follow a question through document search, context assembly and the model request, then check the answer’s source links.
Module 2 · 2 lessons · about 53 minDefine the task and baseline
Define representative questions and expected behavior, then record a fixed-pipeline baseline.
Build a RAG eval datasetRead
Define which questions your documents can answer and which passages support them. Keep documentation versions and evaluation splits separate.
Record a RAG baselineRead
Save a fixed RAG run before changing it. Compare retrieved passages and answer checks while keeping failures and missing responses visible.
Module 3 · 3 lessons · about 1 hourDocument ingestion
Read documentation into passages, retain source locations and report files that cannot be ingested.
Load developer documentationRead
Turn pinned local documentation files into text records. Reject changed inputs and keep each document’s identity, source link and version.
Track passage sourcesRead
Keep a passage tied to its exact source lines. Detect changed source files or altered passage text before displaying it.
Handle ingestion failuresRead
Continue loading valid documents when another source fails. Keep accepted text and failure reasons together, and mark incomplete batches.
Module 4 · 3 lessons · about 1 hourMaintain the corpus
Version indexed content, resume interrupted ingestion and apply document updates and deletions.
Version documents and chunksRead
Give document text, metadata and chunks their own revision identities. Compare a source-text edit with a metadata-only title change.
Resume document ingestionRead
Restart interrupted ingestion without skipping unfinished sources or duplicating completed chunks. Check stored content before trusting a checkpoint.
Update and delete indexed contentRead
Replace or remove document passages and their text-index entries together. Verify search results and roll back interrupted changes.
Module 5 · 3 lessons · about 1 hourRetrieval fundamentals
Compare keyword and vector matching, then enforce the same filters across both retrievers.
How BM25 ranks documentsRead
See how matching words and document lengths affect SQLite BM25 ranking. Inspect indexed terms and scores before interpreting a result.
Add vector retrievalRead
Search with saved text embeddings in a LangChain vector store. Inspect ranked passages and reject questions outside the recording.
Apply filters across retrieversRead
Apply the same documentation-version rule before choosing lexical and vector results. See why filtering after a result limit can lose useful passages.
Module 6 · 3 lessons · about 1 hourHybrid search and reranking
Combine retrieval results, rerank candidate passages and compare configurations on the same questions.
Build hybrid retrievalRead
Combine word-based and vector-search rankings without adding incompatible scores. Trace each passage’s contribution to the combined order.
Rerank retrieved passagesRead
Reorder retrieved passages with term coverage, Gemini and a cross-encoder. Compare their recorded rankings and the limits of each scorer.
Compare retrieval configurationsRead
Compare word-based, vector, hybrid and reranked search on the same questions and source targets. Inspect individual misses before averages.
Module 7 · 3 lessons · about 1 hourContext engineering
Choose passage boundaries, recover nearby text and fit selected context into a token budget.
Choose chunk boundariesRead
Compare character, paragraph and heading-based splits on one document. Check whether each chunk keeps an instruction with its qualifier.
Retrieve surrounding contextRead
Add nearby source text around selected passages, merge overlaps, and keep each window inside the same section and document revision.
Assemble context within a token budgetRead
Fit source windows, instructions and the question into a complete token-counted request. Reserve space for output and reject required-content overflow.
Module 8 · 2 lessons · about 50 minAnswer streaming and source conflicts
Stream answer text and handle passages that describe conflicting versions.
Stream RAG answersRead
Reconstruct complete replies from streamed data and check source references before accepting them. Compare saved replay with a recorded Gemini stream.
Handle conflicting documentationRead
Keep the requested documentation version, compare explicit source rules, and withhold an answer request when eligible claims conflict.
Module 9 · 5 lessons · about 2 hoursBounded retrieval policies
Expose search and read actions, bound repeated retrieval and compare scripted and model-selected decisions.
Add search and read toolsRead
Separate candidate search from reading source text. Bind each read to a result issued for the same request and document snapshot.
Refine queries with a scripted policyRead
Use a scripted policy to read a passage, refine its search query and decide when to stop. Keep each attempt and its stopping reason.
Bound scripted retrieval runsRead
Check search, read and source-byte allowances before running a scripted action. Distinguish denied calls from admitted calls that fail.
Compare fixed, scripted and Gemini retrieval policiesRead
Compare fixed, scripted and Gemini-selected retrieval on the same tasks. Check source reads separately from whether the controller finished.
Build a model-driven RAG agentRead
Let Gemini choose search, read, answer or stop actions. Enforce tool limits, check citations and compare the recorded results with fixed RAG.
Module 10 · 3 lessons · about 1 hourApplication integration
Serve retrieval over HTTP, inspect selected passages and expose the tools through MCP.
Serve the RAG application with FastAPIRead
Expose the retrieval core through FastAPI. Validate requests, return source traces and distinguish HTTP errors from limited retrieval runs.
Build a retrieval inspectorRead
Inspect retrieval decisions and source passages in a browser. Check response bytes and request identity before displaying the latest result.
Connect retrieval tools through MCPRead
Expose documentation search and reads through an MCP client and server. Discover tool schemas and keep issued passage handles in the same session.
Module 11 · 4 lessons · about 2 hoursRuntime controls
Authorize searches, cache results, trace requests and limit concurrent work.
Authorize collection searchesRead
Limit search and passage reads to collections the caller may access. Recheck identity and current permissions before returning source text.
Cache retrieval resultsRead
Reuse completed retrieval results only for matching callers, permissions and source snapshots. Expire old entries and skip failed or incomplete runs.
Trace RAG requestsRead
Follow each local retrieval execution through its operations. Separate concurrent attempts and keep questions, source text and credentials out of trace logs.
Limit concurrent RAG requestsRead
Limit active retrieval work and waiting requests. Inspect queue overflow, waiting deadlines and slot cleanup when a client cancels or times out.
Module 12 · 4 lessons · about 2 hoursEvaluation and local release checks
Evaluate corpus changes and retrieval tasks, then run local release checks and assemble the assistant.
Run RAG evals on an updated corpusRead
Compare retrieval before and after a document update. Reject stale target labels and keep deleted sources visible in the comparison.
Evaluate scripted retrieval tasksRead
Check whether fixed and scripted policies read their required passages. Separate execution checks, task outcomes and local release decisions.
Release the RAG applicationRead
Check a staged local retrieval service against its files, runtime behavior and task report. Preserve failed promotion and rollback results.
Build the developer knowledge assistantRead
Build a local documentation assistant with a browser UI and CLI. Connect version-aware search, collection permissions, source-linked answers and evaluation.