jnachi
Learning Hub
Agentic AI & RAG9 min readAdvanced

Knowledge Graph RAG (GraphRAG) & Multi-Hop Entity Reasoning

Extract entities and relations, construct property knowledge graphs in Neo4j, and execute multi-hop reasoning queries that traditional vector search cannot answer.

Works with:Microsoft GraphRAGNeo4j / CypherNetworkXLlamaIndex PropertyGraph

Key Takeaways

  • Vector search struggles with global dataset questions ("What are the top 5 overarching supply chain risks across all vendor contracts?")
  • GraphRAG extracts (Subject, Predicate, Object) knowledge triples and builds hierarchical entity clusters
  • Hybrid Graph-Vector querying combines semantic passage similarity with multi-hop graph traversals (Cypher queries)
  • Community summaries synthesize high-level thematic intelligence across entire corpus clusters

The Diagnostic Context

When answering complex relational questions spanning 50 different documents (e.g. "Which suppliers in Region A depend on microchips produced by Company B?"), vector search returns fragmented snippets. GraphRAG structures unstructured text into a queryable knowledge graph.

The Core Technique

Constructing Knowledge Triples for GraphRAG

PYTHON
from pydantic import BaseModel, Field

class KnowledgeTriple(BaseModel):
    subject: str = Field(description="Entity node initiating the relationship")
    predicate: str = Field(description="Relationship verb/type in UPPERCASE_SNAKE_CASE")
    object: str = Field(description="Target entity node")
    confidence: float = Field(ge=0.0, le=1.0)

class ExtractedGraphData(BaseModel):
    triples: list[KnowledgeTriple]
    entities: list[str]

# Example Cypher Query for Multi-Hop Graph Traversal in Neo4j:
# MATCH (c:Company {name: "Apex Semiconductor"})-[:SUPPLIES_TO*1..3]->(target:Company)
# RETURN target.name, target.country

Global Search vs Local Search in GraphRAG

  • Local Search: Focuses on specific entity neighborhoods (e.g., "What are the contractual terms for Vendor X?").
  • Global Search: Aggregates pre-computed community summaries across the entire graph to answer broad thematic questions (e.g., "What are the common vulnerabilities in our 2026 cloud architecture?").
5-Minute Activation Challenge

Try This Right Now

Extract 5 knowledge triples from a short press release about an acquisition (e.g. Company A acquired Company B for $500M led by CEO C) and visualize them as nodes and edges!

Tip: Knowledge only becomes capability once you run the prompt yourself.

Comprehension Check

Test Your Instincts (1 Questions)

1

Which query type represents the greatest strength of GraphRAG compared to naive vector similarity search?