# microsoft/ograg2 architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/ograg2
- Repository: https://github.com/microsoft/ograg2

## Overview

OG-RAG maps domain documents into ontology-shaped JSON-LD and knowledge-graph triples, then answers user questions using selectable retrieval and generation strategies. The graph preserves the documented construction and query workflows, along with the distinct query engines exposed by the package. Some engine internals and wiring are unsampled, so those relationships are omitted rather than inferred.

Main entry points: [`query_llm.py`](https://github.com/microsoft/ograg2/blob/main/query_llm.py) (Query workflow), [`build_knowledge_graph.py`](https://github.com/microsoft/ograg2/blob/main/build_knowledge_graph.py) (Build workflow), [`ontology_mapping/ontology_mapping.py`](https://github.com/microsoft/ograg2/blob/main/ontology_mapping/ontology_mapping.py) (Ontology mapping), [`knowledge_graph/knowledge_graph.py`](https://github.com/microsoft/ograg2/blob/main/knowledge_graph/knowledge_graph.py) (Triple extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Knowledge preparation"]
  node_build["Build workflow"]
  node_mapping["Ontology mapping"]
  node_triples["Triple extraction<br/>[knowledge_graph.py]"]
  node_kg[("Knowledge graph")]
  node_questions["Question generation"]
end

subgraph group_query["Query strategies"]
  node_querycli["Query workflow<br/>[query_llm.py]"]
  node_kgquery["Graph query engines"]
  node_hyperquery["Hypergraph retrieval"]
  node_ontograph["Ontology graph retrieval"]
  node_snippet["Snippet RAG"]
  node_graphrag["GraphRAG"]
  node_rag["Vector RAG"]
  node_llmquery["LLM query"]
  node_fullonto["Full ontology query"]
  node_raptor["RAPTOR retrieval"]
  node_retriever["Retriever utilities<br/>[retriever.py]"]
end

subgraph group_shared["Shared services"]
  node_config["Config parsing<br/>[parser.py]"]
  node_utils["Model and data utilities<br/>[utils.py]"]
end

node_user(("User"))
node_ontology["Domain ontology"]
node_documents["Domain documents"]
node_model["LLM and embeddings"]
node_answer["Answer"]

node_user -->|"requests build"| node_build
node_ontology -.->|"ontology input"| node_mapping
node_documents -.->|"document input"| node_mapping
node_build -->|"invokes"| node_mapping
node_build -->|"invokes"| node_triples
node_build -->|"uses"| node_utils
node_triples -.->|"creates graph data"| node_kg
node_user -->|"submits question"| node_querycli
node_querycli -->|"loads configuration"| node_utils
node_querycli -->|"dispatches"| node_hyperquery
node_querycli -->|"dispatches"| node_ontograph
node_querycli -->|"dispatches"| node_snippet
node_querycli -->|"dispatches"| node_graphrag
node_querycli -.->|"selects engine"| node_kgquery
node_querycli -.->|"selects engine"| node_rag
node_querycli -.->|"selects engine"| node_llmquery
node_querycli -.->|"selects engine"| node_fullonto
node_querycli -.->|"selects engine"| node_raptor
node_querycli -.->|"uses retrieval"| node_retriever
node_hyperquery -->|"embeds and generates"| node_model
node_snippet -->|"embeds and generates"| node_model
node_graphrag -->|"generates answer"| node_model
node_querycli -.->|"writes results"| node_answer
node_questions -.->|"generates questions"| node_model

click node_build "https://github.com/microsoft/ograg2/blob/main/build_knowledge_graph.py"
click node_mapping "https://github.com/microsoft/ograg2/blob/main/ontology_mapping/ontology_mapping.py"
click node_triples "https://github.com/microsoft/ograg2/blob/main/knowledge_graph/knowledge_graph.py"
click node_kg "https://github.com/microsoft/ograg2/blob/main/knowledge_graph/create_knowledge_graph.py"
click node_questions "https://github.com/microsoft/ograg2/blob/main/generate_questions.py"
click node_querycli "https://github.com/microsoft/ograg2/blob/main/query_llm.py"
click node_kgquery "https://github.com/microsoft/ograg2/blob/main/query_engine/knowledge_graph_query_engine.py"
click node_hyperquery "https://github.com/microsoft/ograg2/blob/main/query_engine/ontograph_query_engine.py"
click node_ontograph "https://github.com/microsoft/ograg2/blob/main/query_engine/ontograph_query_engine_copy.py"
click node_snippet "https://github.com/microsoft/ograg2/blob/main/query_engine/snippet_rag_query_engine.py"
click node_graphrag "https://github.com/microsoft/ograg2/blob/main/query_engine/graphrag_query_engine.py"
click node_rag "https://github.com/microsoft/ograg2/blob/main/query_engine/rag_query_engine.py"
click node_llmquery "https://github.com/microsoft/ograg2/blob/main/query_engine/llm_query_engine.py"
click node_fullonto "https://github.com/microsoft/ograg2/blob/main/query_engine/full_onto_query_engine.py"
click node_raptor "https://github.com/microsoft/ograg2/blob/main/query_engine/raptor_query_engine.py"
click node_retriever "https://github.com/microsoft/ograg2/blob/main/query_engine/retriever.py"
click node_config "https://github.com/microsoft/ograg2/blob/main/utils/parser.py"
click node_utils "https://github.com/microsoft/ograg2/blob/main/utils/utils.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_build,node_mapping,node_triples,node_kg,node_questions,node_user toneBlue
class node_querycli,node_kgquery,node_hyperquery,node_ontograph,node_snippet,node_graphrag,node_rag,node_llmquery,node_fullonto,node_raptor,node_retriever toneAmber
class node_config,node_utils toneMint
class node_ontology,node_documents,node_model,node_answer toneIndigo
```

## Components

### Knowledge preparation

- [Build workflow](https://github.com/microsoft/ograg2/blob/main/build_knowledge_graph.py): `build_knowledge_graph.py`
- [Ontology mapping](https://github.com/microsoft/ograg2/blob/main/ontology_mapping/ontology_mapping.py): `ontology_mapping/ontology_mapping.py`
- [Triple extraction](https://github.com/microsoft/ograg2/blob/main/knowledge_graph/knowledge_graph.py): `knowledge_graph/knowledge_graph.py`
- [Knowledge graph](https://github.com/microsoft/ograg2/blob/main/knowledge_graph/create_knowledge_graph.py): `knowledge_graph/create_knowledge_graph.py`
- [Question generation](https://github.com/microsoft/ograg2/blob/main/generate_questions.py): `generate_questions.py`

### Query strategies

- [Query workflow](https://github.com/microsoft/ograg2/blob/main/query_llm.py): `query_llm.py`
- [Graph query engines](https://github.com/microsoft/ograg2/blob/main/query_engine/knowledge_graph_query_engine.py): `query_engine/knowledge_graph_query_engine.py`
- [Hypergraph retrieval](https://github.com/microsoft/ograg2/blob/main/query_engine/ontograph_query_engine.py): `query_engine/ontograph_query_engine.py`
- [Ontology graph retrieval](https://github.com/microsoft/ograg2/blob/main/query_engine/ontograph_query_engine_copy.py): `query_engine/ontograph_query_engine_copy.py`
- [Snippet RAG](https://github.com/microsoft/ograg2/blob/main/query_engine/snippet_rag_query_engine.py): `query_engine/snippet_rag_query_engine.py`
- [GraphRAG](https://github.com/microsoft/ograg2/blob/main/query_engine/graphrag_query_engine.py): `query_engine/graphrag_query_engine.py`
- [Vector RAG](https://github.com/microsoft/ograg2/blob/main/query_engine/rag_query_engine.py): `query_engine/rag_query_engine.py`
- [LLM query](https://github.com/microsoft/ograg2/blob/main/query_engine/llm_query_engine.py): `query_engine/llm_query_engine.py`
- [Full ontology query](https://github.com/microsoft/ograg2/blob/main/query_engine/full_onto_query_engine.py): `query_engine/full_onto_query_engine.py`
- [RAPTOR retrieval](https://github.com/microsoft/ograg2/blob/main/query_engine/raptor_query_engine.py): `query_engine/raptor_query_engine.py`
- [Retriever utilities](https://github.com/microsoft/ograg2/blob/main/query_engine/retriever.py): `query_engine/retriever.py`

### Shared services

- [Config parsing](https://github.com/microsoft/ograg2/blob/main/utils/parser.py): `utils/parser.py`
- [Model and data utilities](https://github.com/microsoft/ograg2/blob/main/utils/utils.py): `utils/utils.py`

### Other components

- **User**
- **Domain ontology**
- **Domain documents**
- **LLM and embeddings**
- **Answer**

## Connections

- User → Build workflow: requests build (evidence: `README.md`)
- Domain ontology → Ontology mapping: ontology input
- Domain documents → Ontology mapping: document input
- Build workflow → Ontology mapping: invokes (evidence: `build_knowledge_graph.py`)
- Build workflow → Triple extraction: invokes (evidence: `build_knowledge_graph.py`)
- Build workflow → Model and data utilities: uses (evidence: `build_knowledge_graph.py`)
- Triple extraction → Knowledge graph: creates graph data
- User → Query workflow: submits question (evidence: `README.md`)
- Query workflow → Model and data utilities: loads configuration (evidence: `query_llm.py`)
- Query workflow → Hypergraph retrieval: dispatches (evidence: `query_llm.py`)
- Query workflow → Ontology graph retrieval: dispatches (evidence: `query_llm.py`)
- Query workflow → Snippet RAG: dispatches (evidence: `query_llm.py`)
- Query workflow → GraphRAG: dispatches (evidence: `query_llm.py`)
- Query workflow → Graph query engines: selects engine
- Query workflow → Vector RAG: selects engine
- Query workflow → LLM query: selects engine
- Query workflow → Full ontology query: selects engine
- Query workflow → RAPTOR retrieval: selects engine
- Query workflow → Retriever utilities: uses retrieval
- Hypergraph retrieval → LLM and embeddings: embeds and generates (evidence: `query_engine/ontograph_query_engine.py`)
- Snippet RAG → LLM and embeddings: embeds and generates (evidence: `query_engine/snippet_rag_query_engine.py`)
- GraphRAG → LLM and embeddings: generates answer (evidence: `query_engine/graphrag_query_engine.py`)
- Query workflow → Answer: writes results
- Question generation → LLM and embeddings: generates questions
