Use ohi with Cognee
Use ohi to give Cognee standard ontologies in OWL format. Cognee turns documents, chats or code into knowledge graphs used by AI agents. On its own, Cognee makes up labels for the people, companies and other things it finds, so the same thing can end up with different labels. An ontology gives it a fixed set of terms to use instead.
ohi finds these ontologies, downloads them with their dependencies and pins their versions in a lock file. Everyone on your team then loads the same files, so everyone’s graph uses the same terms. This guide uses W3C Organization and FOAF.
To use other ontologies, search on ohi.dev or use ohi search.
How ohi and Cognee work together
Section titled “How ohi and Cognee work together”- ohi downloads the ontologies as
.owlfiles. It writes down which ones you chose inohi.yaml, and the exact files inohi.lock.json. - Your script gives Cognee the paths to those files.
- When Cognee reads your data, it checks each thing it finds against the ontologies.
Before you begin
Section titled “Before you begin”- Python 3.10 to 3.14.
- ohi installed.
- Cognee installed.
Download the ontologies with ohi
Section titled “Download the ontologies with ohi”-
Create a project that saves ontologies as
.owlfiles in anontologiesfolder:Terminal window ohi init cognee-ontologies --default_format owl-turtle --to ontologiescd cognee-ontologiesCognee’s documentation uses
owl-rdfxml, butowl-turtleworks just as well and it is much easier to read and review. -
Add your ontologies:
Terminal window ohi add w3c/org@2014ohi add foaf/foaf@2014-01-14Each one lands in its own folder, such as
ontologies/w3c/org/2014/, along with any ontologies it depends on. -
Check that the files are there:
Terminal window find ontologies -name '*.owl*'In PowerShell, run
Get-ChildItem ontologies -Recurse -Filter *.owl*. You should see two files,org.owl.ttlandfoaf.owl.ttl. -
Commit
ohi.yamlandohi.lock.jsonto git. Your teammates can then runohi syncto get the exact same files, so everyone’s graph uses the same ontology terms. Learn more in Manage ontology projects.
Load your data into Cognee with the ontologies
Section titled “Load your data into Cognee with the ontologies”This is the script from Cognee’s Ontology Quickstart, with ontology_path pointed at the files you just downloaded and the forget line commented out.
-
Save this script as
ontology_quickstart.pyin the project folder.Careful:
cognee.forget(everything=True)deletes everything Cognee has stored on your computer.import asynciofrom pathlib import Pathimport cogneefrom cognee.modules.ontology.ontology_config import Configfrom cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolverasync def main():# Uncomment to start from a clean state. This deletes all Cognee data.# await cognee.forget(everything=True)texts = ["Winnie the Pooh works at Tesla as head of eco-honey program."]# Changed ontology_path: every .owl file ohi downloaded.ontology_path = [str(p) for p in Path(__file__).parent.glob("ontologies/**/*.owl*")]# Create full config structure manuallyconfig: Config = {"ontology_config": {"ontology_resolver": RDFLibOntologyResolver(ontology_file=ontology_path)}}# self_improvement=False skips Cognee's extra enrichment pass, which makes more LLM calls.# The graph is built either way.await cognee.remember(texts, config=config, self_improvement=False)if __name__ == "__main__":asyncio.run(main()) -
Run it:
Terminal window python ontology_quickstart.py
To try it on your own data, replace texts with your own text. You can also pass a file path, or a list of paths.
The script loads every ontology file under ontologies/, so ontologies you add later are picked up automatically.
Check that Cognee used your ontologies
Section titled “Check that Cognee used your ontologies”The easiest way to check is to look at the graph. Save this as show_graph.py in the project folder, run it with python show_graph.py, and open graph.html in your browser:
import asyncio
import cognee
asyncio.run(cognee.visualize_graph("graph.html"))
Pink nodes with a green ring come from your ontologies. Here, Winnie the Pooh is linked to person and the eco-honey program to project, both from FOAF. Tesla is linked to formalorganization from W3C Organization. That term comes from ontologies/w3c/org/2014/org.owl, the file ohi downloaded.
Click a node with a green ring to see where it came from. Here, person groups Winnie the Pooh and is marked ontology valid, so Cognee took it from FOAF.

If no node has a green ring, check the start of Cognee’s log. If there are no Ontology loaded successfully lines, Cognee didn’t find the files: check that the script is next to ohi.yaml and that the ontologies folder has .owl or .owl.ttl files in it.
Update the ontologies
Section titled “Update the ontologies”- Find the latest version with
ohi inspect <ontology_id>, for exampleohi inspect w3c/org. - Change the version in
ohi.yamland runohi sync. - The new version goes into a new folder, named after its version. Delete the old version’s folder, so the script doesn’t load both.
- Delete the old graph and build it again with the new terms: add
await cognee.forget(dataset="main_dataset")at the start ofmain()and run the script. If you use Cognee inside an app that keeps running, restart it.
Clean up
Section titled “Clean up”- To delete everything Cognee stored, uncomment the
cognee.forget(everything=True)line in the script and run it again. - To remove the ontologies, delete the
ontologiesfolder.ohi syncbrings them back.
Get help
Section titled “Get help”NeverBlink, the team behind ohi, maintains this guide, not the Cognee team. If something does not work, open an ohi issue or ask on Discord. For problems with Cognee itself, use the Cognee issue tracker.