Last chapter's mean aggregated every neighbor a node has. Fine for a six-node toy graph — but a real social network node can have thousands of neighbors, and a brand-new user shows up after training is already done. What breaks first, and how do you fix it without starting over?
Click node 1 — it has three neighbors, but only two get highlighted. That's a fixed-size sample, not the full neighborhood. Compare the two readouts: sampling and using everything don't always agree.
GraphSAGE ("SAmple and aggreGatE") changes two things about the previous chapter's GCN (short for Graph Convolutional Network). First, it aggregates a fixed-size random sample of neighbors instead of all of them — bounded work per node, no matter how high the degree gets:
- — node 's feature after rounds of message passing.
- — node 's updated feature after one more round.
- — a sampled neighbor 's current feature.
- — node 's full neighborhood, before sampling.
- SAMPLE() — a fixed-size random draw of neighbors from 's full neighborhood.
- — the sample size: how many neighbors get aggregated, regardless of how many actually exist.
- AGGREGATE — the learned combining function, applied to any neighborhood, seen or unseen.
- Learns a function, not a lookup table
Second — and this is the bigger idea — it learns an aggregation function, not a per-node lookup table.
- Transductive methods can't handle unseen nodes
A method that memorizes one embedding vector per node (like node2vec) is transductive: it has nothing to say about a node it never saw.
- Inductive: any neighborhood works immediately
GraphSAGE's function takes any neighborhood as input, so it's inductive: hand it a brand-new node's neighborhood and it produces an answer immediately.
Add the new node. It was never part of the original six-node graph, never "trained on" — but the exact same aggregation function runs on it instantly, because the function only ever looked at neighbor values, never at a fixed table of node identities.
With sample size (always take the two lowest-numbered neighbors, standing in for a random draw):
- A low-degree node: sampling changes nothing
Node has exactly two neighbors, — sampling two out of two keeps everything. Sampled mean , identical to the full mean.
- A high-degree node: sampling genuinely loses information
Node has three neighbors, . Sampling keeps only , dropping neighbor (feature ). Sampled mean ; the true full-neighborhood mean is — a real, measurable gap, the price of bounding the work per node.
- A node that never existed during training
A new node with feature , connected only to node (feature ): its aggregate is , using the same function as every original node — no new parameters, no retraining pass, just one more function call.
Click through the nodes until you find the one where the sampled mean and the full-neighborhood mean genuinely disagree — only one of them has more neighbors than the sample size of 2.
Sampling trades a little accuracy for a hard cap on cost per node — essential once "neighbor count" can be in the thousands. Being inductive is the deeper payoff: any model built to learn a function of a neighborhood generalizes to graphs it's never seen, the same way a CNN's learned filters generalize to images it's never seen. The next chapter asks whether "sample K neighbors and average them equally" is really the best way to combine them — or whether some neighbors should just count for more.