> ## 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.

# Ontology Quickstart

> Step-by-step guide to using OWL ontologies to ground Cognee knowledge graphs

A minimal guide to using OWL ontologies to ground Cognee's knowledge graphs. The guide uses `remember()` so the data and ontology config are processed together in one call.

**Before you start:**

* Complete [Quickstart](getting-started/quickstart) to understand basic operations
* Read [Ontologies](../core-concepts/further-concepts/ontologies) to understand the concepts
* Ensure you have [LLM Providers](setup-configuration/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` with `domain=CarManufacturer`, `range=Car`)

Example ontology files:

* `examples/guides/ontology_input_example/basic_ontology.owl` ([GitHub](https://github.com/topoteretes/cognee/blob/dev/examples/guides/ontology_input_example/basic_ontology.owl))

<Tip>
  Use any RDF/OWL editor (Protégé) to edit .owl files.
</Tip>

<Note>
  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.
</Note>

## Step 2: Prepare Your Data

Add either raw text or a directory. Keep it relevant to your ontology.

```python theme={null}
texts = [
    "Audi produces the R8 and e-tron.",
    "Apple develops iPhone and MacBook."
]
```

<Note>
  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.
</Note>

## Step 3: Remember Your Data with the Ontology Config

Create the `config` that contains the ontology information, then pass it directly to `remember()`.

```python theme={null}
# Create full config structure manually
config: Config = {
    "ontology_config": {
        "ontology_resolver": RDFLibOntologyResolver(ontology_file=ontology_path)
    }
}

await cognee.remember(texts, config=config, self_improvement=False)
```

<Info>
  If omitted, Cognee builds memory without ontology grounding. With an ontology config, Cognee aligns nodes to classes and individuals while processing the remembered data.
</Info>

## Hot Reload and File Updates

Ontology files are parsed **once at initialization** — when `RDFLibOntologyResolver` is constructed, it reads and parses the file with RDFLib and caches the result in memory. There is no automatic file system monitoring, so changes to the `.owl` file on disk are not picked up while a session or server is running.

## Full Example

<Accordion title="Latest guide">
  ```python theme={null}
  import asyncio
  import cognee
  import os
  from cognee.modules.ontology.ontology_config import Config
  from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver


  async def main():
      # Prune data and system metadata before running, only if we want "fresh" state.
      await cognee.forget(everything=True)

      texts = ["Audi produces the R8 and e-tron.", "Apple develops iPhone and MacBook."]

      ontology_path = os.path.join(
          os.path.dirname(os.path.abspath(__file__)), "ontology_input_example/basic_ontology.owl"
      )

      # Create full config structure manually
      config: Config = {
          "ontology_config": {
              "ontology_resolver": RDFLibOntologyResolver(ontology_file=ontology_path)
          }
      }

      await cognee.remember(texts, config=config, self_improvement=False)


  if __name__ == "__main__":
      asyncio.run(main())
  ```
</Accordion>

<Accordion title="Legacy guide">
  ```python theme={null}
  import cognee
  import os
  from cognee.modules.ontology.ontology_config import Config
  from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver

  ontology_path = os.path.join(
      os.path.dirname(os.path.abspath(__file__)), "ontology_input_example/basic_ontology.owl"
  )

  # Create full config structure manually
  config: Config = {
      "ontology_config": {
          "ontology_resolver": RDFLibOntologyResolver(ontology_file=ontology_path)
      }
  }

  await cognee.cognify(config=config)
  ```
</Accordion>

* Basic ontology demo script can be found on the following [link](https://github.com/topoteretes/cognee/blob/dev/examples/guides/ontology_quickstart.py)
* Advanced ontology demo script can be found on the following [link](https://github.com/topoteretes/cognee/blob/dev/examples/demos/ontology_reference_vocabulary/ontology_as_reference_vocabulary_example.py)

<Columns cols={3}>
  <Card title="Core Concepts" icon="brain" href="/core-concepts/further-concepts/ontologies">
    Understand ontology fundamentals
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/introduction">
    Explore ontology API endpoints
  </Card>
</Columns>
