Building a martech knowledge graph, part 2/5: designing the ontology

Part 2 of 5. A martech knowledge graph is only as useful as the rules behind it. This post walks through the ontology: seven classes split into a business and a technical layer, the named edges between them, and why KPIs attach to stages rather than journeys. At its centre is the Measurement node, a pattern that exists because two login stages share one CJA dimension and differ only by a filter value. It closes with the classes I deliberately left out, and the test every new class has to pass.

In part 1 I argued that the questions that hurt live in the connections, not on single components. This post is about the rules that decide which connections exist at all: the ontology. Seven classes, a handful of named edges, and one pattern that exists only because of one of the two demo journeys. There’s no Turtle (the plain-text format the graph files are written in) in this one. That’s part 3. Here it’s about the model and the decisions behind it.

The example: two demo journeys

Every example in this post comes from the demo workspace that ships with the GitHub repo. It’s deliberately small: two journeys, two KPIs, and the components and data layer variables behind them. Small enough to read in one go, different enough to break a naive model.

JourneyStagesMeasured byKPIOwner
Ecommerce purchase journeyProduct view, Cart add, Checkout, OrderOne metric per stage: Product views, Product list adds, Checkouts, OrdersOrder conversion rate: Orders / Product views, target 0.20%Digital Marketing
Customer login journeyLogin, Login successOne shared dimension, Page name, filtered by valueMonthly login rate: Monthly logins / Sessions, target 35%Product Analytics

At the data layer, both journeys work the same way. One variable carries a different value for each step: digitalData.conversion.conversionFunnel.step for the purchase funnel, digitalData.page.pageInfo.name for the login flow. The value is what tells one step from the next.

The difference is where that value gets turned into meaning. In the purchase funnel it happens in the implementation: each step value is mapped to a dedicated metric, so by the time the data reaches CJA there’s Product views, Product list adds, Checkouts and Orders, and each stage has a metric of its own. In the login flow nothing like that happens. The value stays a value on one shared dimension, Page name, and the step only becomes visible when you filter on it. That second case is the one that shaped the ontology, and section 4 shows why.

Figure 1: Ecommerce Journey

The purchase funnel resolves its step values upstream. Every stage gets its own metric, so the link from stage to component needs no extra information.The login flow keeps its step values as values. Both stages land on the same dimension, and only the filter value tells Login from Login success.

1. What the ontology is for

An ontology is the schema of a graph: which kinds of nodes exist, which edges may connect them, and what each one means. Without it, a graph is a pile of facts anyone can extend in any direction, and every query has to guess what’s in there.

Mine is small on purpose and written in RDFS (RDF Schema), the lightest schema layer RDF has. RDF itself is the W3C standard behind the graph: every fact is stored as a triple of subject, predicate and object. Every class and every property gets a label and a comment. Every edge declares where it starts and where it ends, for example: rolls_up_to goes from a Stage to a KPI, never the other way round, never from a Component.

Those comments do more work than they seem to. The graph’s MCP server has a tool, get_ontology_schema, that hands them to an LLM word for word. So when an agent wants to know what refs means, it doesn’t guess from the name. It reads the comment: refs points to the original entity in AEP’s own graph, and the data behind it is never copied into mine. In other words, writing the ontology also means writing the documentation your agent works from. Vague comments lead to vague queries.

I held the design to three rules:

  • Model what you’ll query, not everything that exists. A class earns its place by answering a question nothing else in the graph can answer.
  • Meaning lives here, identity lives in Adobe. Anything AEP or CJA already owns gets a pointer, not a copy. That was the main decision in part 1, and it keeps shaping the model below.
  • Type it if you’ll filter on it, write it as text if you’ll read it. A PII flag is a boolean because you query for it. Consent rules are free text because nobody filters on a paragraph.

2. Seven classes, two layers

The whole ontology is seven classes. Four describe the business side, two describe the implementation, and one sits in between.

Figure 2: Core ontology

Read it top down: the business question at the top, the implementation at the bottom, and every path between them running through a Measurement.

ClassLayerWhat it holdsExample from the demo data
RequirementBusinessThe question or problem that justifies tracking anything, plus a lifecycle statusUnderstand monthly login frequency (active)
KPIBusinessA formula and a targetMonthly login rate: Monthly logins / Sessions, target 0.35
JourneyBusinessA named, end-to-end customer pathCustomer login journey
StageBusinessAn ordered step in a journey, with its entry criteriaLogin success, stage 2 of 2
MeasurementBridgeWhich component measures which stage, and with which filter valueLogin success, measured by Page name where the value is /customer/login/success
ComponentTechnicalA CJA metric or dimension, plus the business context I curate for itPage name (dimension)
Data Layer VariableTechnicalThe raw implementation field and the system it lives indigitalData.page.pageInfo.name, web data layer

The split isn’t just tidy. It mirrors where the knowledge comes from. The business layer comes out of planning conversations, KPI decks and requirement workshops. The technical layer comes out of CJA and the implementation, and most of it can be synced rather than typed. It also mirrors who maintains what: in the demo data, the Monthly login rate KPI belongs to Product Analytics while the Page name component belongs to Digital Analytics.

Measurement is the only class that crosses the line. That’s not an accident, and section 4 is about why it has to exist.

3. The edges, and where they attach

Classes are the easy part. The decisions that matter are about edges: which two classes an edge connects, and at what level of detail.

EdgeFromToReads as
addressed_byRequirementKPIThe requirement is answered by this number
has_stageJourneyStageThe journey consists of these steps
rolls_up_toStageKPIThe outcome of this step feeds this KPI
measured_entity / measured_componentMeasurementStage / ComponentThis measurement links that stage to that component
maps_toDataLayerVariableComponentThis variable populates this component
refsComponentAEP / CJA entityThe authoritative version lives over there

Direction is mostly about readability. SPARQL (the query language for graphs, roughly what SQL is for tables) walks an edge both ways equally well, so I named each one so the fact reads as a natural sentence: Login success rolls up to Monthly login rate. What matters much more is where an edge attaches.

KPIs attach to stages, not journeys

The obvious model is Journey to KPI. I attached KPIs to stages instead. Monthly login rate rolls up from Login success, not from the login journey as a whole. Order conversion rate rolls up from the Order stage, not from the purchase journey.

The reason is precision. If the KPI hangs on the journey, the graph knows the two are related but not which step produces the number. If it hangs on the stage, the journey link comes for free: journey has stage, stage rolls up to KPI. Store the precise edge, derive the coarse one. The reverse doesn’t work.

Requirements attach to KPIs

Same logic one level up. A requirement like understand monthly login frequency is answered by a number, so it points at the KPI. The journey and its components follow from there. A requirement that can’t name its KPI is usually not ready to be tracked yet, and the model makes that visible.

Owner attaches to everything

owner is the one property with no fixed domain. Requirements, KPIs, journeys and components all use it. Ownership means the same thing wherever it appears, so it gets one property, and “everything Product Analytics owns” stays one query instead of four.

4. When a relationship needs its own attribute

Back to the login journey. The naive model has a direct edge from Stage to Component: Order is measured by Orders. For the ecommerce funnel that works perfectly. Underneath, it has the same pattern as the login journey: one data layer variable with a different value per step. But the implementation already turns each value into its own metric, Product views, Product list adds, Checkouts and Orders. By the time the funnel reaches CJA, there’s nothing left to qualify.

Now apply it to the login journey. You get two edges: Login is measured by Page name, and Login success is measured by Page name. They’re identical. Ask the graph how Login success is measured and it answers “Page name”, which is true and useless. Pull Page name into a CJA freeform table and you get every page on the site.

Figure 3: Login Journey

The missing piece is /customer/login/success, and the model has nowhere to put it. I looked at three options.

Option 1: put the value on the stage

Add a filter property to Login success and store the value there. It looks simple, but the value only makes sense together with one specific component. A stage measured by two components would need two values, and the graph couldn’t tell which value belongs to which. There’s already an entry_criteria property on Stage for the human-readable description of when someone enters a step. The filter value needs to be machine-precise and tied to its component.

Option 2: create a component per value

Invent a component called Page name: /customer/login/success. Now the graph has a component that doesn’t exist in CJA. The sync can’t create it, refs can’t point at anything real, and you’re back to keeping two versions of the truth in step. It breaks the one rule from part 1 that I’m least willing to break.

Option 3: turn the relationship into a node

This is the one I picked. Instead of an edge from Stage to Component, there’s a Measurement node in the middle. It points at the stage it measures (measured_entity), at the component that measures it (measured_component) and, when needed, carries the filter_value. The value finally has a home: not on the stage, not on the component, but on the relationship, made into something that can hold a field.

Figure 4: Measurement node

With a plain edge, both stages point at Page name and nothing tells them apart. With a Measurement in between, each stage carries its own filter value.

This is a known pattern, not a workaround I invented. The W3C describes it as an n-ary relation: when a relationship needs attributes of its own, you model it as a node with edges to each participant.

One shape for both journeys

The ecommerce stages use Measurement too, they just leave filter_value empty. That matters more than it sounds. Every stage is measured the same way, so every query that walks from a stage to its components has one shape, whether a filter is involved or not. No special case for journeys built on shared dimensions.

The component and the measurement also explain each other. The caveat on Page name says, in plain words, that it’s a shared dimension and filtering by value is required to isolate a journey step. The component says why it can’t identify a stage on its own. The Measurement says how each stage is identified. An LLM that reads both gets the full picture without anyone writing a special rule for it.

The price is one extra hop. Every question from a stage to a component now goes through the Measurement node. In part 3 you’ll see what that does to the SPARQL, and why I think it’s a fair trade for answers that are actually correct.

5. The component: half Adobe’s, half mine

Component is the only class with split ownership. Its identity belongs to Adobe: the CJA component and the XDM field behind it. Its meaning belongs to the graph. The ontology makes that split explicit in the fields.

FieldTypeWhere it comes fromExample (Checkouts)
refsPointerWritten on sync from CJAThe XDM path commerce.checkouts.value in the sandbox
component_typeTextMetric or dimensionmetric
definitionTextCuratedNumber of times a user started the checkout process
caveatsTextCuratedCounts starts, not completions. One user can start checkout several times without buying
contextTextCuratedWhy the component matters for the business
ownerTextCuratedDigital Analytics
is_piiBooleanCuratedWhether it carries or derives from personal data
governance_notesTextCuratedConsent requirements, retention, data quality concerns

The curated fields are where the work is, and where the value is. CJA’s own metadata knows that Checkouts is a metric. It has no slot for the fact that a checkout start isn’t a checkout completion, and that’s exactly the caveat that keeps someone from reading the wrong conversion rate off a dashboard.

Governance fields follow the typing rule

is_pii and governance_notes look like they could be one field. They’re two because they serve different questions. The boolean is for filtering: which PII components feed a KPI that gets reported to the board? is one query. The notes are for reading: a consent requirement or a retention rule is a sentence, not a value, and squeezing it into a dropdown would lose the part that matters. Neither is set automatically. They’re judgement calls, like caveats, so they live next to the definition.

Requirements have a lifecycle

The same thinking applies one level up. A Requirement has a status: active, answered or retired. Both requirements in the demo, understanding shop performance and drop-off and understanding monthly login frequency, are active, but the field pays off over time. Once a requirement is retired, the graph can tell you which KPIs, stages and components exist only to serve it. Those are tracking you can stop maintaining, and in my experience nobody ever goes looking for that list without a reason.

Data layer variables know where they live

The last technical class is the smallest. A Data Layer Variable has a name, a source_system and a maps_to edge to each component it populates. In the demo, digitalData.conversion.conversionFunnel.step maps to four components and digitalData.page.pageInfo.name to one. The source system is a field rather than an assumption, so a second source, an app SDK for example, can sit next to the web data layer without changing the model.

6. What didn’t become a node

A small ontology is mostly a list of things you decided not to model. Three candidates were obvious, and I left all three out.

Conversion rates. A conversion rate looks like a relationship between two stages with a number attached, which sounds like another Measurement-style node. But the graph isn’t where numbers get calculated. CJA does that. What the graph needs is the definition: Order conversion rate is Orders divided by Product views, with a target of 0.20%. That’s a KPI with a formula and a target, and the KPI class already holds it. A separate node would store either a value that’s stale the moment it’s written, or a definition that already exists.

Transitions between stages. Every stage has an order, an integer. That’s enough to know Checkout comes after Cart add. A transition only deserves its own node if the step between two stages carries its own attributes, say an expected duration or a known drop-off reason. Neither journey needs that today, so the integer stays.

Segments, destinations, schemas. All real, all important, and all already modelled in AEP’s own graph. They get referenced through refs, not rebuilt. Part 4 covers that boundary in detail.

The test is the same each time: does the new class answer a question the existing ones can’t? Measurement passed it, because without it the login journey gives wrong answers. None of the three above has passed it yet. If one does, adding a class to an RDFS ontology is a few lines, and the existing data doesn’t break.

Key takeaways

  • The ontology is also documentation. Its comments are what an LLM reads through get_ontology_schema, so write them for a reader, not for a validator.
  • Attach edges at the most precise level. KPIs hang on stages, not journeys. The coarse link can always be derived from the precise one, never the other way round.
  • When a relationship needs a field, make it a node. The Measurement class exists because Login and Login success share one component and differ only by a filter value.
  • Type what you filter on, write what you read. is_pii is a boolean, governance_notes is text, and both are judgement calls that sit next to the definition.
  • Every class has to earn its place. Conversion rates, transitions and segments stay out until they answer a question nothing else can.

Part 3 turns this model into Turtle: both demo journeys written out as triples, the SPARQL that walks through a Measurement node, and the code to load and query it all yourself. If you want to look ahead, the ontology file is in the GitHub repo.

Until then, one exercise. Take a journey you report on and list its stages. For each stage, name the one component that measures it, and ask whether that component alone identifies the stage. If you had to add a filter value even once, you’ve found your own Measurement node.