ontorag 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. ontorag-0.1.0/.example.env +17 -0
  2. ontorag-0.1.0/.github/workflows/ci.yml +26 -0
  3. ontorag-0.1.0/.github/workflows/release.yml +45 -0
  4. ontorag-0.1.0/.gitignore +7 -0
  5. ontorag-0.1.0/ARCHITECTURE_REVIEW.md +188 -0
  6. ontorag-0.1.0/CLAUDE.md +151 -0
  7. ontorag-0.1.0/LICENSE +201 -0
  8. ontorag-0.1.0/PKG-INFO +800 -0
  9. ontorag-0.1.0/README.md +552 -0
  10. ontorag-0.1.0/_requirements.txt +154 -0
  11. ontorag-0.1.0/app.py +187 -0
  12. ontorag-0.1.0/data/ontologies/catalog.json +3 -0
  13. ontorag-0.1.0/data/ontologies/rpg.ttl +1835 -0
  14. ontorag-0.1.0/ontology_induction.prompt.md +75 -0
  15. ontorag-0.1.0/ontorag/__init__.py +0 -0
  16. ontorag-0.1.0/ontorag/alignment_normalizer.py +138 -0
  17. ontorag-0.1.0/ontorag/blazegraph.py +44 -0
  18. ontorag-0.1.0/ontorag/cli.py +560 -0
  19. ontorag-0.1.0/ontorag/dto.py +70 -0
  20. ontorag-0.1.0/ontorag/extractor_ingest.py +398 -0
  21. ontorag-0.1.0/ontorag/hub/__init__.py +6 -0
  22. ontorag-0.1.0/ontorag/hub/app.py +452 -0
  23. ontorag-0.1.0/ontorag/hub/auth.py +133 -0
  24. ontorag-0.1.0/ontorag/hub/github_storage.py +167 -0
  25. ontorag-0.1.0/ontorag/hub/models.py +99 -0
  26. ontorag-0.1.0/ontorag/instance_extractor_openrouter.py +162 -0
  27. ontorag-0.1.0/ontorag/instances_to_ttl.py +109 -0
  28. ontorag-0.1.0/ontorag/mcp_backend.py +97 -0
  29. ontorag-0.1.0/ontorag/mcp_client.py +90 -0
  30. ontorag-0.1.0/ontorag/mcp_server.py +75 -0
  31. ontorag-0.1.0/ontorag/ontology_catalog.py +386 -0
  32. ontorag-0.1.0/ontorag/ontology_extractor_openrouter.py +137 -0
  33. ontorag-0.1.0/ontorag/ontology_mcp.py +207 -0
  34. ontorag-0.1.0/ontorag/proposal_aggregator.py +229 -0
  35. ontorag-0.1.0/ontorag/proposal_to_ttl.py +85 -0
  36. ontorag-0.1.0/ontorag/schema_alignment.py +388 -0
  37. ontorag-0.1.0/ontorag/schema_card.py +263 -0
  38. ontorag-0.1.0/ontorag/sparql_server.py +192 -0
  39. ontorag-0.1.0/ontorag/storage_jsonl.py +34 -0
  40. ontorag-0.1.0/ontorag/verbosity.py +46 -0
  41. ontorag-0.1.0/pyproject.toml +58 -0
  42. ontorag-0.1.0/tests/test_cli.py +56 -0
  43. ontorag-0.1.0/uv.lock +2231 -0
  44. ontorag-0.1.0/vercel.json +14 -0
@@ -0,0 +1,17 @@
1
+
2
+ OPENROUTER_API_KEY="..."
3
+ OPENROUTER_MODEL="xiaomi/mimo-v2-flash:free"
4
+ OPENROUTER_BASE_URL="https://openrouter.ai/api/v1"
5
+ OPENROUTER_APP_NAME="OntoRAG"
6
+ OPENROUTER_SITE_URL="https://ontorag.github.io"
7
+
8
+ # PageIndex (document ingestion) — hosted API at pageindex.ai
9
+ PAGEINDEX_API_KEY="..."
10
+
11
+ # OntoRAG Hub (ontorag hub command)
12
+ GITHUB_CLIENT_ID=""
13
+ GITHUB_CLIENT_SECRET=""
14
+ HUB_JWT_SECRET="change-me-in-production"
15
+ HUB_JWT_EXPIRY_HOURS=24
16
+ HUB_ONTOLOGY_DIR="./data/hub_ontologies"
17
+ HUB_BASE_URL="http://localhost:8000"
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ python-version: ["3.12", "3.13"]
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: ${{ matrix.python-version }}
24
+ - run: python -m pip install --upgrade pip
25
+ - run: pip install -e ".[dev]"
26
+ - run: pytest -q
@@ -0,0 +1,45 @@
1
+ name: Release to PyPI
2
+
3
+ # Publishes to PyPI via Trusted Publishing (OIDC — no API token stored).
4
+ # One-time setup on PyPI: add a "pending publisher" for project `ontorag`
5
+ # owner: ontorag repo: ontorag workflow: release.yml environment: pypi
6
+ # Then push a tag: `git tag v0.1.0 && git push origin v0.1.0`.
7
+
8
+ on:
9
+ push:
10
+ tags: ["v*"]
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.12"
24
+ - run: python -m pip install --upgrade pip build twine
25
+ - run: python -m build
26
+ - run: twine check dist/*
27
+ - uses: actions/upload-artifact@v4
28
+ with:
29
+ name: dist
30
+ path: dist/
31
+
32
+ publish:
33
+ needs: build
34
+ runs-on: ubuntu-latest
35
+ environment:
36
+ name: pypi
37
+ url: https://pypi.org/p/ontorag
38
+ permissions:
39
+ id-token: write # required for Trusted Publishing
40
+ steps:
41
+ - uses: actions/download-artifact@v4
42
+ with:
43
+ name: dist
44
+ path: dist/
45
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,7 @@
1
+ .env
2
+ __pycache__/*
3
+ *.pyc
4
+ data/*
5
+ !data/ontologies/
6
+ !data/ontologies/catalog.json
7
+ *.egg-info/*
@@ -0,0 +1,188 @@
1
+ # OntoRAG System Architecture Review
2
+
3
+ ## Overall Assessment
4
+
5
+ The architecture is **coherent and well-designed**. The pipeline follows a clear, principled flow:
6
+
7
+ ```
8
+ Documents → DTOs → LLM Proposals → Schema Card → Instance Extraction → RDF/TTL → SPARQL/MCP
9
+ ```
10
+
11
+ The core philosophy — "LLMs propose, Code decides, Humans govern" — is consistently applied throughout. Each stage has a clear responsibility, data flows forward through well-defined interfaces, and the separation between LLM-generated proposals and deterministic merging is sound.
12
+
13
+ ---
14
+
15
+ ## What Works Well
16
+
17
+ 1. **DTO-first ingestion** (`dto.py`, `extractor_ingest.py`, `storage_jsonl.py`) — Clean Pydantic models with stable IDs (SHA1-based), provenance tracking, and JSONL persistence. The DTOs serve as a replayable checkpoint.
18
+
19
+ 2. **Two-phase schema evolution** — LLM proposals (`ontology_extractor_openrouter.py`) are aggregated (`proposal_aggregator.py`) then deterministically merged into the schema card (`schema_card.py`). No hidden ML decisions in the merge step.
20
+
21
+ 3. **Evidence/provenance threading** — Every proposed class, property, and instance carries evidence quotes back to source chunks. The instance RDF embeds PROV-style mention nodes linking facts to their textual origin.
22
+
23
+ 4. **Schema card as governance artifact** — Versioned, human-reviewable JSON that guides all downstream extraction. This prevents schema drift and makes the ontology auditable.
24
+
25
+ 5. **Multi-backend design** — Local rdflib for inspection, Blazegraph for production. SPARQL as the universal query interface.
26
+
27
+ 6. **MCP integration** — Exposes the knowledge graph as structured tools for LLM agents, cleanly separating reasoning from data.
28
+
29
+ ---
30
+
31
+ ## Critical Issues
32
+
33
+ ### 1. Missing `mcp_backend` module
34
+
35
+ **Files affected:** `cli.py:228`, `mcp_server.py:7`
36
+
37
+ Both files import from `ontorag.mcp_backend`:
38
+ - `cli.py`: `from ontorag.mcp_backend import LocalRdfBackend, RemoteSparqlBackend`
39
+ - `mcp_server.py`: `from ontorag.mcp_backend import SparqlBackend`
40
+
41
+ **No `mcp_backend.py` file exists in the codebase.** This means:
42
+ - The `ontorag mcp-server` CLI command will crash with `ModuleNotFoundError`
43
+ - The `mcp_server.py` module cannot be imported at all
44
+
45
+ **Expected contents:** A `SparqlBackend` abstract base class with `select()` and `construct()` methods, and two implementations: `LocalRdfBackend` (wrapping rdflib in-memory graph) and `RemoteSparqlBackend` (wrapping a remote SPARQL endpoint via HTTP).
46
+
47
+ ### 2. SPARQL server filename is both misspelled and uses an invalid Python module name
48
+
49
+ **File:** `ontorag/saprql-server.py`
50
+ **Import in CLI:** `from ontorag.sparql_server import create_app` (`cli.py:199`)
51
+
52
+ Two problems:
53
+ - The filename is misspelled: `saprql-server.py` instead of `sparql_server.py`
54
+ - Hyphens are invalid in Python module names — Python cannot import `saprql-server` as a module
55
+
56
+ The `ontorag sparql-server` CLI command will fail with `ModuleNotFoundError`.
57
+
58
+ **Fix:** Rename `saprql-server.py` → `sparql_server.py`
59
+
60
+ ### 3. `ontology_extractor.py` has a broken import and is dead code
61
+
62
+ **File:** `ontorag/ontology_extractor.py:5`
63
+
64
+ ```python
65
+ from ontology_proposal import ChunkOntologyProposal
66
+ ```
67
+
68
+ This imports from a root-level file (`ontology_proposal.py`) using a bare import. As a package module, this will fail unless the root directory is manually added to `sys.path`. Additionally, nothing in the codebase imports `ontology_extractor.py` — the actual extractor used is `ontology_extractor_openrouter.py`.
69
+
70
+ ---
71
+
72
+ ## Moderate Issues
73
+
74
+ ### 4. `blazegraph_upload_ttl` injects raw TTL into SPARQL UPDATE
75
+
76
+ **File:** `blazegraph.py:20-27`
77
+
78
+ Raw Turtle content is string-interpolated directly into a SPARQL UPDATE query:
79
+ ```python
80
+ update = f"""
81
+ INSERT DATA {{
82
+ GRAPH <{graph_iri}> {{
83
+ {ttl}
84
+ }}
85
+ }}
86
+ """
87
+ ```
88
+
89
+ Turtle syntax can contain curly braces, angle brackets, and other characters that conflict with SPARQL syntax. This will break for non-trivial TTL files. A more robust approach would use Blazegraph's REST API for bulk graph loading (e.g., POST to the endpoint with `Content-Type: application/x-turtle`).
90
+
91
+ ### 5. No rate limiting in instance extraction
92
+
93
+ **File:** `instance_extractor_openrouter.py:118-139`
94
+
95
+ The schema extractor (`ontology_extractor_openrouter.py:98`) includes `time.sleep(10)` between chunk calls, but the instance extractor has no inter-chunk delay. For documents with many chunks, this will likely hit OpenRouter rate limits.
96
+
97
+ ### 6. SPARQL query type detection is fragile
98
+
99
+ **File:** `saprql-server.py:12-22`
100
+
101
+ `_detect_query_kind()` checks if the query starts with a SPARQL keyword, then checks for keywords after newlines. Single-line queries with PREFIX blocks (e.g., `PREFIX foo: <...> SELECT ...`) will not be detected and will fall through to the "unknown" fallback. The fallback does work (it tries the query and checks the result type), so this is not fatal, but it's fragile.
102
+
103
+ ### 7. SPARQL injection in MCP server tools
104
+
105
+ **File:** `mcp_server.py:26-51`
106
+
107
+ Tools like `describe()`, `list_by_class()`, `outgoing()`, and `incoming()` inject IRIs directly into SPARQL query strings via f-strings:
108
+ ```python
109
+ q = f"DESCRIBE <{iri}>"
110
+ ```
111
+
112
+ If an IRI contains `>` or other special characters, the query will break or behave unexpectedly. Since these are MCP tools exposed to LLM agents, malformed input is plausible.
113
+
114
+ ### 8. `pyproject.toml` missing runtime dependencies
115
+
116
+ **File:** `pyproject.toml`
117
+
118
+ Only 6 dependencies are listed (typer, requests, pydantic, rdflib, llama-index, python-dotenv), but the codebase also requires at runtime:
119
+ - `fastapi` + `uvicorn` (SPARQL server)
120
+ - `fastmcp` (MCP server)
121
+ - `openai` (used by `openrouter_client.py`)
122
+
123
+ Users installing via `pip install .` will get incomplete dependencies.
124
+
125
+ ---
126
+
127
+ ## Minor Issues
128
+
129
+ ### 9. `datetime.utcnow()` is deprecated
130
+
131
+ **Files:** `dto.py:34,43`, `schema_card.py:9`
132
+
133
+ Since Python 3.12, `datetime.utcnow()` is deprecated in favor of `datetime.now(datetime.timezone.utc)`.
134
+
135
+ ### 10. Legacy root-level files with broken imports
136
+
137
+ Three files at the project root are leftover from an earlier iteration:
138
+ - `cli_extract.py` — imports `from extractor import ...` (should be `extractor_ingest`)
139
+ - `openrouter_client.py` — standalone OpenAI client factory, unused by package
140
+ - `ontology_proposal.py` — Pydantic models superseded by the dict-based approach in the package
141
+
142
+ None of these are importable from the package or referenced by it.
143
+
144
+ ### 11. `openrouter_client.py` returns string, not dict
145
+
146
+ **File:** `openrouter_client.py:28`
147
+
148
+ The function `chat_json` returns `resp.choices[0].message.content` which is a raw string, not parsed JSON, despite the function name suggesting otherwise. The comment acknowledges this (`# JSON string (poi json.loads)`), but the API is misleading.
149
+
150
+ ### 12. Schema card class name validation is case-sensitive for warnings but case-insensitive for dedup
151
+
152
+ **File:** `schema_card.py:215-223`
153
+
154
+ Classes are deduplicated by lowercase key (`_key_class`), but the warning check `p["domain"] not in class_names` uses the original-case `name` field. If a property references a class with different casing (e.g., "person" vs "Person"), it will exist in the deduplicated map but trigger a spurious warning.
155
+
156
+ ---
157
+
158
+ ## Data Flow Verification
159
+
160
+ | Step | Input | Output | Verified |
161
+ |------|-------|--------|----------|
162
+ | `ingest` | File path | DocumentDTO + ChunkDTOs (JSONL) | OK |
163
+ | `extract-schema` | Chunks JSONL + schema card | Aggregated proposal JSON | OK |
164
+ | `build-schema-card` | Previous card + proposal | New schema card JSON | OK |
165
+ | `export-schema-ttl` | Proposal JSON | OWL/RDFS Turtle | OK |
166
+ | `extract-instances` | Chunks JSONL + schema card | Instance RDF TTL with provenance | OK |
167
+ | `load-ttl` | TTL file + graph IRI | Blazegraph upload | OK (with caveat #4) |
168
+ | `sparql-server` | Ontology TTL + Instances TTL | FastAPI SPARQL endpoint | BROKEN (issue #2) |
169
+ | `mcp-server` | TTL or SPARQL endpoint | MCP tools | BROKEN (issue #1) |
170
+
171
+ ---
172
+
173
+ ## Recommendations (Priority Order)
174
+
175
+ 1. **Create `ontorag/mcp_backend.py`** with `SparqlBackend`, `LocalRdfBackend`, and `RemoteSparqlBackend`
176
+ 2. **Rename `saprql-server.py` → `sparql_server.py`**
177
+ 3. **Fix `blazegraph_upload_ttl`** to use Blazegraph REST API instead of SPARQL INSERT DATA
178
+ 4. **Add missing dependencies** to `pyproject.toml` (fastapi, uvicorn, fastmcp)
179
+ 5. **Add inter-chunk delay** in `instance_extractor_openrouter.py`
180
+ 6. **Sanitize IRI inputs** in MCP server SPARQL templates
181
+ 7. **Remove or relocate legacy files** (`cli_extract.py`, `openrouter_client.py`, `ontology_proposal.py`, `ontology_extractor.py`)
182
+ 8. **Add a test suite** — the project has zero tests
183
+
184
+ ---
185
+
186
+ ## Conclusion
187
+
188
+ The OntoRAG system architecture is **fundamentally sound**. The pipeline design, governance model, and separation of concerns are well thought out. The two blocking issues (missing `mcp_backend` module and misspelled SPARQL server filename) prevent two CLI commands from working, but the core extraction pipeline (`ingest` → `extract-schema` → `build-schema-card` → `export-schema-ttl` → `extract-instances`) is complete and internally consistent.
@@ -0,0 +1,151 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ uv sync # installs core deps; rebuilds .venv if broken
9
+ cp .example.env .env # fill in OPENROUTER_API_KEY and optionally BLAZEGRAPH_ENDPOINT
10
+ ```
11
+
12
+ Requires Python 3.12. Uses `uv` (see `uv.lock`). `pymupdf`, `pageindex`, and `llama-index` are optional extras:
13
+
14
+ ```bash
15
+ uv sync --extra pdf # for PDF ingest via PyMuPDF
16
+ uv sync --extra pageindex # for hierarchical PDF ingest via PageIndex
17
+ uv sync --extra llamaindex # for LlamaIndex fixed-chunk ingest
18
+ ```
19
+
20
+ ## CLI
21
+
22
+ The shell `PYTHONPATH` on this server is polluted with old system Python paths. Always invoke as:
23
+
24
+ ```bash
25
+ PYTHONPATH=/srv/sembase/extractor_new uv run ontorag <command>
26
+ ```
27
+
28
+ Verbosity flags go before the subcommand: `uv run ontorag -v <command>` or `-vv` for debug traces.
29
+
30
+ ## Key commands
31
+
32
+ | Command | Purpose |
33
+ |---|---|
34
+ | `ontorag ingest <file> --out data/dto` | Parse document → DocumentDTO + ChunkDTOs (content-addressed, skips re-runs) |
35
+ | `ontorag extract-schema --chunks ... --schema-card ... --out ...` | LLM per-chunk ontology proposals → aggregated proposal JSON |
36
+ | `ontorag align-schema --proposal ... --baseline ... --out ...` | LLM alignment of induced items against baseline ontologies |
37
+ | `ontorag build-schema-card --previous ... --proposal ... --out ...` | Deterministic merge of proposal into schema card |
38
+ | `ontorag export-schema-ttl --proposal ... --out ... --namespace ...` | Proposal/alignment JSON → OWL/RDFS Turtle |
39
+ | `ontorag extract-instances --chunks ... --schema-card ... --out-ttl ...` | LLM instance extraction → RDF TTL with PROV provenance |
40
+ | `ontorag sparql-server --onto ... --inst ...` | FastAPI in-memory SPARQL endpoint (port 8890) |
41
+ | `ontorag mcp-server --onto ... --inst ...` | Knowledge graph MCP server (port 9010) |
42
+ | `ontorag ontology-mcp --catalog ...` | Ontology catalog MCP server (port 9020) |
43
+ | `ontorag register-ontology <slug> <ttl>` | Register a baseline OWL/TTL into the catalog |
44
+ | `ontorag init-schema-card --baselines foaf,prov --out ...` | Compose baselines → initial schema card |
45
+ | `ontorag hub` | Start Hub API server (requires GitHub OAuth env vars) |
46
+
47
+ ## Architecture
48
+
49
+ The core philosophy: **LLMs propose. Code decides. Humans govern.**
50
+
51
+ Pipeline flow:
52
+ ```
53
+ Baseline Ontologies (TTL)
54
+ → init-schema-card → schema_card.json
55
+ Documents
56
+ → ingest → data/dto/documents/*.json + data/dto/chunks/*.jsonl
57
+ → extract-schema → data/proposals/*.json (LLM, per-chunk → aggregated)
58
+ → align-schema → alignment JSON (LLM, optional baseline alignment)
59
+ → build-schema-card → schema_card.json (deterministic merge)
60
+ → export-schema-ttl → staging_schema.ttl
61
+ → extract-instances → instances.ttl (LLM, RDF + PROV provenance)
62
+ → sparql-server / mcp-server
63
+ ```
64
+
65
+ ### Module map (`ontorag/`)
66
+
67
+ | File | Role |
68
+ |---|---|
69
+ | `cli.py` | Typer CLI — all 13 commands |
70
+ | `dto.py` | `DocumentDTO`, `ChunkDTO`, `ProvenanceDTO`; content-hash (`stable_document_id`) |
71
+ | `extractor_ingest.py` | Document parsing via PageIndex (hierarchical) or LlamaIndex (fixed chunks) |
72
+ | `storage_jsonl.py` | JSONL persistence for DTOs |
73
+ | `ontology_extractor_openrouter.py` | LLM schema proposal extraction (per chunk) |
74
+ | `instance_extractor_openrouter.py` | LLM instance extraction (per chunk) |
75
+ | `proposal_aggregator.py` | Merge per-chunk proposals into one document-level proposal |
76
+ | `schema_card.py` | Deterministic schema card merge with origin tracking |
77
+ | `schema_alignment.py` | LLM-based alignment of induced items against baselines |
78
+ | `proposal_to_ttl.py` | Schema proposal/alignment JSON → rdflib `Graph` (OWL/RDFS) |
79
+ | `instances_to_ttl.py` | Instance proposals → rdflib `Graph` with PROV mention nodes |
80
+ | `blazegraph.py` | Blazegraph REST API (upload TTL, SPARQL UPDATE) |
81
+ | `sparql_server.py` | FastAPI SPARQL endpoint (SELECT/ASK/CONSTRUCT/DESCRIBE, content negotiation) |
82
+ | `mcp_backend.py` | `SparqlBackend` ABC + `LocalRdfBackend` + `RemoteSparqlBackend` |
83
+ | `mcp_server.py` | Knowledge graph MCP tools (`sparql_select`, `describe`, `list_by_class`, etc.) |
84
+ | `mcp_client.py` | Async SSE client for remote MCP |
85
+ | `ontology_catalog.py` | Local catalog + OWL/TTL → schema card converter; remote baseline fetch |
86
+ | `ontology_mcp.py` | Ontology catalog MCP server |
87
+ | `verbosity.py` | Logging setup (`-v`/`-vv` flags) |
88
+ | `hub/` | Hub FastAPI app, GitHub OAuth, GitHub storage backend |
89
+
90
+ ### Schema card format
91
+
92
+ The schema card (`schema_card.json`) is the central governance artifact:
93
+
94
+ ```json
95
+ {
96
+ "version": "<ISO timestamp>",
97
+ "namespace": "http://my.org/ns/",
98
+ "classes": [{"name": "...", "description": "...", "origin": "foaf|schema_org|induced|..."}],
99
+ "datatype_properties": [{"name": "...", "domain": "...", "range": "string|integer|...", "description": "...", "origin": "..."}],
100
+ "object_properties": [{"name": "...", "domain": "...", "range": "...", "description": "...", "origin": "..."}],
101
+ "events": [],
102
+ "aliases": [{"names": [...], "rationale": "..."}],
103
+ "warnings": []
104
+ }
105
+ ```
106
+
107
+ Dedup is by normalized (lowercased) name. Baseline origins are preserved across merges; LLM-induced items get `"origin": "induced"`.
108
+
109
+ ### LLM integration
110
+
111
+ All LLM calls go through OpenRouter (`OPENROUTER_API_KEY`, `OPENROUTER_MODEL`). The modules `ontology_extractor_openrouter.py`, `instance_extractor_openrouter.py`, and `schema_alignment.py` each manage their own `requests` calls directly (no shared client abstraction). The `extract-schema` command adds a 10-second inter-chunk delay; `extract-instances` does not.
112
+
113
+ `align-schema` supports **partial-save and auto-resume**: if the output file exists with `"_partial": true`, it resumes from the last completed category.
114
+
115
+ ### Ingest engines
116
+
117
+ `ontorag ingest` supports two engines via `--engine`:
118
+ - `llamaindex` (default): fixed-size chunks (1024 tokens, 120 overlap)
119
+ - `pageindex`: hierarchical section detection, requires `PAGEINDEX_API_KEY`
120
+
121
+ Documents are content-hashed (SHA-256); re-ingesting the same file is a no-op unless `--force` is passed.
122
+
123
+ ### Data directories
124
+
125
+ ```
126
+ data/dto/documents/ DocumentDTO JSON files (doc_<hash>.json)
127
+ data/dto/chunks/ ChunkDTO JSONL files (doc_<hash>.jsonl)
128
+ data/proposals/ Aggregated schema proposals and alignment JSON
129
+ data/schema/ Schema cards and exported TTL
130
+ data/instances/ Instance RDF TTL
131
+ data/ontologies/ Baseline catalog (catalog.json + *.ttl)
132
+ data/ttl/ Misc TTL files
133
+ ```
134
+
135
+ ## Environment variables
136
+
137
+ | Variable | Required for |
138
+ |---|---|
139
+ | `OPENROUTER_API_KEY` | All LLM commands |
140
+ | `OPENROUTER_MODEL` | LLM model selection (default: `openai/gpt-4o-mini`) |
141
+ | `OPENROUTER_BASE_URL` | OpenRouter endpoint |
142
+ | `BLAZEGRAPH_ENDPOINT` | `load-ttl`, `sparql-update` commands |
143
+ | `PAGEINDEX_API_KEY` | `ingest --engine pageindex` |
144
+ | `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` / `HUB_JWT_SECRET` | `hub` command |
145
+ | `ONTORAG_MCP_URL` | Remote baseline resolution in `init-schema-card` (default: `https://mcp.rpg-schema.org`) |
146
+
147
+ ## Known issues
148
+
149
+ - `blazegraph.py`: raw TTL is string-interpolated into SPARQL UPDATE — breaks for non-trivial TTL; Blazegraph REST bulk load is the proper fix.
150
+ - Hub async endpoints block the event loop (sync LLM calls inside `async def`).
151
+ - No test suite exists in this repository.
ontorag-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for, or grant, warranty, support, indemnity or other liability
168
+ obligations and/or rights consistent with this License. However,
169
+ in accepting such obligations, You may act only on Your own behalf
170
+ and on Your sole responsibility, not on behalf of any other
171
+ Contributor, and only if You agree to indemnify, defend, and hold
172
+ each Contributor harmless for any liability incurred by, or claims
173
+ asserted against, such Contributor by reason of your accepting any
174
+ such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Marco Montanari and OntoRAG contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.