# nuri428/ontorag architecture

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

- Interactive diagram: https://gitdiagram.com/nuri428/ontorag
- Repository: https://github.com/nuri428/ontorag

## Overview

ontorag is an ontology-first RAG framework: users ask questions through its API or browser UI, an LLM agent selects structured graph tools, and graph-store backends return grounded results. Other product paths load and learn ontology data, provide search and Bayesian/causal reasoning, and expose schema/data browsing. The graph groups the main runtime by responsibility; backend alternatives and several capabilities are documented but their implementations were not sampled, so those links rely on README evidence or are omitted where ownership is unclear.

Main entry points: [`src/ontorag/stores/base.py`](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/base.py) (Graph store interface), [`src/ontorag/api/main.py`](https://github.com/nuri428/ontorag/blob/main/src/ontorag/api/main.py) (HTTP API), [`src/ontorag/chat/agent.py`](https://github.com/nuri428/ontorag/blob/main/src/ontorag/chat/agent.py) (Agent loop), [`src/ontorag/stores/factory.py`](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/factory.py) (Backend selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Interfaces"]
  node_api["HTTP API<br/>[main.py]"]
  node_chat_route["Chat endpoint<br/>[chat.py]"]
  node_web_ui["Browser UI<br/>[router.py]"]
end

subgraph group_knowledge["Ontology data"]
  node_loader["Ontology loading<br/>[batch_loader.py]"]
  node_learning["Ontology learning<br/>[pipeline.py]"]
  node_scope["Ontology scoping<br/>[ontology.py]"]
end

subgraph group_agent["Agent and tools"]
  node_agent_loop["Agent loop<br/>[agent.py]"]
  node_tool_routes["MCP tool routes"]
  node_multi_agent["Multi-agent flow"]
end

subgraph group_reasoning["Search and reasoning"]
  node_search["Text and vector search"]
  node_embedding["Graph embeddings<br/>[embedding.py]"]
  node_bayes["Bayesian inference<br/>[engine.py]"]
  node_causal["Causal inference<br/>[engine.py]"]
end

subgraph group_infra["Providers and storage"]
  node_llm["LLM providers<br/>[factory.py]"]
  node_graph_store["Graph store interface<br/>[base.py]"]
  node_store_factory["Backend selection<br/>[factory.py]"]
  node_fuseki[("Fuseki backend<br/>[fuseki.py]")]
  node_neo4j[("Neo4j backend<br/>[neo4j.py]")]
  node_falkordb[("FalkorDB backend<br/>[falkordb.py]")]
  node_qdrant[("Qdrant vectors<br/>[_qdrant.py]")]
end

node_user(("User"))

node_user -->|"sends requests"| node_api
node_api -->|"routes chat"| node_chat_route
node_chat_route -->|"runs agent"| node_agent_loop
node_agent_loop -->|"requests completions"| node_llm
node_agent_loop -->|"calls graph methods"| node_graph_store
node_api -->|"registers tools"| node_tool_routes
node_web_ui -->|"queries graph"| node_graph_store
node_loader -->|"loads triples"| node_graph_store
node_learning -->|"reads schema"| node_graph_store
node_graph_store -->|"scopes ontology data"| node_scope
node_store_factory -->|"selects backend"| node_fuseki
node_store_factory -->|"selects backend"| node_neo4j
node_store_factory -->|"selects backend"| node_falkordb
node_search -->|"queries ranked results"| node_graph_store
node_embedding -->|"supports similarity retrieval"| node_search
node_search -.->|"stores vectors"| node_qdrant
node_api -->|"routes inference"| node_bayes
node_api -->|"routes causal tools"| node_causal
node_causal -->|"reuses Bayesian model"| node_bayes
node_multi_agent -->|"uses agent loop"| node_agent_loop

click node_api "https://github.com/nuri428/ontorag/blob/main/src/ontorag/api/main.py"
click node_chat_route "https://github.com/nuri428/ontorag/blob/main/src/ontorag/api/routes/chat.py"
click node_web_ui "https://github.com/nuri428/ontorag/blob/main/src/ontorag/web/router.py"
click node_loader "https://github.com/nuri428/ontorag/blob/main/src/ontorag/core/batch_loader.py"
click node_learning "https://github.com/nuri428/ontorag/blob/main/src/ontorag/learn/pipeline.py"
click node_scope "https://github.com/nuri428/ontorag/blob/main/src/ontorag/core/ontology.py"
click node_agent_loop "https://github.com/nuri428/ontorag/blob/main/src/ontorag/chat/agent.py"
click node_tool_routes "https://github.com/nuri428/ontorag/tree/main/src/ontorag/api/routes"
click node_multi_agent "https://github.com/nuri428/ontorag/tree/main/src/ontorag/chat/multi_agent"
click node_llm "https://github.com/nuri428/ontorag/blob/main/src/ontorag/llm/factory.py"
click node_graph_store "https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/base.py"
click node_store_factory "https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/factory.py"
click node_fuseki "https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/fuseki.py"
click node_neo4j "https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/neo4j.py"
click node_falkordb "https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/falkordb.py"
click node_search "https://github.com/nuri428/ontorag/tree/main/src/ontorag/api/routes/tools"
click node_embedding "https://github.com/nuri428/ontorag/blob/main/src/ontorag/llm/embedding.py"
click node_qdrant "https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/_qdrant.py"
click node_bayes "https://github.com/nuri428/ontorag/blob/main/src/ontorag/bayes/engine.py"
click node_causal "https://github.com/nuri428/ontorag/blob/main/src/ontorag/causal/engine.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_chat_route,node_web_ui,node_user toneBlue
class node_loader,node_learning,node_scope toneAmber
class node_agent_loop,node_tool_routes,node_multi_agent toneMint
class node_search,node_embedding,node_bayes,node_causal toneRose
class node_llm,node_graph_store,node_store_factory,node_fuseki,node_neo4j,node_falkordb,node_qdrant toneIndigo
```

## Components

### Interfaces

- [HTTP API](https://github.com/nuri428/ontorag/blob/main/src/ontorag/api/main.py): `src/ontorag/api/main.py`
- [Chat endpoint](https://github.com/nuri428/ontorag/blob/main/src/ontorag/api/routes/chat.py): `src/ontorag/api/routes/chat.py`
- [Browser UI](https://github.com/nuri428/ontorag/blob/main/src/ontorag/web/router.py): `src/ontorag/web/router.py`

### Ontology data

- [Ontology loading](https://github.com/nuri428/ontorag/blob/main/src/ontorag/core/batch_loader.py): `src/ontorag/core/batch_loader.py`
- [Ontology learning](https://github.com/nuri428/ontorag/blob/main/src/ontorag/learn/pipeline.py): `src/ontorag/learn/pipeline.py`
- [Ontology scoping](https://github.com/nuri428/ontorag/blob/main/src/ontorag/core/ontology.py): `src/ontorag/core/ontology.py`

### Agent and tools

- [Agent loop](https://github.com/nuri428/ontorag/blob/main/src/ontorag/chat/agent.py): `src/ontorag/chat/agent.py`
- [MCP tool routes](https://github.com/nuri428/ontorag/tree/main/src/ontorag/api/routes): `src/ontorag/api/routes`
- [Multi-agent flow](https://github.com/nuri428/ontorag/tree/main/src/ontorag/chat/multi_agent): `src/ontorag/chat/multi_agent`

### Search and reasoning

- [Text and vector search](https://github.com/nuri428/ontorag/tree/main/src/ontorag/api/routes/tools): `src/ontorag/api/routes/tools`
- [Graph embeddings](https://github.com/nuri428/ontorag/blob/main/src/ontorag/llm/embedding.py): `src/ontorag/llm/embedding.py`
- [Bayesian inference](https://github.com/nuri428/ontorag/blob/main/src/ontorag/bayes/engine.py): `src/ontorag/bayes/engine.py`
- [Causal inference](https://github.com/nuri428/ontorag/blob/main/src/ontorag/causal/engine.py): `src/ontorag/causal/engine.py`

### Providers and storage

- [LLM providers](https://github.com/nuri428/ontorag/blob/main/src/ontorag/llm/factory.py): `src/ontorag/llm/factory.py`
- [Graph store interface](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/base.py): `src/ontorag/stores/base.py`
- [Backend selection](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/factory.py): `src/ontorag/stores/factory.py`
- [Fuseki backend](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/fuseki.py): `src/ontorag/stores/fuseki.py`
- [Neo4j backend](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/neo4j.py): `src/ontorag/stores/neo4j.py`
- [FalkorDB backend](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/falkordb.py): `src/ontorag/stores/falkordb.py`
- [Qdrant vectors](https://github.com/nuri428/ontorag/blob/main/src/ontorag/stores/_qdrant.py): `src/ontorag/stores/_qdrant.py`

### Other components

- **User**

## Connections

- User → HTTP API: sends requests (evidence: `README.md`)
- HTTP API → Chat endpoint: routes chat (evidence: `src/ontorag/api/main.py`)
- Chat endpoint → Agent loop: runs agent (evidence: `src/ontorag/api/routes/chat.py`)
- Agent loop → LLM providers: requests completions (evidence: `src/ontorag/chat/agent.py`)
- Agent loop → Graph store interface: calls graph methods (evidence: `src/ontorag/chat/agent.py`)
- HTTP API → MCP tool routes: registers tools (evidence: `src/ontorag/api/main.py`)
- Browser UI → Graph store interface: queries graph (evidence: `src/ontorag/web/router.py`)
- Ontology loading → Graph store interface: loads triples (evidence: `src/ontorag/core/batch_loader.py`)
- Ontology learning → Graph store interface: reads schema (evidence: `src/ontorag/learn/pipeline.py`)
- Graph store interface → Ontology scoping: scopes ontology data (evidence: `src/ontorag/stores/fuseki.py`)
- Backend selection → Fuseki backend: selects backend (evidence: `README.md`)
- Backend selection → Neo4j backend: selects backend (evidence: `README.md`)
- Backend selection → FalkorDB backend: selects backend (evidence: `README.md`)
- Text and vector search → Graph store interface: queries ranked results (evidence: `README.md`)
- Graph embeddings → Text and vector search: supports similarity retrieval (evidence: `README.md`)
- Text and vector search → Qdrant vectors: stores vectors (evidence: `README.md`)
- HTTP API → Bayesian inference: routes inference (evidence: `src/ontorag/api/main.py`)
- HTTP API → Causal inference: routes causal tools (evidence: `src/ontorag/api/main.py`)
- Causal inference → Bayesian inference: reuses Bayesian model (evidence: `src/ontorag/causal/engine.py`)
- Multi-agent flow → Agent loop: uses agent loop (evidence: `src/ontorag/eval/baselines/ontorag_multiagent.py`)
