How do you implement RAG with knowledge graphs for complex reasoning?
GraphRAG combines vector retrieval with knowledge graph traversal for multi-hop reasoning. Architecture: during indexing, extract entities and relationships from documents using an LLM (entity: "Acme Corp", relationship: "acquired", entity: "TechStart"), store in a graph database (Neo4j, Amazon Neptune), and also embed text chunks in a vector store. At query time, extract entities from the query, retrieve relevant graph neighborhoods (1-2 hops), use the graph context to enhance retrieval (boost chunks containing related entities), and combine graph relationships with retrieved text for the LLM context. Microsoft's GraphRAG implementation creates hierarchical community summaries of document clusters, enabling global questions that span the entire corpus. Implementation pattern: use LLM for entity/relation extraction during indexing, store triples in a property graph, implement graph traversal queries (Cypher for Neo4j) alongside vector search, merge results with rank fusion. Key benefit: GraphRAG excels at questions requiring synthesis across multiple documents ("How are companies A and B connected through their supply chains?") where traditional RAG struggles because no single chunk contains the full answer.