"Should we use a semantic layer, a vector database or a knowledge graph?" usually gets framed as a choice. It is closer to a division of labor. Each one is good at one shape of question and weak at the others, and the questions people actually ask tend to mix all three.
The short version
| L1 Semantic | L2 Vector | L3 Graph and ontology | |
|---|---|---|---|
| Job | Governed numbers | Retrieval over text | Rules (ontology) and records (graph) |
| Good at | Aggregates, trends, comparisons | What a document or thread says | Multi-hop and roll-up questions, such as "which X connects to Y" |
| Bad at | Anything unmodeled; documents | Counting; precise aggregates | Bulk scans and aggregation |
| Typical stack | dbt Semantic Layer, Cube | pgvector, Pinecone, warehouse-native vector search | Neo4j, Amazon Neptune |
L1: the semantic layer
This is the foundation for any question that ends in a number. Metrics, dimensions and joins are defined in code, so "pipeline by segment last quarter" resolves to the same SQL every time. We cover it in detail in The model is guessing at raw tables.
Where it breaks: it only answers what has been modeled, and it has nothing to say about the text sitting in tickets, call notes and contracts.
L2: the vector database
A lot of the context behind a number never makes it into a table. Why a client paused spend is in a call note. What the contract says about early termination is in a PDF. Which accounts complained about pricing is spread across a hundred tickets.
The vector layer chunks and embeds those documents so the agent can retrieve the relevant passages. Two details matter more than the choice of database:
- Citations. Every passage should come back with its source document and location. An answer built on retrieved text that cannot be traced is no better than a guess.
- Permissions. Document access rules have to travel into the index and be enforced at query time. Otherwise retrieval becomes the easiest way to read something you should not.
Where it breaks: retrieval finds passages but cannot count them. "How many accounts raised pricing concerns?" needs the semantic layer to do the counting once retrieval has tagged the accounts.
L3: the ontology and the graph
Some questions are about how things connect: "Which campaigns lost ROAS this month, what creative do they share, and which audience does that creative target?" In SQL, that is a chain of joins across the campaign, creative, audience and performance tables. It has to be written fresh for each variation of the question.
L3 answers these. It is a module with two halves, both stored in one graph database:
- The ontology is the type level. It holds the rules: a campaign belongs to an account, a country rolls up to a region, spend is upstream of revenue. It is a few dozen statements.
- The graph is the instance level. It holds the actual records: this campaign, that account, these engagements. It can run to millions of rows.
The word campaign appears in both. In the ontology it is a rule: "a Campaign belongs to an Account". In the graph it is a real campaign: "Holiday Search 2026 belongs to Acme EMEA". The ontology is the schema and the records are the data, in the same database. That is why the ontology is one half of the L3 module and not a separate system.
A small example
A family tree needs three rules:
- A person has a mother.
- A mother is a person.
- Ancestor is transitive, so your mother's mother is your ancestor.
The graph holds the people: Sam's mother is Mary, and Mary's mother is Anna. Now ask who Sam's ancestors are. Nobody stored a link from Sam to Anna. The transitive rule finds her. Three rules cover any number of people.
The same idea in campaign data
The ontology is about twenty lines, written once:
Campaign belongs_to Account
Account belongs_to Territory
Territory belongs_to BusinessUnit
Campaign runs_on Channel
Spend input_to Revenue
belongs_to is transitive
The graph is loaded from the warehouse and runs to thousands of rows or more:
"Holiday Search 2026" belongs_to "Acme EMEA"
"Acme EMEA" belongs_to "Germany"
"Germany" belongs_to "Europe West"
Ask for revenue in Europe West. No row connects that campaign to Europe West. The transitive rule walks from account to territory to business unit and finds it.
| Ontology | Graph records | |
|---|---|---|
| Says | A campaign belongs to an account | Holiday Search 2026 belongs to Acme EMEA |
| How many | About 20 statements | Thousands or millions |
| Written by | A person, once | Loaded from the warehouse and refreshed |
| Changes | When the business changes shape | Every day |
Why an agent needs both
The ontology alone cannot answer which accounts have not engaged, because it has no accounts in it. The records alone cannot tell an agent where to drill, because nothing declares what contains what. Together they give the agent a path it can explain: campaign, belongs to account, belongs to territory.
The ontology is the rulebook and the graph is the filled-in records. You write the rulebook by hand and it rarely changes. The records load from the warehouse and change every day.
Where it breaks: graphs are poor at bulk aggregation. Use the graph to find which entities matter, then hand those IDs to the semantic layer for the numbers.
How they combine
A real question rarely stays in one layer. Take: "Which enterprise accounts raised a support ticket in the last 30 days and still have no renewal owner?"
- L1 resolves "enterprise segment", "renewal owner" and "ticket count" to governed definitions.
- L3 walks account to ticket to owner to renewal date in one traversal, following the rules in the ontology.
- L2 pulls the ticket text so the answer says what each account is unhappy about.
The agent routes each part of the question to the layer that can answer it and composes the result, with the definitions, path and sources attached. That routing is where most of the engineering effort goes, more than in any single database.
What order to build them in
Start with L1. It covers the highest-value questions (the numbers people make decisions on), and it forces the definitional work that the other two layers depend on. A graph built on undefined entities just moves the confusion somewhere harder to see.
Add L2 when the answer gap log starts filling with "why" questions that point at documents. Add L3 when the same multi-join questions keep coming back in slightly different forms, and each one becomes a new dbt model.
L3 has its own order. Write the ontology first. It is a short piece of modeling, and it is what makes root cause analysis possible. Loading the graph records is a real data engineering project, and you do not need it until a question asks about specific accounts rather than aggregate numbers.
Cost note. Each layer is another system to keep in sync with the warehouse. The vector index needs re-embedding when documents change, and the graph needs updating when relationships change. The ontology changes only when the business changes shape. Budget for that pipeline work up front instead of discovering it after launch.