All 29 lessons
Foundations: what RAG is and a working pipeline
Better retrieval: chunking and search
Answers you can trust, measure and debug
Production in a company
Agentic RAG
Frameworks: LangChain, LangGraph and LangSmith
- 24. The RAG toolbox: what each library does and why you import it
- 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
- 26. Lab: Ask Brightline in LangChain
- 27. Lab: agentic RAG as a LangGraph graph
- 28. Lab: tracing, evaluating and monitoring with LangSmith
- 29. Wrap-up: your production agentic RAG checklist
15 min
GraphRAG and routing across many sources
Decide when a knowledge graph, a database query or plain retrieval answers a question best, and route to it.
By the end of this lesson you can
- Tell a local question from a global question over a whole corpus
- Explain what GraphRAG builds up front and when it's worth the cost
- Route each question to documents, a database or corpus-wide summaries
From earlier lessons · 1 of 2
Search returns three near-miss passages. What should the corrective agent do first?
Pick one answer.
From earlier lessons · 2 of 2
Why check the final answer even after grading the passages?
Pick one answer.
Brightline's IT lead asks Ask Brightline: "What are the main reasons people contact IT?" It retrieves three tickets, all about VPN tokens, and answers "mostly VPN problems". The real answer, across 40,000 tickets, is password resets.
Local questions and global questions
Every question so far was local: its answer sits in one or a few chunks. RAG is built for those. A global question asks about the whole corpus, such as main themes, most common causes or how something changed over the year. No three chunks contain that answer, so top-k retrieval returns a biased sample and the model generalises from it.
The GraphRAG paper (Edge et al., 2024) names this failure directly. Standard RAG fails on global questions aimed at an entire text corpus, such as "What are the main themes in the dataset?"
What GraphRAG builds
GraphRAG spends heavily at indexing time so global questions become cheap later. It has two stages:
- Build a graph. A model reads every document and extracts entities (people, systems, offices, error codes) and the relations between them. That forms a knowledge graph.
- Summarise communities. Closely connected entities are grouped into communities, and a model writes a summary of each one ahead of time.
At question time, each community summary produces a partial answer, and those partial answers are combined into the final one.
The same global question, both ways
q = "What are the main reasons people contact IT?"# Plain RAG: the top 3 tickets, then one answerplain = llm(f"Tickets:\n{search_policies(q)}\n\nQuestion: {q}")# GraphRAG-style: one partial answer per pre-written community summary, then combinepartials = [llm(f"Community summary:\n{s}\n\nAnswer from this summary only: {q}")for s in COMMUNITY_SUMMARIES]combined = llm("Combine these partial answers into one ranked list:\n" + "\n".join(partials))
The plain answer reflects whichever three tickets happened to rank first. The combined answer draws on summaries that together cover every ticket, so it can rank password resets above VPN problems.
That coverage has a cost. A model must read the entire corpus to build the graph and write the summaries, which costs far more than embedding it. Re-indexing a changing corpus costs that again. Pick GraphRAG when global questions are frequent and the corpus is large and fairly stable, as with incident reports, research archives or years of support tickets. For policy lookups, plain RAG is cheaper and just as good.
Take a guess
An employee asks: "How many VPN tickets did the Denver office open in October?" Where should Ask Brightline send it?
No pressure. Guess now, and the lesson will show you if you were right.
Structured questions go to a database
Give the agent a small, fixed query tool instead of letting it write free-form SQL. Parameters keep the input out of the SQL text, and the tool can only ever read.
import sqlite3db = sqlite3.connect(":memory:")db.execute("CREATE TABLE tickets (office TEXT, category TEXT, opened TEXT)")db.executemany("INSERT INTO tickets VALUES (?, ?, ?)", [("Denver", "vpn", "2026-10-03"), ("Denver", "vpn", "2026-10-11"),("Denver", "printer", "2026-10-12"), ("Boston", "vpn", "2026-10-05"),("Denver", "wifi", "2026-10-20"), ("Denver", "vpn", "2026-09-28"),])def ticket_counts(office, since):rows = db.execute("SELECT category, COUNT(*) FROM tickets WHERE office = ? AND opened >= ? ""GROUP BY category ORDER BY COUNT(*) DESC, category", (office, since))return rows.fetchall()print(ticket_counts("Denver", "2026-10-01"))
Text-to-SQL, where the model writes the query itself, is more flexible and much riskier. If you use it, connect with a read-only account limited to specific tables, cap the rows returned and log every query. A few fixed tools like ticket_counts cover most real questions more safely.
A router in front of the sources
ROUTES = {"policies": "rules, limits and how-to steps from policy documents","tickets": "counts, totals and trends from the IT ticket database","themes": "broad themes or summaries across many documents",}def route(question):options = "\n".join(f"- {name}: {use}" for name, use in ROUTES.items())choice = llm(f"Pick the one best source.\n{options}\n\nQuestion: {question}\n""Reply with the source name only.").strip()return choice if choice in ROUTES else "policies" # safe defaultprint(route("How many VPN tickets did Denver open in October?"))
Query routing is a small classification step: one cheap model call, then the right tool. In the agent from lesson 20 you can skip the router and give the model all three tools with clear descriptions. The descriptions then do the routing.
Managed services now package this. Azure AI Search's agentic retrieval uses a model to split a question into focused subqueries. It runs them in parallel across several knowledge sources and keeps each source's permissions. The design questions are the same ones this course covered.
Match
Match each question to its source
Pick an item on the left, then its match on the right.
Worth keeping
- RAG answers local questions; global questions need corpus-wide summaries.
- GraphRAG pays a large indexing cost so global questions become cheap later.
- Counts and totals go to a database through fixed, read-only, parameterised tools.
- Route with one cheap call, or let clear tool descriptions route inside the agent.
Routing sends counts to a database. But a CFO asks Ask Brightline for revenue growth between two quarterly reports, and the numbers sit inside PDF tables. Next lab shows why basic RAG gets that maths wrong, and how finance teams fix it.
Leaderboard
Loading…
50 XP for each lesson you finish, 10 for each right answer. Names show only for learners who turn on Show me on leaderboards.
Sources for this lesson (2)
Each fact in the lesson is marked with the number of the page it comes from.