A graph embedding, also called a whole-graph embedding, is a fixed-length vector that represents an entire graph, so that structurally or functionally similar graphs lie close together in the vector space. In graph learning, a branch of artificial intelligence, it turns objects of varying size and shape, such as molecules, social communities or program call graphs, into inputs that standard classifiers, regressors and similarity search systems can handle.
The term is sometimes used loosely for node embeddings as well. In the strict sense used here, a node embedding assigns one vector to each node, while a graph embedding assigns one vector to the whole graph, usually by summarizing node-level information through a readout step.
How a whole-graph embedding is produced
Most modern graph embeddings follow a two-stage pipeline: first compute node representations, then aggregate them into one vector. Both stages must respect the fact that a graph has no natural node ordering, so the final vector must be invariant to permutations of the node labels.
In the first stage, a message passing neural network such as a graph convolutional network or a graph isomorphism network updates each node vector by aggregating features from its neighbors over several layers. After k layers, each node vector summarizes its k-hop neighborhood. In the second stage, a readout function combines all node vectors, for example by summing them, into the graph-level embedding.
Older approaches skip neural networks altogether. Graph kernels count substructures such as subtrees, walks or small subgraphs, while unsupervised methods such as graph2vec treat rooted subgraphs as words and learn document-style embeddings. Spectral approaches derive a signature from the eigenvalues of the graph Laplacian.
Families of graph embedding methods
Graph embedding methods differ in whether they learn from labels, how they capture structure and how well they scale. The table below groups the main families used in research and industry.
| Family | Core idea | Supervision | Typical example |
|---|---|---|---|
| Graph kernels | Count shared substructures between graphs | None, used with SVMs | Weisfeiler-Lehman subtree kernel |
| Substructure skip-gram | Learn vectors from rooted subgraph co-occurrence | Unsupervised | graph2vec |
| Spectral signatures | Summarize Laplacian eigenvalues or heat traces | Unsupervised | NetLSD |
| GNN with readout | Message passing then pooling | Supervised or self-supervised | GIN with sum readout |
| Contrastive GNN | Pull augmented views of a graph together | Self-supervised | GraphCL, InfoGraph |
Kernels remain strong baselines on small benchmark datasets, but they scale quadratically with the number of graphs because each pair must be compared. Neural methods produce explicit vectors, which allows approximate nearest-neighbor search over millions of graphs.
Readout and graph pooling choices
The readout function largely determines what information survives in the final vector. Simple permutation-invariant operators are fast and stable, while learned pooling methods can capture hierarchical structure at a higher computational cost.
| Readout | What it preserves | Weakness |
|---|---|---|
| Sum pooling | Counts and multiset structure | Magnitude grows with graph size |
| Mean pooling | Feature distribution | Cannot distinguish graph size |
| Max pooling | Most salient features | Discards frequency information |
| Attention pooling | Weighted importance of nodes | Adds parameters and variance |
| Hierarchical pooling | Cluster and motif structure | Higher memory, harder to train |
Theory gives a clear guideline: with injective neighborhood aggregation, sum readout is the most expressive of the simple options, because mean and max can map different multisets of node vectors to the same result. Practitioners often concatenate readouts from every layer to keep both local and wider-range information.
Expressive power and its limits
Standard message passing networks are at most as powerful as the 1-dimensional Weisfeiler-Lehman test at telling non-isomorphic graphs apart. As a result, some structurally different graphs, such as two disjoint triangles and a single six-node cycle, receive identical embeddings when node features are uniform.
Several remedies raise expressiveness: higher-order networks based on k-WL, subgraph-based models, random or structural node features, and positional encodings derived from Laplacian eigenvectors, as used in graph transformers. Each adds computation, and some sacrifice exact permutation invariance unless handled carefully.
Depth brings its own problems. Too many layers cause over-smoothing, where node vectors converge and the graph embedding loses detail, and over-squashing, where information from distant nodes is compressed through narrow bottlenecks.
Graph embedding compared with related representations
Graph embedding is often confused with neighboring representation types in graph representation learning. The distinction depends on what the vector describes and which task it serves.
| Representation | Unit embedded | Typical downstream task |
|---|---|---|
| Graph embedding | Entire graph | Graph classification, similarity search |
| Node embedding | Single node | Node classification, link prediction |
| Knowledge graph embedding | Entities and relation types | Triple completion with TransE or RotatE |
| Subgraph embedding | Selected node subset | Community or motif analysis |
The boundaries are not rigid. A graph embedding can be derived from node embeddings by pooling, and a node embedding can be enriched with a virtual node that stores a graph-level summary during message passing. What matters is the unit the final vector describes, because evaluation metrics, data splits and leakage risks all follow from that choice.
Practical guidance and common mistakes
A reliable workflow starts with a Weisfeiler-Lehman kernel baseline and a GIN with sum readout, then adds complexity only when validation results justify it. Small graph classification benchmarks show high variance across random splits, so results should be reported over repeated folds.
- Ignoring edge and node features, which often carry more signal than topology alone.
- Choosing mean readout by default when graph size itself is predictive.
- Leaking near-duplicate graphs across train and test splits, common with molecular scaffolds.
- Comparing embeddings from different models as if they shared one vector space.
- Stacking many layers on small graphs, which triggers over-smoothing.
For retrieval systems, embedding dimensions between 64 and 512 are typical, and vectors are often L2-normalized so that cosine similarity reflects structural closeness rather than graph size. Any model update requires re-embedding the whole collection, since vectors from different checkpoints are not comparable.
In everyday language
Many things are networks: a molecule is atoms joined by bonds, and a friend group is people joined by friendships. Computers struggle to compare networks directly, because they come in all shapes and sizes.
A graph embedding solves this by turning each whole network into a short list of numbers. Networks that look or behave alike get similar lists. Think of it as a fingerprint for a network. Once every network has a fingerprint, finding similar ones becomes a quick comparison of numbers.
Seen in the real world
A pharmaceutical research team screens about two million candidate molecules for possible toxicity. Each molecule is represented as a graph with atoms as nodes and bonds as edges, with features such as element type, charge and bond order.
The team pretrains a graph isomorphism network with contrastive self-supervision on the full library, then fine-tunes it on roughly 8,000 molecules with known toxicity labels. A sum readout over all layers produces a 300-dimensional graph embedding for every molecule, which feeds a small classifier and an approximate nearest-neighbor index.
When chemists flag a promising compound, the index returns its closest structural neighbors in milliseconds, and the classifier ranks them by predicted risk. Compared with the previous fingerprint-based screening, the team prioritizes a shortlist of a few hundred molecules for laboratory testing and finds toxic candidates earlier, reducing wasted synthesis work.