4 Topics
Chapter•60 Minutes

10. Advanced RAG Patterns

Use query routing, parent-child retrieval, graph retrieval, and structured-data integration when justified by evaluation.

Query Routing Across Sources

A knowledge assistant may search product docs, policies, tickets, API schemas, and databases. Routing chooses the right retrieval path. Use deterministic rules for clear cases and model-based routing only when ambiguity justifies it. Each route needs permissions, timeouts, and an output contract. A router must not select a corpus the user cannot access.

Log the selected route and evaluate routing separately: a retriever may work correctly against the wrong corpus.

Implementation example
function route(q) {
 if (/refund|return policy/i.test(q)) return "approved-policies";
 if (/stack trace|error code/i.test(q)) return "engineering-docs";
 return "general-kb";
}
💡 These rules are illustrative; production routing needs ambiguity handling and ACL checks.
Key Takeaways
  • Inspect the relevant pipeline stage instead of guessing.
  • Preserve source provenance, versions, and access scope.
  • Measure quality on representative queries.
Knowledge Check

Why evaluate routing separately?

Parent-Child and Multi-Vector Retrieval

Small child chunks can be indexed for precise matching while a larger parent section is returned for context. Multi-vector systems can represent titles, tables, text, or image descriptions separately. Preserve lineage and remove duplicate representations during retrieval. Every derived vector must be updated and deleted with its source.

These patterns add complexity and should be adopted when they address measured failures such as missing table context.

Implementation example
Search child chunks -> resolve parent section -> expand selectively
 -> deduplicate -> generate with original source citations
💡 Derived representations need source IDs and consistent lifecycle operations.
Key Takeaways
  • Inspect the relevant pipeline stage instead of guessing.
  • Preserve source provenance, versions, and access scope.
  • Measure quality on representative queries.
Knowledge Check

What must happen when a source with multiple vectors is deleted?

Knowledge Graph and Graph-Augmented Retrieval

Graphs represent entities and relationships such as product→dependency→platform. They help with relationship-heavy and multi-hop questions. Relations extracted by models need validation and provenance. Graph traversal must obey access controls, and edges may need validity periods. Graph RAG adds modeling and maintenance cost; compare it against hybrid retrieval first.

Implementation example
{
 "subject":"Service A",
 "predicate":"depends_on",
 "object":"Runtime B",
 "sourceId":"architecture-doc-12",
 "reviewStatus":"verified"
}
💡 Store provenance and review state for extracted relations.
Key Takeaways
  • Inspect the relevant pipeline stage instead of guessing.
  • Preserve source provenance, versions, and access scope.
  • Measure quality on representative queries.
Knowledge Check

When is graph retrieval especially useful?

Combining RAG with SQL and APIs

Many questions require exact structured values plus an explanation. Fetch current order status from an authorized API, then retrieve policies or troubleshooting documents for context. Do not execute arbitrary model-generated SQL with broad credentials. Use typed tools, parameterized queries, read-only roles, row limits, and validation.

Keep structured data timestamps and document citations distinct in the final answer.

Implementation example
Question -> authorized order API -> exact status
         -> document retrieval -> explanation
         -> combine with provenance and timestamps
💡 Use the right retrieval method for each evidence type.
Key Takeaways
  • Inspect the relevant pipeline stage instead of guessing.
  • Preserve source provenance, versions, and access scope.
  • Measure quality on representative queries.
Knowledge Check

Where should current order status come from?