How microsoft/ograg2 works
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 Query workflow · build_knowledge_graph.py Build workflow · ontology_mapping.py Ontology mapping · knowledge_graph.py Triple extraction
Components 23
Knowledge preparation
- Build workflow
build_knowledge_graph.py - Ontology mapping
ontology_mapping/ontology_mapping.py - Triple extraction
knowledge_graph/knowledge_graph.py - Knowledge graph
knowledge_graph/create_knowledge_graph.py - Question generation
generate_questions.py
Query strategies
- Query workflow
query_llm.py - Graph query engines
query_engine/knowledge_graph_query_engine.py - Hypergraph retrieval
query_engine/ontograph_query_engine.py - Ontology graph retrieval
query_engine/ontograph_query_engine_copy.py - Snippet RAG
query_engine/snippet_rag_query_engine.py - GraphRAG
query_engine/graphrag_query_engine.py - Vector RAG
query_engine/rag_query_engine.py - LLM query
query_engine/llm_query_engine.py - Full ontology query
query_engine/full_onto_query_engine.py - RAPTOR retrieval
query_engine/raptor_query_engine.py - Retriever utilities
query_engine/retriever.py
Shared services
- Config parsing
utils/parser.py - Model and data utilities
utils/utils.py
Other components
- User
- Domain ontology
- Domain documents
- LLM and embeddings
- Answer
Connections 24
- User → Build workflow: requests build
README.md - Domain ontology → Ontology mapping: ontology input
- Domain documents → Ontology mapping: document input
- Build workflow → Ontology mapping: invokes
build_knowledge_graph.py - Build workflow → Triple extraction: invokes
build_knowledge_graph.py - Build workflow → Model and data utilities: uses
build_knowledge_graph.py - Triple extraction → Knowledge graph: creates graph data
- User → Query workflow: submits question
README.md - Query workflow → Model and data utilities: loads configuration
query_llm.py - Query workflow → Hypergraph retrieval: dispatches
query_llm.py - Query workflow → Ontology graph retrieval: dispatches
query_llm.py - Query workflow → Snippet RAG: dispatches
query_llm.py - Query workflow → GraphRAG: dispatches
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
query_engine/ontograph_query_engine.py - Snippet RAG → LLM and embeddings: embeds and generates
query_engine/snippet_rag_query_engine.py - GraphRAG → LLM and embeddings: generates answer
query_engine/graphrag_query_engine.py - Query workflow → Answer: writes results
- Question generation → LLM and embeddings: generates questions