Neighborhood aggregation is the operation in a graph neural network that combines the feature vectors of a node’s neighbors into a single summary vector, which is then used to update that node’s representation. In graph learning, it is the core mechanism of the message passing framework and the reason a node’s embedding comes to reflect both its own attributes and the structure of its surroundings.
The component that performs this step is often called the aggregation function. Because graphs have no fixed ordering of neighbors and nodes have varying degrees, the aggregator must be permutation invariant and must accept inputs of any size. Its choice strongly influences what a model can distinguish, how stable its training is and how well it scales to graphs with millions of nodes.
How neighborhood aggregation works
Neighborhood aggregation works in three steps inside each graph neural network layer: message computation, aggregation and update. First, each neighbor produces a message, typically a learned linear transformation of its current features, sometimes combined with edge features. Second, the aggregator merges all incoming messages into one vector. Third, an update function combines this vector with the node’s own previous state, often through concatenation or addition followed by a nonlinearity.
Stacking layers expands the receptive field: after k layers, each node has received information from nodes up to k hops away. Most practical models use two to four layers, because deeper stacks tend to blur node representations together, a problem known as over-smoothing.
The table below lists the components of a single aggregation layer and their typical implementations.
| Component | Role | Typical implementation |
|---|---|---|
| Message function | Transforms neighbor features | Linear layer or small MLP |
| Aggregation function | Merges messages into one vector | Sum, mean, max or attention |
| Update function | Combines summary with own state | Concatenation plus MLP, GRU cell |
| Normalization | Controls scale across node degrees | Degree normalization, layer norm |
| Self-loop | Keeps the node’s own information | Adding the node to its neighborhood |
Common aggregation functions
The most widely used aggregators are sum, mean, max and attention-weighted sum, and each one preserves a different kind of information about the neighborhood. Choosing among them is a trade-off between expressive power, numerical stability and robustness to degree variation.
| Aggregator | What it preserves | Main limitation | Representative model |
|---|---|---|---|
| Sum | Full multiset, including neighbor counts | Scale grows with node degree | Graph isomorphism network |
| Mean | Distribution of neighbor features | Cannot count neighbors | Graph convolutional network |
| Max | Most salient feature per dimension | Ignores multiplicity and distribution | GraphSAGE pooling variant |
| Attention | Learned importance of each neighbor | Higher cost, possible instability | Graph attention network |
| Multiple combined | Several statistics at once | More parameters and memory | PNA model |
The graph convolutional network uses a symmetrically degree-normalized sum, which behaves like a weighted mean. GraphSAGE introduced mean, LSTM and pooling aggregators over sampled neighborhoods, while graph attention networks compute attention coefficients for each edge and often use multiple attention heads to stabilize learning.
Expressive power and the Weisfeiler-Lehman connection
The expressive power of neighborhood aggregation is bounded by the one-dimensional Weisfeiler-Lehman test, a classical graph isomorphism heuristic that iteratively refines node colors from the multiset of neighbor colors. A message passing network can distinguish two graphs only if this test can distinguish them.
Reaching that upper bound requires an injective aggregation over multisets. Sum aggregation followed by a sufficiently expressive MLP satisfies this condition, which is why the graph isomorphism network uses sum. Mean and max are not injective: mean cannot tell a node with two identical neighbors from one with a single neighbor, and max cannot tell either from a node with ten identical neighbors.
The following table shows how aggregators behave on simple neighborhood multisets with scalar features.
| Neighbor features | Sum | Mean | Max |
|---|---|---|---|
| {1, 1} | 2 | 1 | 1 |
| {1} | 1 | 1 | 1 |
| {1, 1, 1, 1} | 4 | 1 | 1 |
| {0, 2} | 2 | 1 | 2 |
Only sum separates all four cases here, although sum alone still confuses {1, 1} with {0, 2}, which is why learned transformations before aggregation matter in practice.
Scaling, sampling and structural limits
On large graphs, full neighborhood aggregation becomes expensive because the number of nodes involved grows exponentially with depth. A node with an average degree of 50 can reach hundreds of thousands of nodes within three hops, a problem often called neighborhood explosion.
Several techniques control this cost. Neighbor sampling, popularized by GraphSAGE, aggregates over a fixed number of randomly sampled neighbors per layer, for example 25 and then 10. Cluster-GCN partitions the graph and aggregates within subgraphs, and personalized PageRank propagation decouples feature transformation from aggregation.
Aggregation also has structural limits. Over-smoothing makes node representations converge as depth grows, and over-squashing compresses exponentially many distant messages into fixed-size vectors through bottleneck edges. On heterophilous graphs, where connected nodes tend to differ, averaging neighbors can erase useful signals.
| Problem | Cause | Common remedy |
|---|---|---|
| Over-smoothing | Repeated averaging over many layers | Residual connections, fewer layers |
| Over-squashing | Bottleneck edges in the graph | Graph rewiring, virtual node |
| Heterophily | Neighbors carry dissimilar labels | Separate ego and neighbor embeddings |
| High-degree hubs | Unbounded sum magnitude | Degree normalization or sampling |
Choosing an aggregator in practice
The right aggregator depends on the task and the graph. Sum is preferred for graph classification and for tasks where counts matter, such as molecular property prediction. Mean is a robust default for node classification on graphs with highly variable degrees, such as social and citation networks.
- Use attention when neighbors differ strongly in relevance and the graph is moderately sized.
- Combine several aggregators with degree scalers when expressiveness matters more than cost.
- Add edge features to messages when relations carry types or weights, as in heterogeneous graphs.
- Validate depth empirically, because the best number of layers depends on graph diameter and homophily.
In everyday language
Picture a town where each person wants to understand their local area. Each day, they ask their direct neighbors what they know. They then blend those answers with their own view. After two days, they also know what their neighbors’ neighbors said.
Neighborhood aggregation does the same thing for points in a network. Each point collects information from its connections and summarizes it. The way it summarizes matters. Adding everything up keeps track of how many neighbors there are. Averaging shows only the typical neighbor.
Seen in the real world
A payment provider builds a fraud detection model on a graph of about 20 million accounts connected by transactions, shared devices and shared addresses. Each account starts with features such as account age, transaction volume and chargeback history.
The team trains a two-layer GraphSAGE model with mean aggregation and samples 15 neighbors in the first layer and 10 in the second, which keeps each training batch within GPU memory. A second variant uses sum aggregation for the device edges, because the number of accounts sharing one device is itself a strong fraud signal.
Compared with a gradient-boosting model that uses only per-account features, the graph model flags coordinated fraud rings earlier, because suspicious behavior spreads through aggregated neighbor information. Analysts review fewer false alarms at the same detection rate.