Preview — full styling will appear after the next deploy completes.

agentic-ai-patterns

GraphRAG

Knowledge graph-based multi-hop retrieval

Instead of retrieving text chunks, the agent builds a knowledge graph of entities and relationships, then traverses it to answer multi-hop questions that span multiple entities.

flowchart TD
    S([__start__]) --> B[build_graph]
    B --> N1
    subgraph KnowledgeGraph
        N1([Book]) -->|written_by| N2([Author])
        N1 -->|belongs_to| N3([Genre])
        N1 -->|published_by| N4([Publisher])
    end
    N1 --> Q[query_graph]
    Q --> G[generate]
    G --> E([__end__])

GraphRAG replaces vector-based chunk retrieval with a structured knowledge graph. The graph is built by extracting entities (Books, Authors, Genres, Publishers) and relationships (written_by, belongs_to, published_by) from the database. This representation captures the relational structure that flat text chunks obscure.

At query time, the system uses an LLM to identify key entities in the question, finds their corresponding nodes in the graph, and traverses the edge network to collect a relevant subgraph. This subgraph — not raw text — is provided to the generator as context.

The critical advantage is multi-hop reasoning: "Which authors who write Science Fiction have books under $15 published by Penguin?" requires traversing Author → writes_in → Genre AND Author → writes → Book → published_by → Publisher — a query that flat RAG systems handle poorly. GraphRAG handles it naturally.