ML data engineering
Graph Data Engineering and Dynamic Relations
Build point-in-time graph datasets with defensible edge semantics, identity, sampling, and monitoring.
By the end you can
- Define node and edge semantics with temporal availability
- Compare current snapshots, periodic snapshots, and temporal edge logs
- Design candidate sets, negative sampling, and dependency-aware splits
- Monitor graph construction and identity changes
A graph dataset is a claim about which relationships exist
Nodes and edges do not simply appear in nature. Product instrumentation, entity resolution, time windows, sampling, and policy decide which relations enter the graph, and those choices can dominate everything built on top of them.
The Metropolitan Police Service's Gangs Matrix is what an undeclared relation contract looks like at full scale. As of October 2017 nearly 4,000 people were on it. Amnesty International UK, investigating the database, reported that “78% are black, but in reality black people are responsible for just 27% of serious youth crime”. An entry could be generated by an indicator as weak as being a victim of gang violence, or the music videos a person had shared. The UK Information Commissioner's Office investigated in 2018 and reported the result plainly: “The ICO found that, while there was a valid purpose for the database - to tackle violent gang crime - the way it was being used across London was unlawful: it didn’t properly distinguish between victims of crime and offenders and was being shared more widely than was needed.” The Met later removed hundreds of people from it. Then it discontinued the database.
Stated as data engineering, the failure is specific. Two different relations — was harmed by gang violence, and participated in gang violence — were collapsed into one edge type. The observation process that produced the edges decides who gets noticed and whose shared videos get read. It was never written down beside them. The result was then distributed as though it were a set of facts about people, rather than a record of what one process had recorded about them.
The same ambiguity sits in every missing edge. An absence may mean no relationship, an unobserved relationship, a privacy rule that forbade recording it, or a relationship that had not yet formed. Graph data engineering therefore begins with relation semantics and temporal availability, not with a graph neural network library.
An edge is evidence produced by a measurement process, not a universal fact.
Case
The Open Graph Benchmark splits citations by publication year
The Open Graph Benchmark makes its split choices explicit and public. Its ogbn-arxiv citation graph holds 169,343 nodes and 1,166,243 edges, and the split runs by publication year rather than at random. The protocol, published in 2020, is to “train on papers published until 2017, validate on those published in 2018, and test on those published since 2019”. The same rule scales to ogbn-papers100M, with 111,059,956 nodes.
Nothing in the citation data forced those boundaries. Someone decided which future the benchmark was about and wrote the decision into the release. That is what makes it possible for a later reader to disagree with it.
Visual
A graph release contains more than nodes and edges
Each component needs identity, time, provenance, and versioning. None of these are theoretical artefacts. The Temporal Graph Benchmark ships a fixed, published negative set alongside its edges, so that an evaluation can be repeated. PinSage's paper states its sampling policy down to the rank interval its hard negatives are drawn from. A release that records only the nodes and the edges has thrown away the parts a reviewer would need to reconstruct the task.
Node tables
Entity identifiers, node types, attributes, validity intervals, and source ownership.
Edge tables
Source, destination, relation type, direction, weight, event time, and availability time.
Snapshots or event log
A temporal representation of graph evolution and deletion.
Labels and tasks
Node, edge, pair, subgraph, or graph-level targets with prediction cutoffs.
Sampling metadata
Candidate sets, negatives, fanout, truncation, and excluded relations.
The graph version and the task cutoff must be reproducible together.
Example
A fraud graph leaks the investigation outcome
A payment network links accounts, devices, merchants, addresses, and prior cases. The walkthrough below is a mechanism, not a report of one incident. It is how an investigation's own conclusions travel backwards into the training data.
- Investigators create edges between cases after discovering a fraud ring.
- The latest identity graph backfills those links into earlier dates.
- Random edge splitting places connected parts of the same ring in train and test.
- Nonedges are sampled as negatives even though many represent unobserved relationships.
- The model appears excellent because the graph already contains the future investigation structure.
Comparison
Static snapshots and temporal events support different questions
The shape you store should match how relationships form and become available.
The third column rests on a distinction: when a relationship held in the world, against when your system could see that it held. That is not an exotic requirement invented for graph machine learning. It has been in the SQL standard since SQL:2011, which ISO/IEC published in December 2011. Two kinds of table are defined there. Application-time period tables carry validity periods that the user sets and may later correct. System-versioned tables carry SYSTEM_TIME period columns that are GENERATED ALWAYS AS ROW START and ROW END, and users cannot alter them, so that the recorded history “cannot be tampered with”. A table that declares both is bitemporal. Kulkarni and Michels, writing up the standard's temporal features for IBM, gave the reason for wanting both: “Such tables are very useful for capturing both the periods during which facts were believed to be true in the real world as well as the periods during which those facts were recorded in the database.”
An edge table carrying both periods can be queried AS OF a past instant. That is the as-of reconstruction in the third column below, expressed in the query language rather than reimplemented in application code. Implementations such as MariaDB support all three forms.
Current snapshot
Stores the graph state visible now.
- Simple to query
- Weak historical evidence
- Backfills can rewrite past
- Useful for present-state analytics
Periodic snapshots
Preserves graph states at selected boundaries.
- Supports replay by edition
- May miss within-period ordering
- Storage grows with snapshots
- Useful for batch training
Temporal edge log
Stores relation creation, update, and deletion events.
- Supports as-of reconstruction
- Needs event and availability clocks
- More complex processing
- Useful for dynamic tasks
Steps
Build a point-in-time graph dataset
The process should preserve what the system knew before each prediction.
The Temporal Graph Benchmark is steps 3 to 6 carried out in public, on nine datasets that run up to tgbn-token's 72,936,998 edges. The cutoff is stated rather than implied: “All datasets are split chronologically into the training, validation, and test sets, respectively containing 70%, 15%, and 15% of all edges”. The negatives are designed rather than assumed. Each positive edge is ranked against multiple negatives drawn equally from historical and random negatives, and the negative set is fixed and published, so two teams evaluate against the same one. The benchmark also publishes a per-dataset surprise index, the fraction of test edges never seen in training. A model that is mostly memorising can then be recognised as one, rather than congratulated.
That the protocol is written down is what allows it to be checked. Le Yu re-ran nine methods on five TGB link datasets and three node datasets, under the same protocol and the same metrics. The rankings differ sharply from one dataset to the next.
1. Define relation semantics
State direction, multiplicity, weight, source, and what absence means.
2. Resolve identities
Version node merges, splits, aliases, and uncertain matches.
3. Attach temporal fields
Record event, availability, expiration, and deletion times for relations.
4. Construct the cutoff graph
Include only nodes, edges, and features eligible before the task time.
5. Design negatives
Separate known negatives from unlabeled or unobserved pairs.
6. Split by dependency
Use temporal, component, entity, or group boundaries aligned with deployment.
Key idea
A missing edge is not automatically a negative example
Most possible pairs have no recorded edge. Many were never observed or eligible. Sampling them uniformly can create easy negatives and inflate link-prediction performance.
How much it inflates them has been measured. EdgeBank is a parameter-free baseline that does nothing but memorise previously seen edges. Poursafaei and colleagues built it in 2022 to test the standard evaluation. Under the random negative sampling standard to dynamic link prediction, across 13 datasets split chronologically 70%-15%-15%, EdgeBank is competitive with state-of-the-art models. Swap in historical negatives — past edges that are absent at the current step — and the leaderboard reorders. Their conclusion: “First, we observe that the ranking of models can change significantly across different NS settings. This shows that relying on a single NS strategy, such as the random NS, is insufficient for the complete evaluation of methods.”
An independent reproduction put a number on it. Yu and colleagues re-ran nine methods in 2023 with their DyGLib library. On UN Trade, EdgeBank's transductive average precision rises from 60.41 under random negatives to 81.32 under historical negatives, the best of the nine. Its average rank improves from 7.54, the worst of the nine, to 5.92. The model did not change. The negative distribution did.
So define a candidate set representing pairs the system could reasonably consider, and record the sampling distribution. It affects training, metrics, and how the probabilities should be read. Pinterest's deployed PinSage did this at web scale in 2018: 7.5 billion training examples over a graph of 3 billion pin-and-board nodes and 18 billion edges. Uniform negatives were rejected as too easy. With 500 random negatives drawn from over 2 billion items, “the model's resolution is only 1 out of 500”. What replaced them is written down exactly. Five hundred shared random negatives per minibatch, plus hard negatives from items ranked by Personalized PageRank from the query item: “Items ranked at 2000-5000 are randomly sampled as hard negative items.” They arrive on a curriculum that adds n-1 hard negatives at epoch n. The deployed system reached 67% hit-rate and 0.59 MRR, 40 points of hit-rate above the best baseline.
For evaluation, preserve hard negatives and avoid using future nonedges whose relationship later becomes positive without considering the chosen horizon.
OGB shows a third way to fix a candidate set in advance. In ogbl-citation2, two references of each source paper are randomly dropped, and the model must “rank the missing two references higher than 1,000 negative reference candidates”. The source papers are “the most recent papers (those published in 2019)”. The randomness sits inside a candidate set that was chosen, not assumed.
Negative sampling defines the task as much as the model does.
Position
A random split is a claim that the future resembles the past
Splitting rows at random is offered as the choice that assumes nothing. It assumes a great deal: that whatever the model meets after release comes from the same pool it trained on, and that the only thing separating a training row from a test row is which way a coin fell.
The Open Graph Benchmark priced that assumption in 2020. It split ogbn-products by product sales ranking — the top 8% of products for training, the next 2% for validation, and the remaining 88% for testing — and ran GraphSAGE on it: 78.50±0.14% test accuracy against 94.09±0.05% training accuracy. Under a conventional random split of the same graph at the same 8/2/88 ratio, the same model reaches 88.20±0.08% test accuracy. Same graph, same model, same ratio. The rule was the only difference. Their reading of it: “These results indicate that the realistic split is much more challenging than the random split and offer an important opportunity to improve out-of-distribution generalization.”
The pattern is not confined to products. On molecules, the best GIN scores 82.73±2.02% ROC-AUC on a random split of ogbg-molhiv, 5.66 points above what the same model gets on a scaffold split. On ogbg-moltox21 it is 86.03±1.37% against 77.57±0.62%, a gap of 8.46 points. Scaffold splitting comes from MoleculeNet, published in Chemical Science in 2018, whose authors introduced it at an 80/10/10 ratio precisely because it “offers a greater challenge for learning algorithms than the random split”. A benchmark that reports only the random number is reporting the easier of two experiments it could have run.
OGB declines the assumption elsewhere too. Its ogbn-arxiv citation graph, 169,343 nodes and 1,166,243 edges, is split by publication year: “train on papers published until 2017, validate on those published in 2018, and test on those published since 2019”. The same rule scales to ogbn-papers100M and its 111,059,956 nodes. What a random rule risks here is concrete. It can place connected parts of one neighbourhood on both sides of the boundary. That is how a fraud graph ends up with the investigation's own links in training and in test.
None of that was forced by the data. Somebody decided which future the benchmark was about and wrote that decision down, which is what makes it possible to disagree with. A random seed takes the same decision and leaves nothing to disagree with — and, on ogbn-products, awards itself 88.20% where the sales-rank split reports 78.50%.
State which future the split is claiming to represent, so a reviewer has something to argue with.
Analogy
A graph release is a transit map with a date on it
On a transit map, nodes are stations and edges are routes that operate under a timetable. A map from next year should not be used to plan a journey made last winter. Route closures, temporary services, and renamed stations require effective dates and versioned identity. A missing line may mean no service, or merely incomplete surveying. Edges are often inferred rather than published, encoding social, financial, or estimated relationships that may not be there at all. That is how a database can come to link nearly 4,000 people on the strength of, among other things, the videos they shared.
A graph without a date and relation contract is an attractive but ambiguous picture.
Monitor graph construction before monitoring graph embeddings
Track node and edge counts by type, degree distributions, component sizes, isolated-node rates, identity-merge volume, relation latency, and sampling coverage. Sudden embedding changes may originate from a source outage, an aggressive entity merge, or altered candidate generation, rather than from model drift.
Some of these statistics also belong in the release itself, not only on a dashboard. TGB's surprise index — the fraction of test edges never seen in training — is a construction diagnostic published beside the data. It is what lets a reader see that a memorising baseline such as EdgeBank is scoring on repetition rather than on prediction. A metric that can only be computed from the graph, not from the model, is often the one that explains the model.
When the graph is used in multiple products, lineage should identify which release, sampling policy, and excluded relations informed each model.
Graph-model diagnostics are interpretable only when graph-construction diagnostics are available.
Key takeaways
- Nodes and edges are outputs of identity, observation, policy, and temporal decisions rather than neutral facts: the Gangs Matrix held nearly 4,000 people in October 2017 without properly distinguishing victims of crime from offenders, and the ICO found its use across London unlawful.
- Graph releases need versioned node, edge, snapshot, label, and sampling metadata; SQL:2011's application-time and system-versioned tables give the two clocks a standard, queryable form.
- Latest-state graphs can leak relationships discovered or backfilled after a historical prediction, including the investigation's own links.
- Missing edges are not automatically true negatives: swapping random for historical negatives raised EdgeBank's transductive average precision on UN Trade from 60.41 to 81.32 and moved it from worst to best of nine methods.
- Temporal, component, entity, and group-aware splits should reflect how the graph task will operate: OGB's sales-ranking split of ogbn-products leaves GraphSAGE at 78.50±0.14% where a random split at the same 8/2/88 ratio reports 88.20±0.08%.
- Graph construction should be monitored through structure, latency, identity, and coverage diagnostics — TGB's published surprise index is one — before interpreting embeddings.