In one line: an ontology writes down what the data means, next to the data, in a form machines can read. It pays off when the people who use the data are not the people who made it, and when answers have to be checked.
Short answers
- Why not just join tables in a relational database?
- If there is one source and one team knows its schema, a relational database is enough. With many sources, the knowledge of which columns refer to the same thing lives outside the schema, in people and mapping code, and that becomes the main cost. An ontology states that meaning next to the data with IRIs and relations such as subClassOf, which cuts the number of mappings and lets a reasoner answer queries asked at a broader concept.
- Why not a vector database or a better LLM?
- Vector search is cheap and good at finding and summarising similar documents. But questions that count, list everything, follow several hops, ask about absence or need exact identifiers are not solved by finding similar text. A bigger model does not know your data and cannot show why its answer holds. In practice vector search, an ontology and a language model are used together.
- How much more accurate are LLM answers with an ontology?
- In the benchmark by Sequeda et al. (2023), GPT-4 answered 16.7% of questions correctly from the SQL schema alone and 54.2% over a knowledge graph described by an ontology; checking and repairing queries against the ontology raised this to 72.6% (Allemang and Sequeda, 2024). It is one domain and one model, by authors who sell knowledge graph software, so read it as evidence of direction rather than an exact ratio.
- When do you not need an ontology?
- You do not need one when there is a single data source used only by the team that made it, when questions are of the "find related documents" kind, when a slightly wrong answer costs little, or when there is no one whose terms you need to agree with.
"Why not just join tables?"
Often you should. When one team builds one system and knows its schema, a relational database is faster, cheaper and more familiar. An ontology does not replace storage or joins either.
The catch is what a join assumes. You can only join two columns once you already know they refer to the same thing, and that knowledge is not in the schema. It lives in developers' heads, wiki pages and mapping code. With one source that is fine. With two, ten or a hundred, that hidden knowledge becomes most of the cost.
Meaning in people and code
Meaning in the data
Source to source: 10 mappings
Through a shared ontology: 5
| What you want to do | In a relational database | With an ontology |
|---|---|---|
Know that customer_id in system A and client_no in system B are the same person | Write it in mapping code, again for every consumer | Use the same IRI, or state it in the data with owl:sameAs |
| Find every patient with "heart disease" (a myocardial infarction is a kind of heart disease) | Maintain the list of sub-codes yourself, in the query or a side table | A reasoner follows rdfs:subClassOf |
| Add a new data source | Schema change and migration | Leave existing data alone and add triples and mappings |
| Exchange data with another organisation in the same sense | Agree in documents and contracts | Both use the same IRIs from a public ontology |
Relational: maintain the code list
Ontology: follow the subclasses
The difference is not how data is stored but where its meaning lives. Many systems keep their data in a relational database and lay an ontology over it. Thousands of labs run different databases and can still combine results because they use the same Gene Ontology terms. How to turn tables into a graph is covered in From tables to graphs.
"Why not a vector database, or a better model?"
Also largely right. Finding and summarising similar documents is what vector search does cheaply and well. Models keep getting better too.
But vector search finds similar text. Many business questions do not ask for similar text: they ask you to count, to collect everything, or to follow relations.
Vector search: the k nearest
3 of 7 relevant
Graph: follow relations to all
All 7, and an exact count
| Kind of question | Example | Why vector search alone struggles |
|---|---|---|
| Counts and totals | How many business customers cancelled last quarter? | It returns the top few similar passages, so it cannot count the whole |
| Complete lists | Every product that uses this part | It cuts off by similarity, so you cannot tell what is missing |
| Several hops | The contact for projects delivered by subsidiaries of company A | No single passage states every link in the chain |
| Negation and exceptions | Patients with no recorded allergy | "Nothing recorded" is not something similar text can find |
| Exact identifiers | Diagnosis codes I21.4 and I21.9 | Similar spelling gives similar vectors |
A bigger model does not remove these problems. It has not been trained on your data. Putting all of it in the context runs into length and cost, and even then counting thousands of rows exactly is error-prone. Above all, it cannot show why an answer is right. A better model gets better at turning a question into a query; it does not decide what your data means.
How big is the measured difference?
Accuracy (%)
SQL schema only, write SQL
Knowledge graph described by an ontology, write SPARQL
+ check and repair queries against the ontology
Sequeda et al. (2023) tested GPT-4 on questions over an insurance database. Given only the SQL schema and asked to write SQL, it answered 16.7% correctly. Asked to write SPARQL over a knowledge graph of the same data described by an ontology, it answered 54.2% correctly. In a follow-up (Allemang and Sequeda, 2024), checking the generated queries against the ontology and having the model repair them raised this to 72.6%.
Read with care: one domain, one model (GPT-4 as of 2023), one research group, and the authors work for a company that sells knowledge graph software. The comparison is with SQL generation, not with vector search. Take the direction rather than the numbers: the more meaning the schema states, the less the model gets wrong. For a comparison with vector search, the GraphRAG study (Edge et al., 2024) found graph-based answers more comprehensive for questions about a whole document collection, again as judged by a model.
So: together, not instead
- 1 →
Question
"How many business customers cancelled last quarter?"
- 2 →
Vector search
Find the things and documents the question mentions
- 3 →
Ontology and graph
Follow relations, count and filter
- 4
Language model
Write the answer and attach the triples behind it
How to connect the steps is covered in LLMs and knowledge graphs.
When you do not need one
- There is one data source, and only the team that made it uses it.
- Your questions are of the "find documents about this" kind.
- A slightly wrong answer costs little.
- There is no one (another team, organisation or system) whose terms you need to agree with.
Relational database and SQL
Exact answers over a schema one team knows
Time to consider an ontology
Align meaning across sources and show why answers hold
Spreadsheet or a simple app
An ontology is overkill
Vector search and summaries
Finding and reading related documents is enough
If instead there are many sources, the people using the data are not the people who made it, and answers must be verifiable, it is time to consider an ontology. You do not have to build it all: reusing published ontologies is the place to start.
Where to next
Real cases →
What was built in search, medicine, cultural heritage and media, and what changed
What is an ontology →
The first lesson of the course
Find public ontologies →
Start with what already exists in your field
Draft competency questions →
Decide first what the ontology must answer
References
- Juan Sequeda, Dean Allemang, Bryon Jacob (2023). A Benchmark to Understand the Role of Knowledge Graphs on Large Language Model's Accuracy for Question Answering on Enterprise SQL Databases
- Dean Allemang, Juan Sequeda (2024). Increasing the LLM Accuracy for Question Answering: Ontologies to the Rescue!
- Darren Edge et al. (2024). From Local to Global: A Graph RAG Approach to Query-Focused Summarization