axiothOntology Hub

Why ontology

"Why not just join tables in a relational database?" "Why not a vector database, or a better model?" Both are often right. This page sets out when they are, and when they fall short.

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

On the left, the fact that two columns refer to the same customer lives only in mapping code. On the right, it shows in the data: both point to the same IRI.

Source to source: 10 mappings

Through a shared ontology: 5

With n sources, direct mappings grow as n(n−1)/2. Mapping each to a shared ontology takes n.
What you want to doIn a relational databaseWith an ontology
Know that customer_id in system A and client_no in system B are the same personWrite it in mapping code, again for every consumerUse 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 tableA reasoner follows rdfs:subClassOf
Add a new data sourceSchema change and migrationLeave existing data alone and add triples and mappings
Exchange data with another organisation in the same senseAgree in documents and contractsBoth use the same IRIs from a public ontology

Relational: maintain the code list

Ontology: follow the subclasses

Ask for "heart disease" and a reasoner follows rdfs:subClassOf to include everything below it. With a hand-kept list, a new code or one forgotten entry makes the query quietly wrong.

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

Blue dots are the items actually relevant to the question. Vector search cuts off by closeness, so it misses items worded differently, and cannot tell you how many it missed.
Kind of questionExampleWhy vector search alone struggles
Counts and totalsHow many business customers cancelled last quarter?It returns the top few similar passages, so it cannot count the whole
Complete listsEvery product that uses this partIt cuts off by similarity, so you cannot tell what is missing
Several hopsThe contact for projects delivered by subsidiaries of company ANo single passage states every link in the chain
Negation and exceptionsPatients with no recorded allergy"Nothing recorded" is not something similar text can find
Exact identifiersDiagnosis codes I21.4 and I21.9Similar 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

16.7%

Knowledge graph described by an ontology, write SPARQL

54.2%

+ check and repair queries against the ontology

72.6%
GPT-4 on an insurance database. Sequeda et al. 2023; Allemang and Sequeda 2024. Read the caveats below.

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. 1 →

    Question

    "How many business customers cancelled last quarter?"

  2. 2 →

    Vector search

    Find the things and documents the question mentions

  3. 3 →

    Ontology and graph

    Follow relations, count and filter

  4. 4

    Language model

    Write the answer and attach the triples behind it

Each tool does only what it is good at.

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.
↑ Need to verify answers
high

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

low

Spreadsheet or a simple app

An ontology is overkill

Vector search and summaries

Finding and reading related documents is enough

oneData sources →many
A rough guide. If you are on the border, start small by reusing a public ontology.

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

References