A graph model learns from entities and relationships whose meaning and availability must be fixed at the prediction point.
Graph learning contract: entities, relations and snapshot time
Name the prediction
AI Trove might predict which prerequisite lesson a learner should study next. A node could be a lesson, learner or concept, but mixing those types under one anonymous ID makes edges ambiguous. Define a relation such as lesson-requires-concept separately from learner-completed-lesson. The recommendation objective determines which edge is evidence and which is a target.
Assign stable identity
Canonical lesson paths can identify lesson nodes while an internal learner key identifies a learner under an approved privacy policy. A title change should not create a new lesson node, and a merged page needs an explicit redirect or retirement event. Treat duplicate edges as updates or repeated observations under a declared rule. Direction matters: requires is not the same as required-by.
Freeze the snapshot
At a recommendation issued on October 5, only edges and node attributes known by that instant may enter features. A completion recorded afterward is a label or future evidence, not past context. Keep edge event time, ingestion time and graph build version. Availability rules apply even when a graph library hides the joins.
Check the input fixture
Create lesson A requiring concept C and lesson B teaching C. Add a learner who completed B after a historical prediction time; that completion must disappear from the earlier graph snapshot. Include a renamed lesson path and a duplicate edge. A reviewer should identify exactly which nodes and relations are available for the target decision.
Implementation
def available_edges(edge_rows, cutoff):
retained = {}
for edge in edge_rows:
if edge["known_at"] >= cutoff:
continue
key = (edge["source"], edge["relation"], edge["target"])
retained[key] = edge
return list(retained.values())Performance and operating cost
Scanning E edges costs O(E) expected time and O(U) memory for U unique relationships. Versioned snapshots consume storage, but they prevent a high offline score built from future edges from being mistaken for a deployable model.
Common Mistakes
- Do not merge distinct relation types into an unlabeled edge.
- Do not use a completion edge that arrived after the prediction cutoff.
- Do not let a page rename create a false new entity.
Read next
- Graph construction: direction, duplicates and high-degree nodes
- Link prediction evaluation: time splits and honest negative candidates
- Recommendation objective and interaction log: define what success means
- Lag features: prove each input existed at forecast time
Continue the workflow: Knowledge-graph contract: entity identity, relations and claims.
