A subgraph is a graph formed from selected nodes and their corresponding edges in a larger graph. It makes large or disconnected graphs easier to process, inspect, and model. Creating one requires filtering edges that leave the selected node set, relabeling nodes consistently, and keeping features, labels, and original identifiers aligned. section 3.1.1 section 8.3
A practical subgraph-construction pipeline is:
- Select nodes using an index range, domain rule, connected-component analysis, or graph-sampling strategy. section 3.1.1 section 3.6
- Filter the edge list so that retained edges connect only retained nodes. section 3.1.1
- Relabel retained nodes, then slice and reassign their features and labels using the new ordering. section 3.1.1
- Preserve mappings to original node indices when downstream work needs identifiers such as product categories or SKUs. section 3.1.1
Reducing a product graph
For the Amazon Products graph, selecting the first 10,000 node indices creates a smaller working graph from 2.5 million nodes and 61.9 million co-purchase edges. PyTorch Geometric's subgraph utility returns filtered edges and can relabel nodes; features and labels are then sliced into a new graph object. section 3.1.1
Figure 8.12 The full graph, with its large connected component in the middle, surrounded by many smaller components. For our example, we’ll use only the nodes in the large connected component.
A graph visualization contrasts one large connected component with many small components, motivating subgraph extraction before analysis. section 8.3.3

