Detecting Small Query Graphs in A Large Graph via Neural Subgraph Search

Yunsheng Bai, Derek Qiang Xu, Yizhou Sun, Wei Wang · DOI

Abstract

Recent advances have shown the success of using reinforcement learning and search to solve NP-hard graph-related tasks. However, efficiently and accurately detecting small query graphs in large target graphs—a core operation in graph databases and biomedical analysis—remains challenging. This task, Subgraph Matching, involves subgraph isomorphism checks where the target graph is often orders-of-magnitude larger than the query. We propose NSUBS, a neural subgraph search framework featuring a novel encoder-decoder architecture that dynamically computes matching information and a look-ahead loss function for policy training. Experiments on six large real-world graphs demonstrate that NSUBS significantly improves subgraph matching performance over traditional and learning-based baselines.

Introduction

Subgraph matching is a fundamental problem in computer science with applications ranging from drug discovery to social network analysis. Given its NP-hard nature, traditional solvers rely on backtracking search guided by hand-crafted heuristics. While effective for smaller instances, these heuristics often struggle with the massive search spaces presented by modern large-scale graphs.

The "learning-to-search" paradigm offers a promising alternative, using reinforcement learning (RL) to guide search algorithms. However, applying RL to subgraph matching introduces unique challenges: the extreme size disparity between query and target graphs leads to solution and reward sparsity, making it difficult for agents to learn effective policies.

Methodology: Neural Subgraph Search (NSUBS)

NSUBS addresses these challenges by replacing static heuristics with a learned policy. The framework consists of two primary innovations:

1. QC-SGMNN Architecture

The Query-Conditioned Subgraph Matching Neural Network (QC-SGMNN) utilizes a decoupled encoder-decoder design.

  • Encoder: Separates intra-graph message passing (static features) from inter-graph matching (dynamic search state). By caching state-independent node embeddings at the start of the search, NSUBS minimizes per-step computational overhead.
  • Decoder: An attention-based module that generates a state embedding by focusing on relevant query nodes and outputs a probability distribution over candidate target nodes.
The NSUBS architecture decouples state-independent node embeddings from state-dependent matching to ensure search efficiency.

2. Look-ahead Loss

To combat reward sparsity, where successful matches are rare during training, we introduce a look-ahead loss function. Instead of relying solely on immediate feedback, this function incorporates signals from future successful states in the search tree, providing a denser and more informative training signal for the policy network.

Experimental Evaluation

We evaluated NSUBS on one synthetic dataset (BA) and six real-world target graphs: BRAIN, HPRD (biological), COSMOS (astronomy), DBLP (citation), ETHE (blockchain), and YOUTUBE (social).

Performance and Scalability

NSUBS was compared against seven state-of-the-art backtracking solvers (e.g., GraphQL, CECI) and the learning-based NMatch.

Performance comparison of NSUBS against baseline solvers across multiple datasets. NSUBS (red line) consistently solves more pairs as time progresses.

Key findings include:

  • Higher Success Rates: NSUBS significantly outperformed all baselines in the number of solved pairs within a 5-minute window. For instance, on the HPRD dataset, NSUBS achieved a 48% success rate compared to the 16% of the best baseline.
  • Search Efficiency: Although the initial neural network forward pass introduces some overhead, NSUBS's superior search guidance allows it to quickly overtake heuristic-based methods as the complexity of the search space increases.
  • Solution Density: NSUBS proved more effective at finding multiple occurrences of a query graph, highlighting its ability to navigate complex graph topologies.

Conclusion

NSUBS demonstrates that a learned policy, supported by efficient architecture and dense training signals, can overcome the limitations of traditional heuristics in large-scale subgraph matching. By decoupling static and dynamic computations, NSUBS achieves the speed necessary for real-time search while maintaining high accuracy. Future work will focus on further reducing initial overhead and extending the framework to even larger query graphs.

Summary updated

BibTeX
@inproceedings{bai2022detecting,
  author = {Yunsheng Bai and Derek Qiang Xu and Yizhou Sun and Wei Wang},
  title = {{Detecting Small Query Graphs in A Large Graph via Neural Subgraph Search}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  doi = {10.48550/arxiv.2207.10305},
}
Figure