TrustGraphGet Started

Ontology RAG

A Retrieval-Augmented Generation technique that uses formal ontologies (OWL schemas) to guide the extraction of structured, typed knowledge from unstructured text, producing conformant Knowledge Graphs with validated entity types and relationships.

Core Concepts

Ontology RAG is a schema-driven approach to Retrieval-Augmented Generation that uses formal ontologies to guide knowledge extraction. Unlike GraphRAG, which discovers structure automatically, Ontology RAG ensures extracted entities and relationships conform to predefined types and constraints defined in OWL (Web Ontology Language) schemas.

How Ontology RAG Works

Ontology RAG follows an 8-step pipeline:

  1. Define Ontology: Create OWL schema with entity types, properties, and constraints
  2. Configure Flow: Set up processing pipeline with ontology reference
  3. Ingest Documents: Add unstructured text to document library
  4. Process with Ontology: Extract entities that match ontology classes
  5. Validate Structure: Ensure extracted graph conforms to ontology rules
  6. Store in Knowledge Graph: Save typed, validated triples
  7. Query with Schema: Leverage ontology for intelligent queries
  8. Reason with Inference: Apply ontology rules for deductive reasoning

Ontology RAG vs GraphRAG

AspectGraphRAGOntology RAG
SchemaSchema-free, discovers structureSchema-driven, follows ontology
Entity TypesDiscovered from textPredefined in ontology
RelationshipsAutomatically discoveredConstrained by ontology
ValidationNone (flexible)Strict (conformance required)
ReasoningGraph-based inferenceOntology-based deduction
Best ForExploratory analysis, unknown domainsStructured domains, regulatory compliance

Key Components

OWL Ontology

Defines the semantic structure:

@prefix : <http://example.org/sensors#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

:Sensor a owl:Class ;
    rdfs:label "Sensor" .

:Observation a owl:Class ;
    rdfs:label "Observation" .

:madeBySensor a owl:ObjectProperty ;
    rdfs:domain :Observation ;
    rdfs:range :Sensor .

Typed Entity Extraction

LLM extracts entities that match ontology classes:

{
  "@type": "Sensor",
  "id": "sensor_12345",
  "name": "Temperature Monitor Alpha",
  "type": "TemperatureSensor"
}

Conformance Validation

Ensures extracted knowledge follows ontology rules:

  • Entity types must exist in ontology
  • Properties must be defined for those types
  • Relationships must respect domain/range constraints
  • Cardinality rules must be satisfied

When to Use Ontology RAG

Choose Ontology RAG when:

  • Domain expertise exists: Well-defined ontology available
  • Type safety required: Strict entity types needed
  • Compliance necessary: Regulatory or standards compliance
  • Reasoning needed: Formal logical inference required
  • Integration critical: Must match existing systems
  • Quality over quantity: Precision more important than coverage

Choose GraphRAG when:

  • Domain is new or evolving
  • Exploratory analysis needed
  • Flexibility more important than conformance
  • Discovering unknown patterns

TrustGraph CLI Usage

Configure and run Ontology RAG:

# Define ontology
cat domain-ontology.json | tg-put-config-item \
  --type ontology \
  --key my-ontology \
  --stdin

# Start Ontology RAG flow
tg-start-flow \
  -n onto-rag \
  -i onto-rag \
  -d "Ontology RAG with domain ontology"

# Process documents with ontology
tg-start-library-processing \
  --flow-id onto-rag \
  --document-id doc-id \
  --collection domain-docs

# Query typed knowledge
tg-invoke-graph-rag \
  -f onto-rag \
  -C domain-docs \
  -q "Find all Sensors that made Observations"

Benefits

  1. Type Safety: Guaranteed entity types and relationships
  2. Validation: Automatic conformance checking
  3. Reasoning: Formal logical inference from ontology
  4. Interoperability: Standard ontologies enable data exchange
  5. Quality Assurance: Errors caught during extraction
  6. Documentation: Ontology documents knowledge structure
  7. Reusability: Ontologies reusable across projects

Use Cases

  • Intelligence Analysis: Typed threat actors, sensors, locations
  • Scientific Research: Domain-specific entity extraction
  • Regulatory Compliance: Structured data meeting standards
  • Healthcare: Medical ontologies (SNOMED, ICD)
  • Industrial IoT: Sensor networks with SOSA/SSN ontology
  • Legal Documents: Legal concept extraction

Advanced Features

Reasoning and Inference

Ontology RAG applies logical rules:

# Ontology rule
:TemperatureSensor rdfs:subClassOf :Sensor .

# Extracted entity
<sensor_123> a :TemperatureSensor .

# Inferred fact (automatic)
<sensor_123> a :Sensor .

Multi-Ontology Support

Combine multiple ontologies:

  • Core ontology: Domain fundamentals
  • Extension ontologies: Specialized concepts
  • Mapping ontologies: Link to external standards

Ontology Evolution

Version and update ontologies:

  • Add new classes and properties
  • Deprecate obsolete concepts
  • Maintain backward compatibility
  • Migrate existing knowledge graphs

Examples

  • Using SOSA/SSN ontology to extract sensor observations, measurements, and properties from intelligence reports with strict type conformance
  • Intelligence analysis systems extracting typed entities (ThreatActor, Sensor, Location) that conform to predefined security ontologies
  • Extracting maritime vessel tracking data that conforms to domain-specific shipping ontologies with validated relationships

Related Terms

Learn More