- Complete Quickstart to understand basic operations
- Read Ontologies to understand the concepts
- Ensure you have LLM Providers configured
- Have an OWL ontology file (
.owl
) in RDF/XML format - Have some text or files relevant to the ontology’s domain
What Ontology Support Does
- Grounds entities and relations to your OWL ontology (classes, individuals, properties)
- Validates types via ontology domains/ranges and class hierarchy
- Improves graph completion answers for domain-specific queries
Step 1: Prepare an Ontology File
Start from a simple OWL file. Minimal ingredients:- Classes (e.g.,
TechnologyCompany
,Car
) - Individuals (e.g.,
Apple
,Audi
) - Object properties with domain/range (e.g.,
produces
withdomain=CarManufacturer
,range=Car
)
examples/python/ontology_input_example/basic_ontology.owl
examples/python/ontology_input_example/enriched_medical_ontology_with_classes.owl
Use any RDF/OWL editor (Protégé) to edit .owl files.
This example uses a simple ontology for demonstration. In practice, you can work with larger, more complex ontologies - the same approach works regardless of ontology size or complexity.
Step 2: Add Your Data
Add either raw text or a directory. Keep it relevant to your ontology.This simple example uses a list of strings for demonstration. In practice, you can add multiple documents, files, or entire datasets - the ontology processing works the same way across all your data.
Step 3: Cognify Your Data + Ontologies
Passontology_file_path
to ground extracted entities/relations to the ontology.
If omitted, Cognee builds a graph without ontology grounding. With an ontology, Cognee aligns nodes to classes/individuals and enforces property domain/range.
Step 4: Ask Ontology-aware Questions
UseSearchType.GRAPH_COMPLETION
to get answers that leverage ontology structure.
Phrase questions using ontology terms (class names, individual names, property language like “produces”, “develops”). If results feel generic, check that the ontology contains the expected classes/individuals and that your data mentions them.
Full Working Examples
- Small cars/tech demo:
examples/python/ontology_demo_example.py
- Medical comparison demo:
examples/python/ontology_demo_example_2.py