Dynamic Ontology
Terraphim's Dynamic Ontology enables schema-first knowledge graph construction with coverage governance signals. This document explains the architecture, feature gates, and usage.
Overview
Dynamic Ontology is a schema-first approach to knowledge graphs inspired by Akash Goyal's methodology. It provides:
- Two-layer architecture: Curated schema + ontology catalog
- Extraction: LLM-based entity extraction with schema signals
- Normalization: Aho-Corasick + fuzzy matching (no vector embeddings needed)
- Coverage governance: Quality signals to judge extraction quality
- Grounding metadata: Canonical URIs for interoperability
Architecture
Text Input
↓
┌─────────────────────────────────────────────┐
│ Multi-Agent Orchestration │
├─────────────────────────────────────────────┤
│ 1. Extraction Agent → Schema signals │
│ 2. Normalization Agent → Graph + fuzzy │
│ 3. Coverage Agent → Governance signal │
│ 4. Review Agent → QA on low-confidence │
└─────────────────────────────────────────────┘
↓
Grounded Knowledge GraphFeature Gates
The Dynamic Ontology module uses Rust feature gates to support both generic and domain-specific use cases:
| Feature | Description |
|---------|-------------|
| ontology (default) | Core generic types (GroundingMetadata, CoverageSignal, SchemaSignal) |
| medical | Medical/oncology EntityType/RelationshipType enums |
| hgnc | HGNC gene normalization (EGFR, TP53, KRAS, etc.) |
Feature Hierarchy
ontology (default)
↓
medical (implies ontology)
↓
hgnc (implies medical)Usage
# Cargo.toml
[dependencies]
terraphim_types = { version = "1.4", features = ["ontology"] } # Generic only
terraphim_types = { version = "1.4", features = ["medical"] } # Medical types
terraphim_types = { version = "1.4", features = ["hgnc"] } # Full medical + HGNCCore Types
GroundingMetadata
NormalizationMethod
CoverageSignal
SchemaSignal
Medical Entity Types (feature-gated)
When medical feature is enabled:
Usage Examples
Basic Entity Extraction
use ;
// Create extracted entity
let entity = ExtractedEntity ;
// Compute coverage
let categories = vec!;
let coverage = compute;
println!;HGNC Gene Normalization (requires hgnc feature)
use HgncNormalizer;
let normalizer = new;
// Exact match
let result = normalizer.normalize;
assert!;
// Alias resolution (ERBB1 -> EGFR)
let result = normalizer.normalize;
assert_eq!;
// Fuzzy variant matching (EGFRvIII -> EGFR)
let result = normalizer.normalize;
assert_eq!;Knowledge Graph Normalization Example
The kg_normalization example demonstrates full pipeline:
This example:
- Loads markdown documents from a knowledge corpus
- Builds ontology with extracted terms
- Extracts entities from sample text
- Computes coverage signals
- Exports thesaurus for Terraphim automata
Multi-Agent Workflow
The terraphim_multi_agent crate provides specialized agents:
use ;
// Create extraction agent
let extraction_agent = new?;
// Extract schema signal
let schema_signal = extraction_agent.extract.await?;
// Create normalization agent with ontology terms
let normalizer = new?;
let normalized = normalizer.normalize.await?;
// Compute coverage
let coverage_agent = new;
let coverage = coverage_agent.compute_coverage;
// Review low-confidence matches
let review_agent = new?;
let reviewed = review_agent.review.await?;Coverage Governance
Coverage signals provide quality governance:
| Coverage Ratio | Status | Action | |----------------|--------|--------| | >= 70% | Excellent | Proceed | | 40-70% | Good | Minor review | | 20-40% | Needs improvement | Expand ontology | | < 20% | Poor | Different approach needed |
Performance
- No vector embeddings required - Uses existing Aho-Corasick + fuzzy matching
- Graph ranking - Leverages existing rolegraph node rankings
- Feature-gated - Pay only for what you use