# neo4j-contrib/ms-graphrag-neo4j architecture

> Architecture diagram of the GitHub repository neo4j-contrib/ms-graphrag-neo4j, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neo4j-contrib/ms-graphrag-neo4j
- Repository: https://github.com/neo4j-contrib/ms-graphrag-neo4j

## Overview

MsGraphRAG-Neo4j is a Python library for building and enriching a Neo4j knowledge graph to support query-focused summarization and retrieval. The principal workflow accepts text and entity types, uses an LLM to extract entities and relationships, stores them in Neo4j, summarizes graph data, then detects and summarizes communities. The graph separates those domain stages from their shared orchestration and prompt/parsing layer. The README documents the overall workflow; sampled source confirms key calls and query definitions, but does not show a user-facing search or retrieval API.

Main entry points: [`src/ms_graphrag_neo4j/ms_graphrag.py`](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py) (MsGraphRAG API), [`src/ms_graphrag_neo4j/cypher_queries.py`](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/cypher_queries.py) (Graph queries), [`src/ms_graphrag_neo4j/prompts.py`](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/prompts.py) (LLM prompt templates), [`src/ms_graphrag_neo4j/utils.py`](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/utils.py) (Output parsing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Graph workflow"]
  node_api["MsGraphRAG API<br/>[ms_graphrag.py]"]
  node_extract["Entity extraction<br/>[ms_graphrag.py]"]
  node_summarize["Node and relation summaries<br/>[ms_graphrag.py]"]
  node_detect["Community detection<br/>[ms_graphrag.py]"]
  node_community_summary["Community summaries<br/>[ms_graphrag.py]"]
end

subgraph group_processing["Graph processing"]
  node_prompts["LLM prompt templates<br/>[prompts.py]"]
  node_parsing["Output parsing<br/>[utils.py]"]
  node_cypher["Graph queries<br/>[cypher_queries.py]"]
end

subgraph group_integrations["LLM and database"]
  node_openai["OpenAI API"]
  node_neo4j[("Neo4j graph")]
  node_gds["Neo4j GDS"]
  node_apoc["Neo4j APOC"]
end

node_user(("Library user"))

node_user -->|"calls"| node_api
node_api -->|"runs"| node_extract
node_extract -->|"requests extraction"| node_openai
node_extract -->|"parses output"| node_parsing
node_extract -->|"imports graph data"| node_neo4j
node_extract -.->|"uses prompts"| node_prompts
node_api -->|"runs"| node_summarize
node_summarize -->|"reads and writes"| node_neo4j
node_summarize -->|"requests summaries"| node_openai
node_summarize -->|"uses queries"| node_cypher
node_api -->|"runs"| node_detect
node_detect -->|"runs graph queries"| node_neo4j
node_cypher -->|"calls Leiden"| node_gds
node_api -->|"runs"| node_community_summary
node_community_summary -->|"reads and writes"| node_neo4j
node_community_summary -->|"requests summaries"| node_openai
node_community_summary -.->|"uses prompts"| node_prompts
node_cypher -->|"calls subgraph procedure"| node_apoc

click node_api "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py"
click node_extract "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py"
click node_summarize "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py"
click node_detect "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py"
click node_community_summary "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py"
click node_prompts "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/prompts.py"
click node_parsing "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/utils.py"
click node_cypher "https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/cypher_queries.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_extract,node_summarize,node_detect,node_community_summary,node_user toneBlue
class node_prompts,node_parsing,node_cypher toneAmber
class node_openai,node_neo4j,node_gds,node_apoc toneMint
```

## Components

### Graph workflow

- [MsGraphRAG API](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py): `src/ms_graphrag_neo4j/ms_graphrag.py`
- [Entity extraction](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py): `src/ms_graphrag_neo4j/ms_graphrag.py`
- [Node and relation summaries](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py): `src/ms_graphrag_neo4j/ms_graphrag.py`
- [Community detection](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py): `src/ms_graphrag_neo4j/ms_graphrag.py`
- [Community summaries](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/ms_graphrag.py): `src/ms_graphrag_neo4j/ms_graphrag.py`

### Graph processing

- [LLM prompt templates](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/prompts.py): `src/ms_graphrag_neo4j/prompts.py`
- [Output parsing](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/utils.py): `src/ms_graphrag_neo4j/utils.py`
- [Graph queries](https://github.com/neo4j-contrib/ms-graphrag-neo4j/blob/main/src/ms_graphrag_neo4j/cypher_queries.py): `src/ms_graphrag_neo4j/cypher_queries.py`

### LLM and database

- **OpenAI API**
- **Neo4j graph**
- **Neo4j GDS**
- **Neo4j APOC**

### Other components

- **Library user**

## Connections

- Library user → MsGraphRAG API: calls (evidence: `README.md`)
- MsGraphRAG API → Entity extraction: runs (evidence: `README.md`)
- Entity extraction → OpenAI API: requests extraction (evidence: `README.md`)
- Entity extraction → Output parsing: parses output (evidence: `src/ms_graphrag_neo4j/ms_graphrag.py`)
- Entity extraction → Neo4j graph: imports graph data (evidence: `src/ms_graphrag_neo4j/ms_graphrag.py`)
- Entity extraction → LLM prompt templates: uses prompts (evidence: `src/ms_graphrag_neo4j/ms_graphrag.py`)
- MsGraphRAG API → Node and relation summaries: runs (evidence: `README.md`)
- Node and relation summaries → Neo4j graph: reads and writes (evidence: `README.md`)
- Node and relation summaries → OpenAI API: requests summaries (evidence: `README.md`)
- Node and relation summaries → Graph queries: uses queries (evidence: `src/ms_graphrag_neo4j/ms_graphrag.py`)
- MsGraphRAG API → Community detection: runs (evidence: `README.md`)
- Community detection → Neo4j graph: runs graph queries (evidence: `README.md`)
- Graph queries → Neo4j GDS: calls Leiden (evidence: `src/ms_graphrag_neo4j/cypher_queries.py`)
- MsGraphRAG API → Community summaries: runs (evidence: `README.md`)
- Community summaries → Neo4j graph: reads and writes (evidence: `README.md`)
- Community summaries → OpenAI API: requests summaries (evidence: `README.md`)
- Community summaries → LLM prompt templates: uses prompts (evidence: `src/ms_graphrag_neo4j/ms_graphrag.py`)
- Graph queries → Neo4j APOC: calls subgraph procedure (evidence: `src/ms_graphrag_neo4j/cypher_queries.py`)
