Skip to content

Graph RAG πŸ“Š

Graph RAG uses knowledge graphs together with large language models (LLMs) to improve how information is retrieved and generated. It overcomes the limits of traditional search methods by using knowledge graphs, which organize data as connected entities and relationships.

One of the main benefits of Graph RAG is its ability to capture and represent complex relationships between entities, something that traditional text-based retrieval systems struggle with. By using this structured knowledge, LLMs can better grasp the context and details of a query, resulting in more accurate and insightful answers.

Official Paper

Offical Implementation

Microsoft Research Blog

Default VectorDB

Graph RAG uses LanceDB as the default vector database for performing vector search to retrieve relevant entities.

Working with Graph RAG is quite straightforward

  • Installation and API KEY as env variable

Set OPENAI_API_KEY as GRAPHRAG_API_KEY

pip install graphrag
export GRAPHRAG_API_KEY="sk-..."
  • Initial structure for indexing dataset
python3 -m graphrag.index --init --root dataset-dir
  • Index Dataset
python3 -m graphrag.index --root dataset-dir
  • Execute Query

Global Query Execution gives a broad overview of dataset

python3 -m graphrag.query --root dataset-dir --method global "query-question"

Local Query Execution gives a detailed and specific answers based on the context of the entities

python3 -m graphrag.query --root  dataset-dir --method local "query-question"

Open In Colab