> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Ontologies

> Enrich your knowledge graph with external vocabularies

## What is an ontology in Cognee?

An **ontology** is an optional RDF/OWL file you can provide to Cognee.
It acts as a **reference vocabulary**, making sure that entity types ("classes") and entity mentions ("individuals") extracted from your data are linked to canonical, well-defined concepts.

## How it works

* You pass `ontology_file_path="my_ontology.owl"` when running [Cognify](../main-operations/legacy-operations/cognify).
* Cognee parses the file with [RDFLib](https://rdflib.dev/) and loads its classes and relationships.
* During graph extraction, entities and types are checked against the ontology:
  * If a match is found, the node is marked `ontology_valid=True`.
  * Parent classes and object-property links from the ontology are attached as extra edges.
* If no ontology is provided, extraction still works, just without validation or enrichment.

## Why use an ontology

* **Consistency**: standardize how entities and types are represented
* **Enrichment**: bring in inherited relationships from a domain schema
* **Control**: align Cognee's graph with existing enterprise or scientific vocabularies

## Where to get ontologies

Cognee works best with **manually curated, focused ontologies** that fit your dataset. Ontology design itself is outside the scope of Cognee, so if you need to create or model an ontology from scratch, use dedicated ontology tools and references first, then bring the resulting RDF/OWL file into Cognee.

Public resources like **Wikidata** or **DBpedia** define millions of classes and entities, which makes them too big to use directly in Cognee. If you start from a public ontology, always work with a subset, not the full ontology:

* **Select only the pieces you need** (specific classes, properties, or individuals)
* **Save the subset** in a format Cognee can parse with [`rdflib`](https://rdflib.readthedocs.io/)
* **If needed, enrich the subset manually** by adding extra classes or relationships relevant to your domain
* **Keep it small and relevant** so matching stays precise and performance remains fast

<AccordionGroup>
  <Accordion title="Common sources">
    - **General vocabularies**: schema.org, Dublin Core Terms (DC/Terms), SKOS, PROV-O, FOAF
    - **Knowledge graph backbones**: DBpedia Ontology, Wikidata (Wikibase RDF ontology)
    - **Domain examples**:
      * Healthcare: SNOMED CT (licensed), ICD, UMLS, MeSH, HL7/FHIR RDF
      * Finance: FIBO (Financial Industry Business Ontology)
      * Geo/IoT: GeoSPARQL, SOSA/SSN, GeoNames
      * Units: QUDT
  </Accordion>

  <Accordion title="Why subsetting is essential">
    Every public ontology is **too broad to ingest wholesale**. Creating a subset is what makes them usable in Cognee:

    * Improves matching precision (fewer false matches when mapping LLM output)
    * Keeps performance acceptable (smaller graphs → faster resolution)
    * Lets you curate only the relevant parts of a domain
  </Accordion>

  <Accordion title="How subsetting works">
    Different communities provide different ways to extract subsets (e.g., "slims" in OBO ontologies, WDumper for Wikidata, module extraction in Protégé). The details vary, but the general principle is the same:

    1. Pick the terms (classes or properties) you care about
    2. Extract those terms plus their immediate context (e.g. parent classes, related properties)
    3. Save the result in an `rdflib`-readable RDF format
  </Accordion>
</AccordionGroup>

## Supported formats

Any format [RDFLib](https://rdflib.readthedocs.io/) can parse:

* RDF/XML (`.owl`, `.rdf`)
* Turtle (`.ttl`)
* N-Triples, JSON-LD, and others

## Additional details and examples

<AccordionGroup>
  <Accordion title="Practical example">
    Once you have your subset file, integrating it into Cognee is simple:

    ```python theme={null}
    import cognee

    await cognee.cognify(
        datasets=["my_dataset"],
        ontology_file_path="subset.owl",  # your curated subset here
    )
    ```
  </Accordion>

  <Accordion title="Using multiple ontology files">
    Cognee can load several OWL files and merge them into one in-memory graph, which is useful when you split a large ontology into focused modules.

    **Environment variable — comma-separated paths:**

    ```bash theme={null}
    ONTOLOGY_FILE_PATH=/path/to/domain.owl,/path/to/entities.owl
    ```

    **Python API — list of paths:**

    ```python theme={null}
    from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
    from cognee.modules.ontology.ontology_config import Config

    resolver = RDFLibOntologyResolver(
        ontology_file=["/path/to/domain.owl", "/path/to/entities.owl"]
    )

    config: Config = {"ontology_config": {"ontology_resolver": resolver}}
    await cognee.cognify(config=config)
    ```

    Files that cannot be found or parsed are skipped with a warning; at least one valid file is required for ontology grounding to take effect.
  </Accordion>

  <Accordion title="Creating or editing ontologies">
    Cognee does not provide ontology-authoring features. If you need to create, edit, or validate an ontology, use dedicated RDF/OWL tooling such as Protégé or your team's existing ontology workflow, then load the resulting file into Cognee.

    When preparing a file for Cognee:

    * Keep the ontology focused on the classes, properties, and individuals relevant to your dataset
    * Prefer a curated subset over a large general-purpose ontology
    * Save it in a format RDFLib can parse, such as RDF/XML (`.owl`, `.rdf`) or Turtle (`.ttl`)
  </Accordion>
</AccordionGroup>

For more detailed examples of working with ontologies in Cognee, check out the demo scripts in the repository:

* [Basic ontology demo](https://github.com/topoteretes/cognee/tree/main/examples/guides) - Shows fundamental ontology integration
* [Advanced ontology demo](https://github.com/topoteretes/cognee/tree/main/examples/demos/ontology_reference_vocabulary) - Demonstrates more complex ontology workflows
