Cognee let’s you organize and model your user’s data for LLMs to use.
In this way you can choose how to load only the data you need.
Let’s say you need all persons mentioned in a novel.
We enable you to:
Specify which persons you want extracted
Load them into the cognee data store
Retrieve them with natural language query
In other words, custom models let you define the structure of your graph, or impose certain structures on it. You can control what nodes get created and how they’re connected. This is useful when dealing with structured or semi-structured data, though they do require some manual coding.
Let’s try it out!
Why is this important? Let’s visualize our data before and after.On this image you can see that purple color nodes are exactly the nodes that represent people mentioned in the novel.Let’s create the graph ourselves.
Create a Python script called example_ontology.py and copy the content from the following file:Custom Model ExampleThis example demonstrates how to define custom Pydantic models for specific data extraction.
The script will create an HTML file in the cognee directory (.artifacts/graph_visualization.html) that you can inspect and check the graph. You can also run a small HTTP server that will render your semantic layer: