journal article·2025-12-19Open access

Early-Stage Graph Fusion with Refined Graph Neural Networks for Semantic Code Search

Longhao Ao, Rongzhi Qi

Applied Sciences· Volume 16· Issue 1

Abstract

Code search has received significant attention in the field of computer science research. Its core objective is to retrieve the most semantically relevant code snippets by aligning the semantics of natural language queries with those of programming languages, thereby contributing to improvements in software development quality and efficiency. As the scale of public code repositories continues to expand rapidly, the ability to accurately understand and efficiently match relevant code has become a critical challenge. Furthermore, while numerous studies have demonstrated the efficacy of deep learning in code-related tasks, the mapping and semantic correlations are often inadequately addressed, leading to the disruption of structural integrity and insufficient representational capacity during semantic matching. To overcome these limitations, we propose the Functional Program Graph for Code Search (called FPGraphCS), a novel code search method that leverages the construction of functional program graphs and an early fusion strategy. By incorporating abstract syntax tree (AST), data dependency graph (DDG), and control flow graph (CFG), the method constructs a comprehensive multigraph representation, enriched with contextual information. Additionally, we propose an improved metapath aggregation graph neural network (IMAGNN) model for the extraction of code features with complex semantic correlations from heterogeneous graphs. Through the use of metapath-associated subgraphs and dynamic metapath selection via a graph attention mechanism, FPGraphCS significantly enhances its search capability. The experimental results demonstrate that FPGraphCS outperforms existing baseline methods, achieving an MRR of 0.65 and ACC@10 of 0.842, showing a significant improvement over previous approaches.
Source: crossref · Quality: baseline

Research context

OpenAlex topics: Software Engineering Research · Software Testing and Debugging Techniques · Advanced Malware Detection Techniques

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

Affiliations

College of Computer Science and Software Engineering, Hohai University, Nanjing 211100, China

Key Laboratory of Water Big Data Technology of Ministry of Water Resources, Hohai University, Nanjing 211100, China

References (40)

Show source-provided references
1. Mao, Y., Wan, C., Jiang, Y., and Gu, X. (2023, January 3–9). Self-Supervised Query Reformulation for Code Search. Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering, San Francisco, CA, USA.10.1145/3611643.3616306 ↗
2. Lv, F., Zhang, H., Lou, J.-G., Wang, S., Zhang, D., and Zhao, J. (2015, January 9–13). CodeHow: Effective Code Search Based on API Understanding and Extended Boolean Model. Proceedings of the 30th IEEE/ACM International Conference on Automated Software Engineering, Lincoln, NE, USA.10.1109/ASE.2015.42 ↗
3. Query Expansion Based on Crowd Knowledge for Code Search10.1109/TSC.2016.2560165 ↗
4. Wang, C., Nong, Z., Gao, C., Li, Z., Zeng, J., Xing, Z., and Liu, Y. (2021). Enriching Query Semantics for Code Search with Reinforcement Learning. arXiv.10.1016/j.neunet.2021.09.025 ↗
5. Huang, J., Tang, D., Shou, L., Gong, M., Xu, K., Jiang, D., Zhou, M., and Duan, N. (2021). CoSQA: 20,000+ Web Queries for Code Search and Question Answering. arXiv.10.18653/v1/2021.acl-long.442 ↗
6. Survey of Code Search Based on Deep Learning
7. GT-SimNet: Improving Code Automatic Summarization via Multi-Modal Similarity Networks10.1016/j.jss.2022.111495 ↗
8. Niu, C., Li, C., Ng, V., Ge, J., Huang, L., and Luo, B. (2022, January 22–27). SPT-code: Sequence-to-Sequence Pre-training for Learning Source Code Representations. Proceedings of the 44th International Conference on Software Engineering, Pittsburgh, PA, USA.10.1145/3510003.3510096 ↗
9. CRaDLe: Deep Code Retrieval Based on Semantic Dependency Learning10.1016/j.neunet.2021.04.019 ↗
10. Fu, X., Zhang, J., Meng, Z., and King, I. (2020, January 20–24). MAGNN: Metapath Aggregated Graph Neural Network for Heterogeneous Graph Embedding. Proceedings of the Web Conference 2020, Taipei, Taiwan.10.1145/3366423.3380297 ↗
11. Husain, H., Wu, H.-H., Gazit, T., Allamanis, M., and Brockschmidt, M. (2019). CodeSearchNet Challenge: Evaluating the State of Semantic Code Search. arXiv.
12. A Survey of Source Code Search: A 3-Dimensional Perspective10.1145/3656341 ↗
13. On the Effectiveness of Transfer Learning for Code Search10.1109/TSE.2022.3192755 ↗
14. Chen, J., Hu, X., Li, Z., Gao, C., Xia, X., and Lo, D. (2024, January 14–20). Code Search Is All You Need? Improving Code Suggestions with Code Search. Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, Lisbon, Portugal.10.1145/3597503.3639085 ↗
15. Gu, X., Zhang, H., and Kim, S. (June, January 27). Deep Code Search. Proceedings of the 40th International Conference on Software Engineering, Gothenburg, Sweden.
16. Sachdev, S., Li, H., Luan, S., Kim, S., Sen, K., and Chandra, S. (2018, January 18). Retrieval on Source Code: A Neural Code Search. Proceedings of the 2nd ACM SIGPLAN International Workshop on Machine Learning and Programming Languages, Philadelphia, PA, USA.10.1145/3211346.3211353 ↗
17. Xu, L., Yang, H., Liu, C., Shuai, J., Yan, M., Lei, Y., and Xu, Z. (2021, January 9–12). Two-Stage Attention-Based Model for Code Search with Textual and Structural Features. Proceedings of the 2021 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), Luxembourg.10.1109/SANER50967.2021.00039 ↗
18. Hu, Y., Cai, B., and Yu, Y. (2022). CSSAM: Code Search via Attention Matching of Code Semantics and Structures. arXiv.
19. Guo, D., Ren, S., Lu, S., Feng, Z., Tang, D., Liu, S., Zhou, L., Duan, N., Svyatkovskiy, A., and Fu, S. (2020). GraphCodeBERT: Pre-training Code Representations with Data Flow. arXiv.
20. Zhao, W., and Liu, Y. (2022, January 1–10). Utilising Edge Attention in Graph-Based Code Search. Proceedings of the 34th International Conference on Software Engineering and Knowledge Engineering, SEKE 2022, Pittsburgh, PA, USA.10.18293/SEKE2022-078 ↗
21. Wan, Y., Shu, J., Sui, Y., Xu, G., Zhao, Z., Wu, J., and Yu, P.S. (2019, January 11–15). Multi-Modal Attention Network Learning for Semantic Source Code Retrieval. Proceedings of the 34th IEEE/ACM International Conference on Automated Software Engineering, San Diego, CA, USA.10.1109/ASE.2019.00012 ↗
22. Tai, K.S., Socher, R., and Manning, C.D. (July, January 26). Improved Semantic Representations From Tree-Structured Long Short-Term Memory Networks. Proceedings of the 53rd Annual Meeting of the Association for Computational Linguistics and the 7th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), Beijing, China.
23. Gu, J., Chen, Z., and Monperrus, M. (2021). Multimodal Representation for Neural Code Search. arXiv.10.1109/ICSME52107.2021.00049 ↗
24. deGraphCS: Embedding Variable-based Flow Graph for Neural Code Search10.1145/3546066 ↗
25. GraphSearchNet: Enhancing GNNs via Capturing Global Dependencies for Semantic Code Search10.1109/TSE.2022.3233901 ↗
26. Yang, X., Yan, M., Pan, S., Ye, X., and Fan, D. (2023). Simple and Efficient Heterogeneous Graph Neural Network. arXiv.10.1609/aaai.v37i9.26283 ↗
27. MECCH: Metapath Context Convolution-based Heterogeneous Graph Neural Networks10.1016/j.neunet.2023.11.030 ↗
28. Zhou, W., Huang, H., Shi, R., Yin, K., and Jin, H. (2024, January 20–27). An Efficient Subgraph-Inferring Framework for Large-Scale Heterogeneous Graphs. Proceedings of the Thirty-Eighth AAAI Conference on Artificial Intelligence (AAAI 2024), Vancouver, BC, Canada.
29. Deep Graph Matching and Searching for Semantic Code Retrieval10.1145/3447571 ↗
30. Higher-Order Attribute-Enhancing Heterogeneous Graph Neural Networks
31. Schlichtkrull, M., Kipf, T.N., Bloem, P., van den Berg, R., Titov, I., and Welling, M. (2017). Modeling Relational Data with Graph Convolutional Networks. arXiv.10.1007/978-3-319-93417-4_38 ↗
32. Wang, X., Ji, H., Shi, C., Wang, B., Cui, P., Yu, P.S., and Ye, Y. (2021). Heterogeneous Graph Attention Network. arXiv.
33. Hu, F., Wang, Y., Du, L., Li, X., Zhang, H., Han, S., and Zhang, D. (March, January 27). Revisiting Code Search in a Two-Stage Paradigm. Proceedings of the Sixteenth ACM International Conference on Web Search and Data Mining, Singapore.
34. Zhu, Q., Sun, Z., Liang, X., Xiong, Y., and Zhang, L. (2020, January 21–25). OCoR: An Overlapping-Aware Code Retriever. Proceedings of the 35th IEEE/ACM International Conference on Automated Software Engineering, Melbourne, Australia.10.1145/3324884.3416530 ↗
35. The Program Dependence Graph and Its Use in Optimization10.1145/24039.24041 ↗
36. Deng, Z., Xu, L., Liu, C., Yan, M., Xu, Z., and Lei, Y. (2022, January 15–18). Fine-Grained Co-Attentive Representation Learning for Semantic Code Search. Proceedings of the 2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), Honolulu, HI, USA.10.1109/SANER53432.2022.00055 ↗
37. Shuai, J., Xu, L., Liu, C., Yan, M., Xia, X., and Lei, Y. (2020, January 5–11). Improving Code Search with Co-Attentive Representation Learning. Proceedings of the 28th International Conference on Program Comprehension, Seoul, Republic of Korea.10.1145/3387904.3389269 ↗
38. Gu, W., Wang, Y., Du, L., Zhang, H., Han, S., Zhang, D., and Lyu, M. (2022, January 22–27). Accelerating Code Search with Deep Hashing and Code Classification. Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), Dublin, Ireland.10.18653/v1/2022.acl-long.181 ↗
39. Feng, Z., Guo, D., Tang, D., Duan, N., Feng, X., Gong, M., Shou, L., Qin, B., Liu, T., and Jiang, D. (2020). CodeBERT: A Pre-Trained Model for Programming and Natural Languages. arXiv.10.18653/v1/2020.findings-emnlp.139 ↗
40. Guo, D., Lu, S., Duan, N., Wang, Y., Zhou, M., and Yin, J. (2022). UniXcoder: Unified Cross-Modal Pre-training for Code Representation. arXiv.10.18653/v1/2022.acl-long.499 ↗