A knowledge graph represents entities, attributes, and relationships as connected structure. In retrieval-augmented generation, these explicit connections help expose context that semantic similarity may miss, especially for multihop questions spanning documents. section 14.1
A GraphRAG pipeline uses the graph operationally:
- Extract entities and relationships from document chunks with an LLM, constraining the response to a Pydantic-defined JSON schema. section 14.1
- Construct graphs from the extracted elements and combine them into a graph representing the document collection. section 14.1
- Detect communities of closely connected entities, then generate summaries for those communities. section 14.1 section 14.4
- Answer globally by generating partial responses from community summaries and combining them, or search locally by combining graph entities with document embeddings. section 14.1.1
Building a document knowledge graph
A Python workflow sends each text chunk to an Ollama model, requests entities and relationships in structured JSON, validates the result with Pydantic, and builds a NetworkX graph. It then applies Leiden community detection, summarizes each entity group, and combines community-level answers into a final response. section 14.1
Figure 14.1 The logical blocks and workflow of Microsoft’s GraphRAG proposal
The workflow diagram clarifies how indexing, entity graphs, community summaries, and query-time answer generation fit together. section 14.1











