Black Friday50% off your first month on any monthly plan with EARLY50 See plans
All 29 lessons
  1. Foundations: what RAG is and a working pipeline

    1. 1. Getting started: what RAG is and when to use it
    2. 2. Types of RAG: a map from naive to agentic
    3. 3. Lab: build the smallest RAG pipeline end to end
    4. 4. How embeddings and vector search find meaning
    5. 5. Document types: what each one breaks, and how to prepare it
  2. Better retrieval: chunking and search

    1. 6. Chunking documents so answers survive
    2. 7. Chunking strategies compared: which to use when
    3. 8. Keyword search vs vector search, and fusing both
    4. 9. Retrieval algorithms compared: which to use when
    5. 10. Reranking the top results before the model reads them
    6. 11. Rewriting the question before you search
  3. Answers you can trust, measure and debug

    1. 12. Lab: grounded answers with citations and refusals
    2. 13. Measuring a RAG system with an evaluation set
    3. 14. Lab: evaluation methods and frameworks: Ragas and DeepEval
    4. 15. Troubleshooting a RAG system, symptom by symptom
  4. Production in a company

    1. 16. Access control: only retrieve what the user may see
    2. 17. Defending against prompt injection in retrieved text
    3. 18. Running RAG in production: freshness, cost and monitoring
    4. 19. Real-world RAG: what worked, what failed, and why
  5. Agentic RAG

    1. 20. Lab: from a fixed pipeline to an agent with a search tool
    2. 21. Self-correcting retrieval: grade, retry, fall back
    3. 22. GraphRAG and routing across many sources
    4. 23. Lab: numbers, tables and financial documents
  6. Frameworks: LangChain, LangGraph and LangSmith

    1. 24. The RAG toolbox: what each library does and why you import it
    2. 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
    3. 26. Lab: Ask Brightline in LangChain
    4. 27. Lab: agentic RAG as a LangGraph graph
    5. 28. Lab: tracing, evaluating and monitoring with LangSmith
    6. 29. Wrap-up: your production agentic RAG checklist
See the leaderboard

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?"

[4]

What GraphRAG builds

GraphRAG spends heavily at indexing time so global questions become cheap later. It has two stages:

  1. 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.
  2. 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.

[4]

The same global question, both ways

python
q = "What are the main reasons people contact IT?"
# Plain RAG: the top 3 tickets, then one answer
plain = llm(f"Tickets:\n{search_policies(q)}\n\nQuestion: {q}")
# GraphRAG-style: one partial answer per pre-written community summary, then combine
partials = [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))
COMMUNITY_SUMMARIES is the list GraphRAG writes at indexing time; search_policies is lesson 20's tool pointed at a ticket index. Assume 12 summaries: 14 model calls for the second answer.

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.

python
import sqlite3
db = 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"))
Expected output: [('vpn', 2), ('printer', 1), ('wifi', 1)]. The September ticket is excluded, as it should be.

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

python
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 default
print(route("How many VPN tickets did Denver open in October?"))
Expected output: tickets. Anything unexpected falls back to policies, the safest source.

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.

[14]

Match

Match each question to its source

Pick an item on the left, then its match on the right.

Worth keeping

  1. RAG answers local questions; global questions need corpus-wide summaries.
  2. GraphRAG pays a large indexing cost so global questions become cheap later.
  3. Counts and totals go to a database through fixed, read-only, parameterised tools.
  4. 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.

  1. [4]Edge et al. (2024), From Local to Global: A Graph RAG Approach
  2. [14]Microsoft Learn: RAG in Azure AI Search