
This blog is written by AI for SEO
RAG vs Ontology: Which Your AI Agents Actually Need
RAG retrieves passages of text that look relevant to a question; an ontology is a model of your business, with entities, the links between them, and the definitions and rules that apply. If your agents answer "what does this document say?", RAG is enough. If they answer "which customers are affected?", they need an ontology.
Most teams reading this already run a RAG pipeline and it mostly works. The failures show up on a specific class of question: the ones that span systems. The same customer is a Stripe ID, a Postgres row and a name in a contract PDF, and no amount of chunking and embedding tells the agent those are one entity. This post gives you a test to decide which of your questions need which, then shows how Helix Foundry builds the ontology and keeps every value traced to its source.
RAG vs ontology in one answer: retrieval of passages vs a model of the business
RAG finds text; an ontology defines things. That is the whole difference, and everything else follows from it.
RAG stands for retrieval-augmented generation: you split documents into chunks, embed them, retrieve the nearest chunks for a question and hand them to a language model to write the answer. Yes, RAG is an AI concept, specifically a pattern for grounding a language model in your own text. It is a retrieval technique, not a data model.
An ontology is the model itself. It declares the types in your business (customer, order, contract, vendor), how they link (a customer has orders, an order is governed by a contract), what each term means, and the rules between them. In plain terms for AI: it is the agent's map of what exists and how it connects, so it does not have to guess from similar-looking paragraphs.
RAG answers "what does this policy say?" An ontology answers "which customers does this policy affect?" because it can follow links across systems and apply one definition of "customer" everywhere.
What RAG does well, and the questions where it quietly fails
RAG is the right starting point for document lookup and summarisation: policies, manuals, reports, support articles. It is quick to stand up, tolerates messy text and returns something useful even when the match is approximate.
It fails quietly on four kinds of question.
Cross-system joins. "Which customers on the Enterprise plan have a contract renewing this quarter?" Plan lives in Stripe, renewal date lives in a PDF. Top-k retrieval returns plausible chunks from one or the other, never the join.
Aggregation. "What is our total open invoice value for customers in the UK?" Retrieval returns a handful of passages. It cannot sum rows it never retrieved, and the model will happily produce a number anyway.
Consistent definitions. If sales counts a customer at signature and finance counts at first payment, chunks from both documents sit side by side in the index and the model picks whichever surfaced first.
Rules and consequences. "Does this refund need approval?" depends on a rule connecting amount, customer tier and contract terms. A rule written in a paragraph is retrieved as text, not enforced.
The danger is the word quietly. The answer looks fluent and cited, and nothing signals that half the relevant records were never retrieved.
What an ontology adds: entities, links, definitions and rules
An ontology adds four things RAG does not have.
Entities. One node per real thing. The customer is one entity, however many systems mention it.
Links. Typed relationships between entities: customer to subscription, subscription to invoice, customer to contract. Multi-hop questions become traversals instead of guesses.
Definitions. "Active customer" is declared once, with the logic that computes it, so every agent and dashboard uses the same meaning.
Rules. Constraints and policies expressed against the model, so an agent can check them rather than read about them.
A few terms people confuse here. An ontology is not the same as a graph: a graph is a storage shape (nodes and edges), while an ontology is the schema and meaning that tells you what the nodes and edges are. An ontology is also not a taxonomy: a taxonomy is a hierarchy of categories (a tree of "is a kind of"), while an ontology adds arbitrary typed links and rules. And the knowledge graph is still relevant: it is how most ontologies are stored and queried, which is why the two are usually discussed together. For the longer version of that distinction, see Ontology vs Knowledge Graph: Which Your AI Workflows Need.
A test for your workload: which questions need which
Take twenty real questions your agents are asked, or that you want them to answer, and run each through these five checks.
Is the answer stated in one passage? If yes, RAG. "What is our refund window?" lives in one paragraph.
Does the answer need facts from two or more systems? If yes, ontology. Stripe plus Postgres plus a contract is the classic case.
Does it need a count, sum or average? If yes, ontology. Aggregation needs complete sets of records, not top-k text.
Does it depend on a business definition people disagree about? If yes, ontology. Define it once.
Will an agent act on the answer? If yes, lean ontology. A wrong summary is an annoyance; a wrong refund is a ticket.
Tally the results. If most questions land on check 1, stay with RAG and spend your effort on chunking and evaluation. If a meaningful share hit checks 2 to 5, you have a modelling problem that better retrieval will not fix, however good your embeddings are.
A worked example makes this concrete. Take one customer, Acme Ltd:
In Stripe, it is a customer ID with an active subscription and two failed payments.
In Postgres, it is an
accountsrow with a different ID, an owner, a region and a support tier.In a contract PDF, it is "Acme Limited", with a renewal clause and a termination-notice period.
Ask: "Which accounts have failed payments and a renewal inside 60 days?" A RAG pipeline retrieves chunks that mention payments or renewals, probably from different customers, and the model blends them. An ontology has one Customer entity linked to a Stripe subscription, a Postgres account and a Contract extracted from the PDF, so the question is a filter over linked facts. The same pattern is walked through in Link the Same Customer Across Stripe, Postgres and Notion.
Using both: ontology for facts and links, RAG for the text around them
You rarely replace RAG; you put it behind the ontology. The split is simple: the ontology owns facts and relationships, RAG owns the prose that explains them.
In the Acme example, the ontology tells the agent which customers match, with the exact failed-payment count and renewal date. RAG then fetches the termination clause wording, the support thread about the last outage, or the policy paragraph on grace periods, scoped to those customers. The agent gets structured, checkable facts plus the surrounding language it needs to write a useful answer.
This is also the safer arrangement for agents that take actions. The decision (does this customer qualify?) rests on modelled data and rules; the text only informs how the agent communicates it.
If your documents are the source of facts rather than just context, extract them into the ontology instead of leaving them as chunks. A termination-notice period buried in a PDF is a field on a Contract, not a paragraph to hope the retriever finds. See How to Extract an Ontology From Contracts and PDFs.
Building the ontology in Helix Foundry: clone, docker compose up, connect, generate, ask
Helix Foundry turns the tools your company runs on into one connected graph, and loads it into HelixDB, the graph-vector database it is built on. Foundry connects your sources, an ontology agent drafts types, links and mappings from your tables, and you ask questions in plain language. Foundry is Apache 2.0 licensed.
To run it on your own machine you need Docker with Compose v2 and ports 3000 and 8333 free:
git clone https://github.com/helixdb/helix-foundry.git
cd helix-foundry
docker compose up -d --waitThen open http://localhost:3000. The local install is single-user on localhost, so keep it off the public internet. If you prefer hosted, Helix Cloud is at foundry.helix-db.com.
From there the flow for the Acme example is:
Connect. Add Stripe and Postgres as sources, test them and sync their tables. The repository lists connectors for PostgreSQL, MySQL, Amazon S3, Stripe and others, and documents can come in alongside them.
Generate. Ask Foundry to draft the ontology, which drafts the types, links and mappings. You review the draft; the Postgres-specific version is in Map Postgres Tables to an Ontology for AI Agents.
Ask. Use Analyst, the interface for querying the ontology, to ask "which accounts have failed payments and a renewal inside 60 days?" Changes it prepares need your confirmation.
Two properties matter for agents. First, every value is traced to its source row or document quote, so an answer is checkable rather than just plausible. Second, Foundry never writes to your sources. When schemas and data drift, the ontology has to keep up; that upkeep is covered in Self-Healing Ontology: Keeping Links Right as Data Drifts and How to Update an Ontology When Your Data Changes.
When your agent runs in Claude Code, Codex or another tool, it can reach the ontology through the Helix MCP, so the same grounded graph backs both people and agents.
Trade-offs: modelling effort, upkeep, and when to skip the ontology
An ontology costs more than RAG, and you should know where.
Modelling effort. Someone has to decide what a customer is and approve the links. Foundry drafts the types and mappings, but a person still reviews them. Budget time for that review; it is where definitions get settled.
Upkeep. Sources change: a column is renamed, a new system arrives, a definition shifts. A static model rots. This is the hard part of running an ontology, and the reason to pick tooling that updates the schema and graph as the data changes rather than a one-off modelling project.
More moving parts. You now maintain connectors and a graph in addition to an index.
Skip the ontology when your questions fail checks 2 to 5 rarely, when your corpus is one body of documents with no structured systems behind it, or when the agent only drafts text a human reviews anyway. Start with RAG, instrument which questions it gets wrong, and add the ontology when those failures cluster around cross-system joins, aggregation or rules. Do not model the whole company up front; model the workflow that is actually breaking.
FAQ: ontology vs graph, ontology vs taxonomy, what RAG stands for, is the knowledge graph still relevant
Short answers are in the FAQ below. The pattern behind all four: RAG is a retrieval technique, a graph is a storage shape, a taxonomy is a category tree, and an ontology is the meaning-bearing model of entities, links and rules that sits on top of the graph.
Run your twenty questions through the test, then model the ones RAG fails
RAG is enough until your agents need to join systems, count things, apply one definition or act on a rule. Then you need a model, not better chunks. Take twenty real questions, mark which fail the five checks, and build an ontology for that slice only. Clone helix-foundry, run docker compose up -d --wait, connect Stripe or Postgres, generate a draft and ask the question your RAG pipeline got wrong.