02. Graph RAG¶
Category: Advanced RAG Architecture
Module: Part V β Advanced Retrieval-Augmented Generation
Difficulty: Advanced
π Overview¶
Traditional RAG primarily retrieves documents or chunks based on semantic similarity.
For example:
This works well when the answer is contained within one or a few semantically similar passages.
However, many enterprise questions are not simple document lookups.
Consider:
"Which customers are affected by the systems
that depend on the payment service currently
using the deprecated authentication component?"
Answering this may require traversing relationships:
Customer
β
Uses
β
Application
β
Depends On
β
Payment Service
β
Uses
β
Authentication Component
β
Deprecated
A vector similarity search may retrieve relevant documents, but it does not inherently understand this relationship structure.
Graph RAG combines:
to answer questions that require understanding entities and their relationships.
π― Learning Objectives¶
After completing this chapter, you will be able to:
- Understand Graph RAG
- Understand why traditional vector RAG can struggle with relationship-heavy questions
- Understand knowledge graphs
- Understand nodes, edges, and properties
- Understand graph construction
- Understand entity extraction
- Understand relationship extraction
- Understand entity resolution
- Understand graph indexing
- Understand graph traversal
- Understand graph-based retrieval
- Combine graph retrieval with vector retrieval
- Design Graph RAG pipelines
- Understand local and global graph retrieval
- Understand community-based retrieval
- Design Graph RAG for enterprise applications
- Understand Graph RAG security and multi-tenancy
- Understand Graph RAG evaluation
- Understand Graph RAG observability
- Understand performance and cost considerations
- Understand when Graph RAG should and should not be used
π§ 1. What Is Graph RAG?¶
Graph RAG is a Retrieval-Augmented Generation architecture where knowledge is represented as a graph of:
Instead of asking only:
the system can ask:
"What entities are involved?"
"What relationships connect them?"
"What paths explain the answer?"
"What supporting evidence exists?"
A simplified architecture is:
flowchart LR
A["User Query"] --> B["Query Understanding"]
B --> C["Graph Retrieval"]
C --> D["Relevant Entities"]
D --> E["Graph Traversal"]
E --> F["Related Entities"]
F --> G["Evidence"]
G --> H["LLM"]
H --> I["Answer"]
π 2. The Core Idea¶
Traditional vector RAG:
Graph RAG:
Hybrid Graph RAG:
Query
β
ββββββββββ΄βββββββββ
βΌ βΌ
Vector Retrieval Graph Retrieval
β β
βΌ βΌ
Semantic Evidence Relationship Evidence
β β
ββββββββββ¬βββββββββ
βΌ
Fusion
β
βΌ
Context
β
βΌ
LLM
π§© 3. Why Graph RAG?¶
Vector search is excellent at finding:
But enterprise questions often involve:
Examples:
Which services depend on service X?
Which customers are connected to product Y?
Who owns the applications affected by incident Z?
Which regulations apply to this business process?
How are these two organizations related?
Which systems depend indirectly on this database?
These questions are naturally represented as graphs.
πΈοΈ 4. Graph Mental Model¶
A graph consists of:
Example:
βββββββββββββββ
β Customer β
β Acme β
ββββββββ¬βββββββ
β
OWNS
β
βΌ
βββββββββββββββ
β Application β
β Payments β
ββββββββ¬βββββββ
β
DEPENDS_ON
β
βΌ
βββββββββββββββ
β Service β
β Payments β
βββββββββββββββ
π§± 5. Nodes¶
A node represents an entity.
Examples:
Person
Company
Customer
Application
Service
Database
Product
Policy
Regulation
Document
Location
Organization
A node may have properties:
{
"id": "service-payment",
"type": "Service",
"name": "Payment Service",
"version": "4.2",
"status": "active"
}
π 6. Edges¶
An edge represents a relationship.
Examples:
Example:
An edge can also contain properties.
{
"source": "application-42",
"relationship": "DEPENDS_ON",
"target": "payment-service",
"criticality": "high"
}
π§© 7. Properties¶
Both nodes and edges can contain properties.
Node
βββ id
βββ type
βββ name
βββ metadata
Edge
βββ source
βββ relationship
βββ target
βββ metadata
This creates a richer representation than a flat chunk of text.
π 8. Graph Example¶
Consider these statements:
Alice works for Acme.
Acme owns Payment Platform.
Payment Platform uses Payment Service.
Payment Service uses PostgreSQL.
PostgreSQL is hosted in AWS.
The graph becomes:
flowchart LR
A["Alice"] -->|WORKS_FOR| B["Acme"]
B -->|OWNS| C["Payment Platform"]
C -->|USES| D["Payment Service"]
D -->|USES| E["PostgreSQL"]
E -->|HOSTED_IN| F["AWS"]
The graph explicitly captures the relationships.
π 9. Vector RAG vs Graph RAG¶
Vector RAG¶
Graph RAG¶
Query
β
Entity Detection
β
Graph Search
β
Relationship Traversal
β
Relevant Subgraph
β
LLM
Hybrid Graph RAG¶
Query
β
ββββββββββββ΄βββββββββββ
βΌ βΌ
Vector Search Graph Search
β β
βΌ βΌ
Semantic Evidence Relationships
β β
ββββββββββββ¬βββββββββββ
βΌ
Fusion
β
βΌ
Context
β
βΌ
LLM
π― 10. When Graph RAG Is Useful¶
Graph RAG is particularly useful when the question requires:
Relationship Understanding¶
Dependency Analysis¶
Multi-Hop Reasoning¶
Entity-Centric Search¶
Network Analysis¶
Organizational Knowledge¶
π« 11. When Graph RAG May Not Be Necessary¶
Graph RAG is not automatically better than vector RAG.
If the query is:
and the answer exists directly in:
vector RAG may be simpler and more appropriate.
A useful rule:
Simple Semantic Lookup
β
Vector RAG
Relationship-Heavy Question
β
Graph RAG
Both
β
Hybrid Graph + Vector RAG
ποΈ 12. Graph RAG Architecture¶
A production Graph RAG system can be divided into:
GRAPH RAG
β
βββββββββββββββββΌβββββββββββββββββ
β β β
βΌ βΌ βΌ
Ingestion Knowledge Graph Retrieval
β β β
βΌ βΌ βΌ
Documents Nodes + Edges Query Planning
β β β
βΌ βΌ βΌ
Entity Extraction Graph Storage Traversal
β β
βΌ βΌ
Relationship Extraction Subgraph
β β
βββββββββββββββββ¬βββββββββββββββββ
βΌ
Context
β
βΌ
LLM
π₯ 13. Graph Construction¶
A knowledge graph normally begins with source data.
Documents
β
Text Extraction
β
Chunking
β
Entity Extraction
β
Relationship Extraction
β
Entity Resolution
β
Graph Construction
β
Graph Database
π§± 14. Graph Construction Pipeline¶
flowchart TD
A["Documents"] --> B["Text Extraction"]
B --> C["Chunking"]
C --> D["Entity Extraction"]
C --> E["Relationship Extraction"]
D --> F["Entity Resolution"]
E --> F
F --> G["Graph Construction"]
G --> H["Graph Database"]
C --> I["Vector Embeddings"]
I --> J["Vector Database"]
Notice that a hybrid system can maintain both:
π 15. Source Documents¶
Graph construction may consume:
Each source should preserve provenance.
Example:
π€ 16. Entity Extraction¶
Given:
the system might extract:
π 17. Relationship Extraction¶
From:
extract:
and:
π§ 18. LLM-Based Extraction¶
An LLM can be used to extract structured graph information.
Example prompt:
Extract entities and relationships from the text.
Return:
entities:
- name
- type
relationships:
- source
- relation
- target
Text:
"Acme's payment platform runs on AWS
and uses PostgreSQL."
Possible output:
{
"entities": [
{
"name": "Acme",
"type": "Organization"
},
{
"name": "Payment Platform",
"type": "Application"
},
{
"name": "AWS",
"type": "Cloud"
},
{
"name": "PostgreSQL",
"type": "Database"
}
],
"relationships": [
{
"source": "Payment Platform",
"relation": "HOSTED_ON",
"target": "AWS"
},
{
"source": "Payment Platform",
"relation": "USES",
"target": "PostgreSQL"
}
]
}
β οΈ 19. Extraction Is Not Ground Truth¶
LLM-generated graph structures may contain:
Incorrect Entities
Incorrect Relationships
Duplicate Entities
Hallucinated Relationships
Wrong Entity Types
Therefore:
should be preferred over:
π 20. Entity Resolution¶
Different documents may refer to the same entity:
Without entity resolution:
could become three separate nodes.
Entity resolution attempts to determine:
π§© 21. Entity Resolution Pipeline¶
flowchart LR
A["Extracted Entities"] --> B["Normalization"]
B --> C["Candidate Matching"]
C --> D["Similarity / Rules"]
D --> E{"Same Entity?"}
E -->|Yes| F["Merge"]
E -->|No| G["Create Node"]
π·οΈ 22. Canonical Entity¶
A canonical entity may look like:
{
"entity_id": "cloud-aws",
"canonical_name": "Amazon Web Services",
"aliases": [
"AWS",
"Amazon AWS",
"AWS Cloud"
],
"type": "CloudProvider"
}
This makes graph traversal more reliable.
πΈοΈ 23. Knowledge Graph Schema¶
A graph should have a defined schema.
Example:
Nodes:
Person
Organization
Application
Service
Database
CloudResource
Document
Policy
Relationships:
WORKS_FOR
OWNS
USES
DEPENDS_ON
HOSTED_ON
MANAGES
APPLIES_TO
DEFINED_BY
π 24. Schema-First vs Schema-Light¶
Schema-First¶
Advantages:
Schema-Light¶
Advantages:
Enterprise systems often benefit from controlled schemas.
π 25. Graph Query¶
Once the graph exists, queries can traverse relationships.
Conceptually:
The query is no longer simply:
It becomes:
π§ 26. Graph Traversal¶
A simple traversal:
Start:
Payment Platform
Depth 1:
Payment Service
Depth 2:
Authentication Service
Database
Depth 3:
Cloud Infrastructure
Visualized:
flowchart TD
A["Payment Platform"] --> B["Payment Service"]
B --> C["Authentication Service"]
B --> D["PostgreSQL"]
C --> E["Identity Provider"]
D --> F["AWS"]
π 27. Traversal Depth¶
Traversal depth matters.
Depth 1
Direct relationships
Depth 2
One intermediary
Depth 3
Two intermediaries
Depth 4+
Potentially large graph neighborhood
Larger depth can increase:
Therefore traversal should be bounded.
π― 28. Bounded Traversal¶
Instead of:
use:
Example:
π 29. Graph Retrieval¶
Graph retrieval can produce:
Example:
Entity:
Payment Service
Relationships:
DEPENDS_ON β Auth Service
USES β PostgreSQL
HOSTED_ON β AWS
Evidence:
architecture.pdf
section 4.2
π 30. Graph Evidence¶
A graph relationship should ideally preserve source evidence.
Instead of:
store:
Payment Service
DEPENDS_ON
Auth Service
Evidence:
architecture-document-42
Page: 14
Section: Authentication
This makes graph results auditable.
π 31. Graph + Document Provenance¶
flowchart TD
A["Document"] --> B["Chunk"]
B --> C["Entity"]
B --> D["Relationship"]
C --> E["Knowledge Graph"]
D --> E
E --> F["Graph Retrieval"]
F --> G["Source Evidence"]
G --> H["LLM"]
This is important for enterprise citations.
π§ 32. Local Graph Retrieval¶
Local graph retrieval focuses on a particular entity or neighborhood.
Example:
Start from:
and retrieve:
π 33. Global Graph Retrieval¶
Global graph retrieval asks questions about broader graph structure.
Examples:
What are the major business domains?
What are the most connected services?
Which departments have the most dependencies?
What themes appear across the enterprise?
This may require:
π₯ 34. Graph Communities¶
A graph can be divided into communities.
Example:
Enterprise Graph
β
ββββββββββββββββββΌβββββββββββββββββ
β β β
βΌ βΌ βΌ
Payments Identity Analytics
Community Community Community
Communities can represent:
π§© 35. Community-Based Retrieval¶
A global query can use community summaries:
Query
β
Identify Relevant Communities
β
Retrieve Community Summaries
β
Retrieve Supporting Evidence
β
LLM
This can reduce the need to traverse every node in a large graph.
π§ 36. Graph Summarization¶
A graph community might be summarized as:
Payments Community
Contains:
- Payment Platform
- Payment Gateway
- Payment Service
- Fraud Service
- Transaction Database
Key Relationships:
- Payment Platform depends on Payment Service
- Payment Service uses Transaction Database
- Fraud Service analyzes transactions
The summary becomes retrieval context.
π 37. Local + Global Graph RAG¶
A mature Graph RAG system may combine:
Architecture:
flowchart TD
A["Query"] --> B["Query Planner"]
B --> C["Local Graph Retrieval"]
B --> D["Global Graph Retrieval"]
B --> E["Vector Retrieval"]
C --> F["Evidence"]
D --> F
E --> F
F --> G["Context Fusion"]
G --> H["LLM"]
π§© 38. Hybrid Graph + Vector RAG¶
This is one of the most useful enterprise architectures.
User Query
β
βββββββββββββββββ
βΌ βΌ
Vector Search Graph Search
β β
βΌ βΌ
Semantic Relationships
Evidence & Paths
β β
βββββββββ¬ββββββββ
βΌ
Fusion
β
βΌ
Context
β
βΌ
LLM
π 39. Why Hybrid Works¶
Vector retrieval answers:
Graph retrieval answers:
Together:
π§ 40. Example: Enterprise Dependency Question¶
Query:
Vector RAG might retrieve:
Graph RAG can traverse:
Payment Service
β
DEPENDED_ON_BY
β
Application A
Application B
Application C
β
OWNED_BY
β
Team X
Team Y
The hybrid system can combine:
ποΈ 41. Enterprise Graph RAG Architecture¶
flowchart TD
A["User"] --> B["API Gateway"]
B --> C["RAG Orchestrator"]
C --> D["Query Understanding"]
D --> E["Query Planner"]
E --> F["Vector Retriever"]
E --> G["Graph Retriever"]
F --> H["Vector Store"]
G --> I["Knowledge Graph"]
H --> J["Evidence Fusion"]
I --> J
J --> K["Re-ranking"]
K --> L["Context Selection"]
L --> M["Prompt Assembly"]
M --> N["LLM"]
N --> O["Response Validation"]
O --> P["Citation Resolver"]
P --> Q["Enterprise Response"]
ποΈ 42. Graph Database¶
A graph database stores:
Conceptually:
Graph Database
β
βββ Node Store
βββ Relationship Store
βββ Property Store
βββ Query Engine
Common graph database approaches include:
π· 43. Property Graph¶
A property graph represents:
Example:
Relationship:
π· 44. RDF Graph¶
RDF represents knowledge using triples:
Example:
Another example:
RDF is especially useful in semantic-web and ontology-driven architectures.
π§ 45. Property Graph vs RDF¶
| Aspect | Property Graph | RDF |
|---|---|---|
| Core Model | Nodes + Edges | Triples |
| Properties | Native | Represented through triples |
| Developer Familiarity | Often intuitive | More semantic |
| Query Style | Graph query languages | SPARQL |
| Ontology Focus | Optional | Strong |
| Enterprise Knowledge Modeling | Strong | Strong |
| Semantic Web | Less central | Strong |
The appropriate model depends on the domain and governance requirements.
π 46. Graph Query Languages¶
Graph technologies may expose query languages such as:
The exact choice depends on the graph technology and data model.
Conceptual Cypher:
MATCH (app:Application)-[:DEPENDS_ON]->(service:Service)
WHERE service.name = "Payment Service"
RETURN app
The query expresses the relationship directly.
π§© 47. Graph Retrieval Interface¶
A provider-agnostic application interface can be:
class GraphRetriever:
def search(
self,
query,
entities=None,
relationships=None,
max_depth=2,
filters=None
):
raise NotImplementedError
The application does not need to know which graph database implements it.
ποΈ 48. Ports & Adapters¶
flowchart LR
A["RAG Application"] --> B["GraphRetriever Port"]
B --> C["Graph Adapter"]
C --> D["Graph Database"]
D --> E["Knowledge Graph"]
Possible adapters:
The specific implementation can evolve independently.
π§ 49. Graph Query Planning¶
A Graph RAG system should not blindly send every query to the graph.
A planner can classify the query:
Or:
π§ 50. Query Router¶
flowchart TD
A["User Query"] --> B["Query Router"]
B --> C{"Query Type"}
C -->|Semantic| D["Vector RAG"]
C -->|Relationship| E["Graph RAG"]
C -->|Mixed| F["Hybrid Graph + Vector"]
D --> G["Context"]
E --> G
F --> G
G --> H["LLM"]
π§ͺ 51. Query Examples¶
| Query | Preferred Retrieval |
|---|---|
| "What is the refund policy?" | Vector |
| "Which services depend on X?" | Graph |
| "Why does service X depend on Y?" | Graph + Vector |
| "What does the policy say about X?" | Vector |
| "Which teams own services affected by X?" | Graph |
| "Explain the architecture of X and its dependencies." | Graph + Vector |
| "What changed in the latest policy?" | Vector + Metadata |
| "Which customers are impacted by service X?" | Graph |
This is a conceptual routing guide.
π 52. Graph RAG Query Lifecycle¶
User Query
β
Intent Detection
β
Entity Detection
β
Entity Resolution
β
Graph Query Planning
β
Graph Traversal
β
Retrieve Supporting Documents
β
Evidence Fusion
β
Re-ranking
β
Context Selection
β
Prompt Assembly
β
LLM
β
Validation
β
Citation
β
Response
π 53. Entity Linking¶
The query:
may refer to:
as a cloud provider.
But a graph could contain:
Entity linking determines which graph entity the query refers to.
π§© 54. Entity Linking Pipeline¶
flowchart LR
A["Query"] --> B["Entity Extraction"]
B --> C["Candidate Entities"]
C --> D["Alias Matching"]
D --> E["Semantic Matching"]
E --> F["Entity ID"]
The canonical ID should be used for graph traversal.
π 55. Graph + Source Documents¶
A strong architecture stores links between:
Example:
Payment Service
β
β DEPENDS_ON
βΌ
Auth Service
β
βββ Evidence
β
architecture.md
section 5.2
chunk-183
This enables explainable retrieval.
π 56. Citation from Graph RAG¶
The final answer can cite:
Example:
The graph should not become an untraceable source of truth.
π‘οΈ 57. Graph RAG Security¶
Graph data may contain highly sensitive relationships.
Examples:
Employee β Manager
Customer β Account
Application β Database
System β Vulnerability
Organization β Contract
Therefore access control must apply to:
π 58. Graph Authorization¶
Bad:
Better:
User Identity
β
Authorization
β
Allowed Entities
β
Allowed Relationships
β
Graph Query
β
Authorized Subgraph
β
LLM
π₯ 59. Multi-Tenant Graph RAG¶
A shared graph may contain:
Tenant A
βββ Customer A1
βββ Service A1
βββ Document A1
Tenant B
βββ Customer B1
βββ Service B1
βββ Document B1
The retrieval layer must enforce:
before returning graph data.
π§© 60. Tenant-Aware Graph Retrieval¶
Conceptually:
The tenant boundary should be enforced by trusted infrastructure.
Do not rely on the LLM to remove unauthorized nodes from the result.
π§ 61. Graph RAG and Hallucination¶
Graph RAG can improve grounding when relationships are correctly represented.
But:
Incorrect graph construction can produce:
Therefore graph quality is critical.
π§ͺ 62. Graph Quality Pipeline¶
Source
β
Extraction
β
Validation
β
Entity Resolution
β
Relationship Validation
β
Graph
β
Evaluation
π 63. Graph Quality Metrics¶
Possible metrics include:
Entity Precision
Entity Recall
Relationship Precision
Relationship Recall
Entity Resolution Accuracy
Graph Coverage
Source Attribution Coverage
These metrics can be evaluated against a curated ground-truth dataset.
π§ͺ 64. Retrieval Evaluation¶
Graph RAG retrieval can be evaluated using:
Additionally evaluate:
π§ 65. Answer Evaluation¶
End-to-end metrics can include:
The evaluation dataset should contain questions where graph reasoning is genuinely required.
πΈοΈ 66. Graph Path Accuracy¶
Suppose the expected path is:
The retrieval system should return the correct relationship chain.
A useful test is:
π 67. Graph RAG Evaluation Dataset¶
Example:
{
"question": "Which database does Payment Service use?",
"expected_entities": [
"Payment Service",
"PostgreSQL"
],
"expected_relationships": [
"USES"
],
"expected_sources": [
"architecture-2026"
]
}
This allows automated retrieval evaluation.
β‘ 68. Performance¶
Graph traversal performance depends on:
Large unrestricted traversals can become expensive.
π 69. Control Traversal Cost¶
Use:
Example:
β‘ 70. Parallel Graph + Vector Retrieval¶
Graph and vector retrieval can often run concurrently:
flowchart TD
A["Query"] --> B["Query Planner"]
B --> C["Vector Retrieval"]
B --> D["Graph Retrieval"]
C --> E["Vector Evidence"]
D --> F["Graph Evidence"]
E --> G["Fusion"]
F --> G
G --> H["Re-ranking"]
H --> I["Context"]
This can reduce overall latency compared with sequential retrieval.
π° 71. Graph RAG Cost¶
Graph RAG introduces additional costs:
Graph Construction
+
Entity Extraction
+
Relationship Extraction
+
Entity Resolution
+
Graph Storage
+
Graph Queries
+
Maintenance
Therefore it should be introduced where graph structure provides meaningful value.
π 72. Graph Maintenance¶
Enterprise knowledge changes.
Example:
Later:
The graph must support:
π 73. Temporal Graphs¶
Some relationships are time-dependent.
Example:
From:
Then:
From:
The relationship should therefore support temporal properties where required.
π 74. Temporal Relationship¶
{
"source": "employee-42",
"relationship": "WORKS_FOR",
"target": "company-b",
"valid_from": "2024-01-01",
"valid_to": null
}
This is valuable for:
π 75. Incremental Graph Updates¶
A production ingestion pipeline can process only changed documents:
Document Change
β
Detect Changed Content
β
Extract Entities
β
Extract Relationships
β
Resolve Entities
β
Update Graph
β
Update Vector Store
This avoids rebuilding the complete graph unnecessarily.
π§© 76. Graph + Vector Data Synchronization¶
A hybrid system must keep:
consistent.
For example:
Document Updated
β
ββββββββββββββββ
βΌ βΌ
Graph Update Vector Update
β β
βββββββββ¬βββββββ
βΌ
Version Check
Store shared identifiers:
ποΈ 77. Enterprise Graph Data Model¶
A mature model might contain:
Document
β
βββ contains β Chunk
β
βββ mentions β Entity
Entity
β
βββ has_property β Property
β
βββ related_to β Entity
Relationship
β
βββ supported_by β Chunk
This creates provenance from:
π§ 78. Graph RAG Context Model¶
The context sent to the LLM can contain:
Query
+
Entities
+
Relationships
+
Paths
+
Community Summaries
+
Supporting Chunks
+
Source Metadata
Example:
QUERY
Which systems depend on Payment Service?
ENTITIES
Payment Service
Application A
Application B
RELATIONSHIPS
Application A β DEPENDS_ON β Payment Service
Application B β DEPENDS_ON β Payment Service
EVIDENCE
architecture.pdf
section 4.2
π 79. Prompt Assembly for Graph RAG¶
A graph-aware prompt can be structured:
SYSTEM:
Answer using the supplied evidence.
QUESTION:
Which systems depend on Payment Service?
GRAPH EVIDENCE:
- Application A DEPENDS_ON Payment Service
- Application B DEPENDS_ON Payment Service
DOCUMENT EVIDENCE:
- Architecture document, section 4.2
- Service dependency document, section 7
RULES:
- Do not infer unsupported relationships.
- Cite supporting evidence.
π‘οΈ 80. Graph Prompt Injection¶
Graph data may originate from untrusted documents.
For example:
If that text is included in graph context, it must be treated as:
not:
Therefore:
Prompt injection defenses remain necessary in Graph RAG.
π§© 81. Graph RAG Failure Modes¶
Common failures include:
Entity Extraction Failure
Relationship Extraction Failure
Entity Resolution Failure
Graph Schema Failure
Graph Staleness
Incorrect Traversal
Over-Traversal
Under-Traversal
Missing Evidence
Unauthorized Graph Access
Citation Failure
π¨ 82. Failure Example¶
Suppose:
is incorrectly resolved to:
Then:
This demonstrates why entity linking is a first-class component.
π§ͺ 83. Graph RAG Debugging¶
When an answer is wrong, inspect:
1. Query
2. Entity Extraction
3. Entity Resolution
4. Graph Query
5. Traversal Path
6. Retrieved Nodes
7. Retrieved Edges
8. Supporting Evidence
9. Context
10. Prompt
11. LLM Response
Observability should make each step inspectable.
π 84. Graph RAG Observability¶
A trace could look like:
Trace ID
β
βββ Query
β
βββ Entity Resolution
β
βββ Graph Query
β
βββ Traversal
β βββ depth
β βββ nodes
β βββ edges
β
βββ Vector Search
β
βββ Fusion
β
βββ Re-ranking
β
βββ Context
β
βββ LLM
β
βββ Response
Useful metrics:
Graph Query Latency
Traversal Depth
Nodes Retrieved
Edges Retrieved
Graph Cache Hit Rate
Entity Resolution Confidence
Graph Retrieval Errors
π 85. Graph Retrieval Dashboard¶
A production dashboard might track:
| Metric | Purpose |
|---|---|
| Graph Query Latency | Performance |
| Traversal Depth | Complexity |
| Nodes Retrieved | Retrieval size |
| Edges Retrieved | Relationship volume |
| Empty Graph Results | Coverage |
| Entity Resolution Failures | Data quality |
| Relationship Extraction Errors | Graph quality |
| Citation Coverage | Explainability |
| Graph Cache Hit Rate | Optimization |
π§ 86. Graph Caching¶
Repeated queries can reuse graph results.
Cache keys may include:
Authorization context must be considered when caching sensitive graph results.
π 87. Graph Versioning¶
A production graph should have identifiable versions.
This helps reproduce:
π’ 88. Enterprise Use Cases¶
Graph RAG is particularly valuable for:
IT Service Management¶
Customer 360¶
Fraud Detection¶
Compliance¶
Knowledge Management¶
π³ 89. Financial Services Example¶
Suppose the graph contains:
A question such as:
is naturally graph-oriented.
A vector search may retrieve relevant policies and transaction documentation, but graph traversal can identify the relationship chain.
π₯ 90. Healthcare Knowledge Example¶
A conceptual graph:
A relationship-aware query may require traversing several entities.
Healthcare implementations require additional privacy, safety, and regulatory controls beyond the architecture described here.
π» 91. Software Architecture Example¶
A software dependency graph:
Question:
Graph traversal can identify:
Vector retrieval can then retrieve:
This is a strong Graph + Vector RAG use case.
π§© 92. Graph RAG for Code¶
Code repositories can be represented as:
Relationships:
Graph RAG can answer questions such as:
Which services call this method?
Which applications depend on this library?
What components are affected by this API change?
π€ 93. Graph RAG + Agents¶
Agentic RAG can use the graph as a tool:
Agent
β
βββ Vector Search
β
βββ Graph Search
β
βββ SQL
β
βββ Web Search
The agent can decide which tool is appropriate.
flowchart TD
A["Agent"] --> B["Tool Selection"]
B --> C["Vector Search"]
B --> D["Graph Search"]
B --> E["SQL"]
B --> F["Other Tools"]
C --> G["Evidence"]
D --> G
E --> G
F --> G
G --> H["Agent Reasoning"]
H --> I{"More Evidence?"}
I -->|Yes| B
I -->|No| J["Final Response"]
π§ 94. Graph RAG vs Agentic RAG¶
They are related but different.
Graph RAG¶
Focus:
Agentic RAG¶
Focus:
They can be combined:
π 95. Graph RAG Design Principles¶
Principle 1 β Build the Graph for a Purpose¶
Do not create a graph simply because:
Define:
Principle 2 β Preserve Provenance¶
Every important relationship should have evidence where possible.
Principle 3 β Control Traversal¶
Avoid unrestricted graph expansion.
Principle 4 β Combine Graph and Vector Retrieval¶
Do not force every query through the graph.
Principle 5 β Secure the Graph¶
Authorization applies to:
Principle 6 β Evaluate the Graph¶
Measure:
π§± 96. Recommended Graph RAG Architecture¶
ββββββββββββββββββββββ
β Query β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Query Understandingβ
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Query Planner β
βββββββββββ¬βββββββββββ
β
ββββββββββββββΌβββββββββββββ
β β β
βΌ βΌ βΌ
Vector Graph SQL
Retrieval Retrieval Retrieval
β β β
ββββββββββββββΌβββββββββββββ
βΌ
ββββββββββββββββββββββ
β Evidence Fusion β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββ
β Re-ranking β
βββββββ¬βββββββ
β
βΌ
ββββββββββββββββββββββ
β Context Engineeringβ
βββββββββββ¬βββββββββββ
β
βΌ
βββββββββ
β LLM β
βββββ¬ββββ
β
βΌ
ββββββββββββββββββββββ
β Validation + β
β Citation β
βββββββββββ¬βββββββββββ
β
βΌ
Response
π§ͺ 97. Practical Exercise¶
Build a small enterprise service graph.
Nodes¶
Relationships¶
Create:
and:
π 98. Query the Graph¶
Test:
1. Which database does Payment Service use?
2. Which applications depend on Payment Service?
3. Which team owns Payment Service?
4. Where is the database hosted?
5. Which applications ultimately depend on AWS?
The first four are straightforward graph queries.
The fifth demonstrates multi-hop traversal.
π§ͺ 99. Add Vector Retrieval¶
Add documents:
Create embeddings.
Now test:
The architecture can combine:
π 100. Evaluate¶
Measure:
Entity Extraction Accuracy
Relationship Accuracy
Entity Resolution Accuracy
Graph Retrieval Recall
Vector Retrieval Recall
Answer Correctness
Citation Accuracy
Latency
Cost
Compare:
π¨ 101. Common Mistakes¶
Mistake 1 β Building a Graph for Every Query¶
Not every query requires graph reasoning.
Mistake 2 β No Entity Resolution¶
may become separate nodes.
Mistake 3 β No Provenance¶
A graph relationship without evidence can become difficult to trust.
Mistake 4 β Unlimited Traversal¶
can create:
Mistake 5 β Treating LLM Extraction as Truth¶
LLM extraction must be validated.
Mistake 6 β Ignoring Graph Freshness¶
A stale dependency graph can produce incorrect answers.
Mistake 7 β Ignoring Authorization¶
Graph relationships can expose sensitive enterprise information.
Mistake 8 β Using Graph RAG Without Measuring Value¶
Graph RAG introduces additional:
It should solve a real retrieval problem.
π 102. Production Checklist¶
β Define Graph RAG use cases
β Identify relationship-heavy queries
β Define entity types
β Define relationship types
β Define graph schema
β Define graph ownership
β Build ingestion pipeline
β Extract entities
β Extract relationships
β Normalize entities
β Resolve entities
β Validate relationships
β Preserve document provenance
β Preserve chunk provenance
β Version graph data
β Define graph update strategy
β Define deletion strategy
β Implement graph retrieval
β Implement bounded traversal
β Implement query planning
β Implement graph filtering
β Implement entity linking
β Integrate vector retrieval
β Implement hybrid retrieval
β Implement evidence fusion
β Implement re-ranking
β Implement context selection
β Implement citation resolution
β Implement response validation
β Implement authentication
β Implement authorization
β Implement tenant isolation
β Protect graph properties
β Protect source documents
β Measure graph retrieval latency
β Measure traversal depth
β Measure graph result size
β Measure entity resolution quality
β Measure relationship quality
β Build evaluation dataset
β Measure graph Recall@K
β Measure path accuracy
β Measure answer correctness
β Measure citation accuracy
β Add graph tracing
β Add graph metrics
β Add graph version metadata
β Add cache where appropriate
β Load test
β Security test
β Failure test
β Data freshness test
β Multi-tenant test
π 103. Key Takeaways¶
- Graph RAG extends RAG with explicit entity and relationship reasoning.
- Knowledge graphs represent entities, relationships, and properties.
- Vector RAG is optimized for semantic similarity.
- Graph RAG is particularly useful for relationship-heavy and multi-hop questions.
- Hybrid Graph + Vector RAG combines semantic retrieval with relationship retrieval.
- Graph construction typically involves entity extraction, relationship extraction, and entity resolution.
- LLM-based extraction should be validated before graph insertion.
- Entity resolution is critical for preventing duplicate or fragmented graph entities.
- Graph schemas improve consistency and governance.
- Graph traversal should be bounded by depth, node count, relationship type, and query budget.
- Graph retrieval should preserve source evidence and provenance.
- Local graph retrieval focuses on entity neighborhoods.
- Global graph retrieval can use community-level summaries and broader graph structures.
- Community-based retrieval can help answer questions spanning large knowledge graphs.
- Graph databases can use property-graph or RDF-based models.
- Graph queries can be expressed through technologies such as Cypher or SPARQL depending on the underlying graph model.
- Graph retrieval should be exposed through a provider-agnostic application interface.
- Ports & Adapters architecture can isolate graph infrastructure from the RAG application.
- Query routing can determine whether a question requires vector, graph, SQL, or hybrid retrieval.
- Graph RAG can be combined with Agentic RAG.
- Graph quality directly affects answer quality.
- Graph data must be versioned and maintained as enterprise knowledge changes.
- Temporal relationships can represent historical ownership, dependencies, and organizational changes.
- Security must apply to graph nodes, relationships, properties, and source evidence.
- Multi-tenant graph retrieval requires trusted tenant-aware filtering.
- Graph RAG introduces additional infrastructure and data-maintenance costs.
- Not every RAG problem requires a knowledge graph.
- Graph RAG should be adopted when relationships provide meaningful retrieval value.
- Production Graph RAG requires evaluation, observability, provenance, security, and lifecycle management.
π 104. Production Graph RAG Reference Model¶
USER
β
βΌ
βββββββββββββββββββ
β Query Processingβ
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Query Planner β
ββββββββββ¬βββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β β β
βΌ βΌ βΌ
Vector Graph SQL
Retrieval Retrieval Retrieval
β β β
β ββββββββ΄βββββββ β
β β β β
β βΌ βΌ β
β Entities Relationshipsβ
β β β β
β ββββββββ¬βββββββ β
β βΌ β
β Graph Traversal β
β β β
ββββββββββββββββΌβββββββββββββββ
βΌ
Evidence Fusion
β
βΌ
Re-ranking
β
βΌ
Context Engineering
β
βΌ
LLM
β
ββββββββββ΄βββββββββ
βΌ βΌ
Validation Citation
β β
ββββββββββ¬βββββββββ
βΌ
Enterprise Response
β
βΌ
Observability
π‘ Final Mental Model¶
GRAPH RAG
β
βΌ
Query
β
βΌ
Entity Understanding
β
βΌ
Entity Resolution
β
βΌ
Graph Search
β
βΌ
Graph Traversal
β
βββββββββββββ΄ββββββββββββ
βΌ βΌ
Relationships Paths
β β
βββββββββββββ¬ββββββββββββ
βΌ
Graph Evidence
β
ββββββββββββββββ
β β
βΌ βΌ
Vector Evidence SQL Evidence
β β
ββββββββ¬ββββββββ
βΌ
Evidence Fusion
β
βΌ
Re-ranking
β
βΌ
Context Engineering
β
βΌ
LLM
β
βββββββββββ΄ββββββββββ
βΌ βΌ
Validation Citation
β β
βββββββββββ¬ββββββββββ
βΌ
Enterprise Response
The central principle is:
Graph RAG is not simply "RAG with a graph database." It is an architectural approach for retrieving and reasoning over entities, relationships, paths, and supporting evidence when semantic similarity alone is insufficient.
The most important distinction is:
Vector RAG
"What content is similar?"
Graph RAG
"What entities are connected?"
Hybrid RAG
"What content is relevant,
and how are the entities connected?"
For enterprise systems, the strongest architecture is often not:
but:
The graph provides the relationship layer.
The vector store provides the semantic layer.
The source documents provide the evidence layer.
The LLM provides the reasoning and generation layer.
Together, they form a powerful foundation for enterprise knowledge systems.
π§ Chapter Navigation¶
Part V β Advanced Retrieval-Augmented Generation¶
Previous:
01. Advanced RAG Architecture
Next:
03. Knowledge Graphs for RAG
Section:
05 β Advanced RAG Architecture
Advanced RAG Architecture Path¶
01 Advanced RAG Architecture
β
02 Graph RAG
β
03 Knowledge Graphs for RAG
β
04 SQL RAG
β
05 Multimodal RAG
β
06 Agentic RAG
Enterprise AI Engineering Handbook
Building Production-Grade Enterprise AI Systems β One Chapter at a Time.