Skip to content

Commit 8eb0974

Browse files
Boris Devclaude
andcommitted
Add paper: Domain Grammar as Compiler Architecture for Knowledge Systems
Generalized paper on domain grammars, compiler IR design, and Chomsky's I-language applied to knowledge graph systems. Replaces placeholder index.html with markdown index page and Jekyll minimal theme. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1da92c9 commit 8eb0974

4 files changed

Lines changed: 377 additions & 2 deletions

File tree

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
theme: jekyll-theme-minimal
2+
title: Boris Dev

domain-grammar-compiler.md

Lines changed: 362 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,362 @@
1+
# Domain Grammar as Compiler Architecture for Knowledge Systems
2+
3+
**Boris Dev** | March 2026
4+
5+
---
6+
7+
```
8+
Ontology (primitives + relations)
9+
10+
│ constrains
11+
12+
Domain Grammar (valid semantic structures)
13+
14+
│ guides parsing
15+
16+
Question ────► Concept IR ◄──── Source Text
17+
│ │
18+
▼ ▼
19+
Query Plan Graph Patch
20+
│ │
21+
└──► Knowledge ◄───┘
22+
Graph
23+
```
24+
25+
```mermaid
26+
flowchart LR
27+
BFO[upper ontology] --> DM((domain_modeling))
28+
DC[domain concepts] --> DM
29+
30+
DM --> G[grammar]
31+
32+
CS[ ] -->|source text| SP((semantic_parsing))
33+
G --> SP
34+
UQ[ ] -->|user question| SP
35+
36+
SP -->|ingestion protocol| SG[typed subgraph]
37+
SG --> KG[(knowledge graph)]
38+
39+
SP -->|query protocol| GQ[graph query]
40+
GQ --> KG
41+
42+
style CS fill:transparent,stroke:transparent
43+
style UQ fill:transparent,stroke:transparent
44+
```
45+
46+
---
47+
48+
## Abstract
49+
50+
Most AI knowledge systems are RAG pipelines: embed documents, retrieve by similarity, generate text. They work until you need *auditable reasoning* — provenance, contradiction detection, cross-source inference.
51+
52+
This paper describes an alternative: treat domain knowledge extraction as a **compilation problem**. Define a domain grammar — the set of valid semantic structures — and compile source text into typed intermediate representations (IR) that execute against a knowledge graph. The grammar is the single artifact that governs extraction, querying, and schema evolution.
53+
54+
The architecture draws equally from **compiler design** (source → IR → executable) and **Chomsky's Minimalist Program** (I-language, competence vs. performance, the primacy of internal grammar over surface form). Both traditions converge on the same insight: *a well-designed intermediate representation, governed by a generative grammar, is more powerful than pattern-matching on surface text*.
55+
56+
---
57+
58+
## 1. The Core Idea
59+
60+
A domain grammar is a generative rule system that defines:
61+
62+
- **What concept classes exist** (entities, processes, artifacts)
63+
- **What compositions are valid** (a Finding must bind an intervention to an outcome via an observed effect)
64+
- **What transformations are legal** (source text → Concept IR → Query Plan or Graph Patch)
65+
66+
From this grammar, everything else is derived: Pydantic schemas, graph schemas, table DDL, extraction prompts, query templates.
67+
68+
| Compiler | Linguistics (Chomsky) | This System |
69+
|----------|-----------------------|-------------|
70+
| Source code | Surface form (E-language) | Source text / user question |
71+
| Parser | Grammar rules | Domain grammar |
72+
| AST / IR | Deep structure | Concept IR |
73+
| Machine code | Logical form | Executable form (Query Plan / Graph Patch) |
74+
| Runtime || Knowledge Graph |
75+
76+
The compiler analogy dominates because the later stages are *execution artifacts*, not meaning representations. But the Chomsky parallel is not decorative — it provides the conceptual vocabulary for reasoning about the system's competence independently of any particular execution.
77+
78+
---
79+
80+
## 2. Five Layers
81+
82+
### Layer definitions
83+
84+
| Layer | Role | Static or Derived? |
85+
|-------|------|--------------------|
86+
| **Ontology** | Primitive types + relations | Static, designed |
87+
| **Domain Grammar** | Valid semantic structures built from ontology types | Static, designed (empirically tuned) |
88+
| **Concept IR** | Parsed, canonicalized meaning instances | Derived from source text + grammar |
89+
| **Executable Form** | System-ready operations | Derived from Concept IR |
90+
| **Knowledge Graph** | Instantiated ontology | Accumulated from Graph Patches |
91+
92+
### Key relationships
93+
94+
- **Ontology underdetermines grammar.** Knowing that `Process` and `Entity` exist does not tell you which compositions are valid. That is a design choice.
95+
- **Grammar fully determines schema.** Given a precise grammar, the Pydantic models, graph schema, and DDL can be mechanically compiled. No human decision required.
96+
- **Concept IR is not ontology.** It *uses* ontology types but is a structured meaning instance, not a type definition.
97+
98+
---
99+
100+
## 3. Grammar vs. Schema — The Critical Distinction
101+
102+
A schema is a **serialized structural specification**: fields, types, enums, nesting, constraints. A domain grammar is the **generative rule system** that defines concept classes, dependency chains, allowed compositions, and transformation rules — from which schemas can be derived.
103+
104+
The key difference: **a schema does not expose its own derivation.**
105+
106+
| | Schema | Domain Grammar |
107+
|---|---|---|
108+
| **Contains** | Fields, types, enums, constraints | All of schema + dependency chains, ontological categories, composition rules, extension invariants |
109+
| **Generative?** | No — it is a product | Yes — it is an engine |
110+
| **Evolvable?** | Only by hand | New valid schemas can be derived from it |
111+
112+
The stack: **Grammar creates schemas. Schemas constrain instances. Instances populate the domain.**
113+
114+
### Why you don't need a data dictionary
115+
116+
Most organizations build bottom-up: engineer writes schema → schema is opaque → someone writes a data dictionary to translate it back into English. The data dictionary is a patch — it retrofits meaning onto structure built without it.
117+
118+
A grammar-first system is top-down: design doc + ontology → domain grammar → schema is *generated*. Meaning comes first. Structure is derived. The grammar *is* the living, executable data dictionary.
119+
120+
---
121+
122+
## 4. The I-Language
123+
124+
In Chomsky's framework, **I-language** (internalized language) is the whole computational system built from exposure to data. The grammar is the spec; the I-language is the instantiated competence [1].
125+
126+
In a domain compiler: the grammar defines what structures are legal. The I-language is the grammar *plus* all canonical concepts *plus* the populated knowledge graph *plus* the extraction/query pipelines. Two systems with identical grammars but different corpora have different I-languages.
127+
128+
| Chomsky | Domain Compiler | Why it matters |
129+
|---|---|---|
130+
| **Grammar** (formal rules) | Field definitions, vertex/edge types, query patterns | The explicit specification — what structures are legal |
131+
| **I-language** (internalized system) | Grammar + canonical concepts + KG + pipelines | The operational competence — what the system actually knows |
132+
| **Primary linguistic data** | Source corpus | The input from which the I-language is acquired |
133+
| **Competence** | What the grammar can express | Valid structures, independent of any particular execution |
134+
| **Performance** | What extraction/query actually produces | Particular executions, subject to LLM errors and cost constraints |
135+
136+
The I-language is a cross-cutting surface, not a layer in a stack. It spans both the ETL layer (ingestion) and the query layer (retrieval):
137+
138+
```
139+
Source text ──► text2concept_ir ──┐
140+
├──► Concept IR
141+
User question ► query2concept_ir ──┘
142+
143+
┌──────────┴──────────┐
144+
▼ ▼
145+
Query Plan Graph Patch
146+
(KG read) (KG write)
147+
```
148+
149+
Both inputs converge into the **same Concept IR**, then diverge into different executable forms. This symmetry guarantees:
150+
151+
- **Semantic alignment**: questions and answers inhabit the same representational space
152+
- **Explainability**: every answer traces back through the same IR
153+
- **Reproducibility**: same input → same Concept IR → same execution
154+
155+
Most RAG systems embed documents and queries into the same vector space but have no shared *semantic* structure. That is why they hallucinate.
156+
157+
---
158+
159+
## 5. Ontology: Entity vs. Process vs. Artifact
160+
161+
The ontology layer provides three primitive categories, grounded in BFO (Basic Formal Ontology) [2]:
162+
163+
```
164+
┌─────────────────────────────────────────────────────────┐
165+
│ Layer 4: SEMANTIC GRAMMAR │
166+
│ Relations that bind concepts into structured claims │
167+
├─────────────────────────────────────────────────────────┤
168+
│ Layer 3: ARTIFACTS │
169+
│ What we know — claims about reality │
170+
├─────────────────────────────────────────────────────────┤
171+
│ Layer 2: PROCESSES │
172+
│ What happens — things that unfold in time │
173+
├─────────────────────────────────────────────────────────┤
174+
│ Layer 1: ENTITIES │
175+
│ What exists — things that persist through time │
176+
└─────────────────────────────────────────────────────────┘
177+
```
178+
179+
The core design rule: **model both the handle (entity) and the flux (process), and relate them via participation.**
180+
181+
- An **entity** *persists* — it exists at any point in time you check. "Metformin" exists whether or not anyone is taking it. (BFO: Continuant)
182+
- A **process** *unfolds* — it has temporal parts, a beginning and end. "Taking metformin 500mg daily for 12 weeks" is a process. (BFO: Occurrent)
183+
- An **artifact** asserts a relationship between entities and processes, but is neither. Two artifacts can contradict each other and both exist in the graph. (BFO: Information Content Entity)
184+
185+
### Why the split matters: three engineering rules
186+
187+
**Rule 1: Entities can be shared across sources. Processes cannot.**
188+
Two studies can reference the same intervention node (metformin) and the same condition node (T2D). But the specific dosing course is unique to one study arm. This is what makes cross-source queries work — traversal through shared entity nodes.
189+
190+
**Rule 2: Processes carry temporal structure. Entities don't.**
191+
If you put "duration: 12 weeks" on an entity node, two sources with different durations can't share the same node. The entity/process split prevents this.
192+
193+
**Rule 3: Artifacts are epistemic — they assert claims, not facts.**
194+
Two findings can contradict each other and both coexist in the graph. This is epistemic scoping, and it's what makes contradiction detection possible.
195+
196+
### Entity vs. Process in action
197+
198+
Without the split — broken:
199+
200+
```
201+
// BAD: temporal detail baked into entity
202+
(:Intervention {name: "metformin", dose: "2g/day", duration: "24 weeks"})
203+
```
204+
205+
Two sources with different doses fork the entity into N copies. Cross-source queries require fuzzy matching.
206+
207+
With the split — correct:
208+
209+
```
210+
// GOOD: entity (shared) + process (per-source)
211+
(:Intervention {name: "metformin"})
212+
←[:REALIZES]─ (:ExposureCourse {dose: "2g/day", duration: "24w"}) // Source A
213+
←[:REALIZES]─ (:ExposureCourse {dose: "500mg/day", duration: "12w"}) // Source B
214+
```
215+
216+
One node. Two process instances. All queries traverse through a single shared entity.
217+
218+
---
219+
220+
## 6. Why Graph over SQL, Why Graph over LLM
221+
222+
### Graph vs. SQL
223+
224+
SQL handles single-entity lookups. Graphs pull ahead when questions cross entity boundaries — which is every interesting question in a knowledge system.
225+
226+
**"What shares a mechanism with X?"**
227+
SQL: 12 joins across 8 tables, recursive CTEs for sub-mechanism traversal.
228+
Graph: start at X, follow `ACTS_VIA` to the mechanism node, follow back. Two hops.
229+
230+
**"What helps with Y but doesn't cause Z?"**
231+
SQL: LEFT JOIN to exclude adverse-event rows. Grows ugly with multiple exclusion criteria.
232+
Graph: one `NOT EXISTS` clause per excluded outcome.
233+
234+
### Graph vs. LLM (ChatGPT)
235+
236+
An LLM gives you a conclusion. A graph gives you a map you can navigate, verify, and challenge.
237+
238+
| | LLM | Graph |
239+
|---|---|---|
240+
| **Completeness** | Frozen training snapshot; can't tell you what's missing | Contains all extracted claims |
241+
| **Provenance** | Can't show *why* it believes something | Every claim traces to source |
242+
| **Contradictions** | Averages or hedges | Both sides coexist as first-class entities |
243+
244+
```mermaid
245+
flowchart LR
246+
subgraph LLM["LLM Approach"]
247+
direction LR
248+
Q1[Question] -->|embed| V[Vector Search]
249+
V --> D1[Doc A]
250+
V --> D2[Doc B]
251+
D1 --> L[LLM]
252+
D2 --> L
253+
L --> A1["Answer: text synthesis<br>(trust me)"]
254+
end
255+
256+
subgraph Graph["Graph Approach"]
257+
direction LR
258+
Q2[Question] -->|constraints| G[(Knowledge Graph)]
259+
G --> I[Entity]
260+
I --> M[Mechanism]
261+
M --> O1[Outcome: Benefit]
262+
M --> O2[Outcome: Harm]
263+
O1 --> A2["Answer: subgraph<br>(trace it yourself)"]
264+
O2 --> A2
265+
end
266+
267+
style LLM fill:#fdecea,stroke:#c62828
268+
style Graph fill:#e8f5e9,stroke:#2e7d32
269+
```
270+
271+
Three structural advantages:
272+
273+
1. **Auditable precision** — every claim traces to a source node with a real identifier. The citation isn't generated text; it's a node in the graph.
274+
275+
2. **Auditable recall** — the system shows what it considered, what it filtered, and what survived. The user can inspect the query, challenge it, modify it. Try doing that with an embedding similarity search.
276+
277+
3. **Auditable reasoning** — the answer is a subgraph, not text. Every hop is a typed edge. The reasoning path *is* the answer.
278+
279+
---
280+
281+
## 7. Build Principles
282+
283+
### Grammar is discovered, not just defined
284+
285+
The model above is linear (Mission → Grammar → Execution). The actual system is a flywheel:
286+
287+
```
288+
source text → AI extraction → reveals grammar gaps → grammar evolves → re-extraction → re-eval
289+
```
290+
291+
Each source document processed is "primary linguistic data" (in the Chomsky sense) that shapes the system's evolving I-language. The grammar specification is never finished — it co-evolves with the corpus.
292+
293+
### Cycle depth and blast radius
294+
295+
Not every cycle mutates the deepest layer. Deeper changes are rarer, slower, and higher-impact:
296+
297+
| Layer | Change frequency | Blast radius |
298+
|---|---|---|
299+
| **Prompts / rules / mappings** | Every session | Local |
300+
| **Schema / artifacts** | Weekly | Moderate — re-derive downstream |
301+
| **Domain grammar** | Monthly | Large — new extraction + query patterns + evals |
302+
| **Ontology** | Rarely | Structural — ripples everywhere |
303+
304+
Most improvement is shallow (fix a prompt, add an alias). Deep changes (restructure the grammar, add a new ontology primitive) are rare but transformative.
305+
306+
### Ambiguity is the main enemy
307+
308+
An LLM reduces ambiguity *probabilistically* — it picks the most likely interpretation and moves on. A domain grammar eliminates ambiguity *formally* or, when elimination is impossible, surfaces it explicitly so the user decides.
309+
310+
Five classes of ambiguity that attack knowledge systems:
311+
312+
| Class | Example | Grammar component that addresses it |
313+
|---|---|---|
314+
| **Terminology** | "blood sugar" — fasting glucose, HbA1c, or OGTT? | Vocabulary: canonical entities + surface-form mapping |
315+
| **Structural** | "X reduced Y" — compared to what? | Ontology: composition requires comparator edge |
316+
| **Retrieval** | Which candidates were considered? | Compiled queries: deterministic traversal, visible filter logic |
317+
| **Reasoning path** | Same mechanism ≠ same outcome | Reasoning subgraph: shows shared path AND divergent outcomes |
318+
| **Answer composition** | Which variant, dose, metric? | Findings IR: each claim is a separate typed node |
319+
320+
---
321+
322+
## 8. The Rosetta Stone: Multi-IR Translation
323+
324+
A general-purpose knowledge system sits between multiple source languages and multiple query languages. The knowledge graph is the pivot:
325+
326+
```
327+
SOURCE IRs QUERY IRs
328+
(each mirrors its source) (each mirrors the asker)
329+
330+
Source Type A IR ──→ ←── Audience X IR
331+
┌──┐
332+
Source Type B IR ──→ ──→│KG│←── ←── Audience Y IR
333+
└──┘
334+
Source Type C IR ──→ ←── Audience Z IR
335+
```
336+
337+
**No source knows about any query type. No query type knows about any source. They only know the graph.**
338+
339+
Each source type gets its own extraction IR that mirrors its natural shape. All compile deterministically to the same serving IR. This is the architectural moat.
340+
341+
### The two-IR pattern
342+
343+
| IR | Purpose | Mirrors |
344+
|---|---|---|
345+
| **Extraction IR** | How the annotator/model reasons | Source structure |
346+
| **Serving IR** | What gets output and queried | User queries |
347+
348+
Sources are structured around their native logic, but users ask flat questions. If we extract in user-query shape, we lose structural detail. If we serve in source shape, users can't query it. Two IRs let each layer use its natural shape.
349+
350+
---
351+
352+
## References
353+
354+
[1] Chomsky, N. (1986). *Knowledge of Language: Its Nature, Origin, and Use*. Praeger. — Introduces the I-language / E-language distinction: I-language is the internalized computational system; E-language is the set of externalizations.
355+
356+
[2] Arp, R., Smith, B., & Spear, A.D. (2015). *Building Ontologies with Basic Formal Ontology*. MIT Press. — BFO provides the upper ontology: Continuant (entities that persist), Occurrent (processes that unfold), Information Content Entity (artifacts/claims).
357+
358+
[3] Aho, A.V., Lam, M.S., Sethi, R., & Ullman, J.D. (2006). *Compilers: Principles, Techniques, and Tools* (2nd ed.). Addison-Wesley. — The dragon book. Source → IR → executable is the canonical compilation pipeline this architecture adapts.
359+
360+
[4] Chomsky, N. (1995). *The Minimalist Program*. MIT Press. — The framework from which we borrow: merge as the basic structure-building operation, the competence/performance distinction, and the primacy of internal grammar over surface realization.
361+
362+
[5] Robinson, I., Webber, J., & Eifrem, E. (2015). *Graph Databases* (2nd ed.). O'Reilly Media. — The case for graph databases over relational for traversal-heavy queries: identity-preserving nodes, typed edges, variable-length paths.

index.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Boris Dev — Papers
2+
3+
---
4+
5+
## Papers
6+
7+
| # | Title | Topic |
8+
|---|-------|-------|
9+
| 1 | [Domain Grammar as Compiler Architecture for Knowledge Systems](domain-grammar-compiler.md) | Domain grammars, knowledge graphs, Chomsky's I-language, compiler IR design |
10+
11+
---
12+
13+
*More papers coming soon.*

0 commit comments

Comments
 (0)