Context-Aware Code Review Automation: A Retrieval-Augmented Approach
Source abstract
Abstract
Manual code review is essential for software quality, but often slows down development cycles due to the high time demands on developers. In this study, we propose an automated solution for Python (version 3.13) projects that generates code review comments by combining Large Language Models (LLMs) with Retrieval-Augmented Generation (RAG). To achieve this, we first curated a dataset from GitHub pull requests (PRs) using the GitHub REST Application Programming Interface (API) (version 2022-11-28) and classified comments into semantic categories using a semi-supervised Support Vector Machine (SVM) model. During the review process, our system uses a vector database to retrieve the top-k most relevant historical comments, providing context for a diverse spectrum of open-weights LLMs, including DeepSeek-Coder-33B, Qwen2.5-Coder-32B, Codestral-22B, CodeLlama-13B, Mistral-Instruct-7B, and Phi-3-Mini. We evaluated the system using a multi-step validation that combined standard metrics (BLEU-4, ROUGE-L, cosine similarity) with an LLM-as-a-Judge approach, and verified the results through targeted human review to ensure consistency with expert standards. The findings show that retrieval augmentation improves feedback relevance for larger models, with DeepSeek-Coder’s alignment score increasing by 17.9% at a retrieval depth of k = 3. In contrast, smaller models such as Phi-3-Mini suffered from context collapse, where too much context reduced accuracy. To manage this trade-off, we built a hybrid expert system that routes each task to the most suitable model. Our results indicate that the proposed approach improved performance by 13.2% compared to the zero-shot baseline (k = 0). In addition, our proposed system reduces hallucinations and generates comments that closely align with the standards expected from the experts.
Source: crossref · Quality: baseline
Research context
OpenAlex topics: Software Engineering Research · Software Engineering Techniques and Practices · Software Testing and Debugging Techniques
SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.
Affiliations
Department of Computer Engineering, Yildiz Technical University, 34220 Istanbul, Turkey
ING Netherlands, 1102 CT Amsterdam, The Netherlands
References (62)
Show source-provided references
1. Bacchelli, A., and Bird, C. (2013, January 18–26). Expectations, outcomes, and challenges of modern code review. Proceedings of the 2013 International Conference on Software Engineering, San Francisco, CA, USA. ICSE ’13.10.1109/ICSE.2013.6606617 ↗
2. Sadowski, C., Söderberg, E., Church, L., Sipko, M., and Bacchelli, A. (June, January 27). Modern code review: A case study at google. Proceedings of the 40th International Conference on Software Engineering: Software Engineering in Practice, Gothenburg, Sweden. ICSE-SEIP ’18.
3. Bosu, A., and Carver, J.C. (2014, January 18–19). Impact of developer reputation on code review outcomes in OSS projects: An empirical investigation. Proceedings of the 8th ACM/IEEE International Symposium on Empirical Software Engineering and Measurement, Torino, Italy.10.1145/2652524.2652544 ↗
4. Rahman, F., Posnett, D., and Devanbu, P. (2012, January 11–16). Recalling the “imprecision” of cross-project defect prediction. Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering, Cary North, CA, USA. FSE ’12.10.1145/2393596.2393669 ↗
5. Johnson, B., Song, Y., Murphy-Hill, E., and Bowdidge, R. (2013, January 18–26). Why don’t software developers use static analysis tools to find bugs?. Proceedings of the 2013 35th International Conference on Software Engineering (ICSE), San Francisco, CA, USA.10.1109/ICSE.2013.6606613 ↗
6. Chen, M., Tworek, J., Jun, H., Yuan, Q., Pondé, H., Kaplan, J., Edwards, H., Burda, Y., Joseph, N., and Brockman, G. (2021). Evaluating Large Language Models Trained on Code. arXiv.
7. Zhang, Q., Fang, C., Xie, Y., Zhang, Y., Yang, Y., Sun, W., Yu, S., and Chen, Z. (2024). A Survey on Large Language Models for Software Engineering. arXiv.
8. Turzo, A.K., Faysal, F., Poddar, O., Sarker, J., Iqbal, A., and Bosu, A. (2023, January 26–27). Towards Automated Classification of Code Review Feedback to Support Analytics. Proceedings of the 2023 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM), New Orleans, LA, USA.10.1109/ESEM56168.2023.10304851 ↗
9. Design and code inspections to reduce errors in program development10.1147/sj.153.0182 ↗
10. A systematic literature review of recent advances on context-aware recommender systems10.1007/s10462-024-10939-4 ↗
11. Sadman, N., Ahsan, M.M., and Mahmud, M.A. (2020, January 28–31). ADCR: An Adaptive Tool to select “Appropriate Developer for Code Review” based on Code Context. Proceedings of the 2020 11th IEEE Annual Ubiquitous Computing, Electronics & Mobile Communication Conference (UEMCON), New York, NY, USA.10.1109/UEMCON51285.2020.9298102 ↗
12. An Empirical Study on Learning Bug-Fixing Patches in the Wild via Neural Machine Translation10.1145/3340544 ↗
13. Li, Z., Lu, S., Guo, D., Duan, N., Jannu, S., Jenks, G., Majumder, D., Green, J., Svyatkovskiy, A., and Fu, S. (2022). CodeReviewer: Pre-Training for Automating Code Review Activities. arXiv.
14. Lin, H.Y., Thongtanunam, P., Treude, C., Godfrey, M.W., Liu, C., and Charoenwet, W. (2025). Leveraging Reviewer Experience in Code Review Comment Generation. ACM Trans. Softw. Eng. Methodol.10.1145/3762183 ↗
15. Rasheed, Z., Sami, M.A., Waseem, M., Kemell, K.K., Wang, X., Nguyen, A., Systä, K., and Abrahamsson, P. (2025). AI-powered Code Review with LLMs: Early Results. arXiv.
16. Leveraging Large Language Models for Enhanced Code Review10.1051/epjconf/202533701066 ↗
17. Haroon, S., Khan, A.F., Humayun, A., Gill, W., Amjad, A.H., Butt, A.R., Khan, M.T., and Gulzar, M.A. (2025). How Accurately Do Large Language Models Understand Code?. arXiv.
18. Lewis, P., Perez, E., Piktus, A., Petroni, F., Karpukhin, V., Goyal, N., Küttler, H., Lewis, M., Yih, W.t., and Rocktäschel, T. (2020, January 6–12). Retrieval-augmented generation for knowledge-intensive NLP tasks. Proceedings of the 34th International Conference on Neural Information Processing Systems, Red Hook, NY, USA. NIPS ’20.
19. Hong, H., and Baik, J. (2025). Retrieval-Augmented Code Review Comment Generation. arXiv.
20. Chiruzzo, L., Ritter, A., and Wang, L. (2025). CodeRAG-Bench: Can Retrieval Augment Code Generation?. Proceedings of the Findings of the Association for Computational Linguistics: NAACL 2025, Association for Computational Linguistics.
21. (2025, December 23). Qdrant: Vector Database for the Next Generation of AI Applications. Available online: https://qdrant.tech/.
22. Zhang, Y., Li, Y., Cui, L., Cai, D., Liu, L., Fu, T., Huang, X., Zhao, E., Zhang, Y., and Xu, C. (2025). Siren’s Song in the AI Ocean: A Survey on Hallucination in Large Language Models. arXiv.10.1162/COLI.a.16 ↗
23. (2025, December 23). Sentence-Transformers/All-MiniLM-L6-v2: Model Card. Available online: https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2.
24. Manning, C.D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, Cambridge University Press.10.1017/CBO9780511809071 ↗
25. Reimers, N., and Gurevych, I. (2019, January 3–7). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), Hong Kong, China.10.18653/v1/D19-1410 ↗
26. Brown, T.B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., and Askell, A. (2020, January 6–12). Language models are few-shot learners. Proceedings of the 34th International Conference on Neural Information Processing Systems, Red Hook, NY, USA. NIPS ’20.
27. Kalliamvakou, E., Gousios, G., Blincoe, K., Singer, L., German, D.M., and Damian, D. (June, January 31). The promises and perils of mining GitHub. Proceedings of the 11th Working Conference on Mining Software Repositories, Hyderabad, India. MSR 2014.10.1145/2597073.2597074 ↗
28. Term-weighting approaches in automatic text retrieval10.1016/0306-4573(88)90021-0 ↗
29. Support-Vector Networks10.1023/A:1022627411411 ↗
30. Self-labeled techniques for semi-supervised learning: Taxonomy, software and empirical study10.1007/s10115-013-0706-y ↗
31. Home Assistant Community (2025, December 23). Home-Assistant/Core: Open Source Home Automation That Puts Local Control and Privacy First. Available online: https://github.com/home-assistant/core.
32. Home Assistant Developer Docs (2025, December 23). Integration Architecture. Available online: https://developers.home-assistant.io/docs/architecture_components/.
33. (2025, December 23). Home Assistant Developer Docs. Pull Request Review Process. Available online: https://developers.home-assistant.io/docs/review-process/.
34. (2025, December 22). Open LLM Leaderboard. Hugging Face. Available online: https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard.
35. Team, O. (2024, December 23). Ollama: Large Language Model Runner. Available online: https://github.com/ollama/ollama.
36. Guo, D., Zhu, Q., Yang, D., Xie, Z., Dong, K., Zhang, W., Chen, G., Bi, X., Wu, Y., and Li, Y.K. (2024). DeepSeek-Coder: When the Large Language Model Meets Programming—The Rise of Code Intelligence. arXiv.
37. Hui, B., Yang, J., Cui, Z., Yang, J., Liu, D., Zhang, L., Liu, T., Zhang, J., Yu, B., and Lu, K. (2024). Qwen2.5-Coder Technical Report. arXiv.
38. Mistral AI Team (2025, December 23). Codestral: Hello, World! 2024. Available online: https://mistral.ai/news/codestral/.
39. Rozière, B., Gehring, J., Gloeckle, F., Sootla, S., Gat, I., Tan, X., Adi, Y., Liu, J., Remez, T., and Rapin, J. (2023). Code Llama: Open Foundation Models for Code. arXiv.
40. Jiang, A.Q., Sablayrolles, A., Mensch, A., Bamford, C., Chaplot, D.S., de las Casas, D., Bressand, F., Lengyel, G., Lample, G., and Saulnier, L. (2023). Mistral 7B. arXiv.
41. Abdin, M., Aneja, J., Awadalla, H., Awadallah, A., Awan, A.A., Bach, N., Bahree, A., Bakhtiari, A., Bao, J., and Behl, H. (2024). Phi-3 Technical Report: A Highly Capable Language Model Locally on Your Phone. arXiv.
42. Isabelle, P., Charniak, E., and Lin, D. (2002). Bleu: A Method for Automatic Evaluation of Machine Translation. Proceedings of the 40th Annual Meeting of the Association for Computational Linguistics, Association for Computational Linguistics.
43. Lin, C.Y. (2004, January 25–26). ROUGE: A Package for Automatic Evaluation of Summaries. Proceedings of the Text Summarization Branches Out, Barcelona, Spain.
44. Post, M. (November, January 31). A Call for Clarity in Reporting BLEU Scores. Proceedings of the Conference on Machine Translation, Brussels, Belgium.
45. Zheng, L., Chiang, W.L., Sheng, Y., Zhuang, S., Wu, Z., Zhuang, Y., Lin, Z., Li, Z., Li, D., and Xing, E.P. (2023, January 10–16). Judging LLM-as-a-judge with MT-bench and Chatbot Arena. Proceedings of the 37th International Conference on Neural Information Processing Systems, Red Hook, NY, USA. NIPS ’23.
46. Grattafiori, A., Dubey, A., Jauhri, A., Pandey, A., Kadian, A., Al-Dahle, A., Letman, A., Mathur, A., Schelten, A., and Vaughan, A. (2024). The Llama 3 Herd of Models. arXiv.
47. Ouyang, L., Wu, J., Jiang, X., Almeida, D., Wainwright, C.L., Mishkin, P., Zhang, C., Agarwal, S., Slama, K., and Ray, A. (2022, January 6–12). Training language models to follow instructions with human feedback. Proceedings of the 36th International Conference on Neural Information Processing Systems, Red Hook, NY, USA. NIPS ’22.
48. Hu, M., Wu, H., Guan, Z., Zhu, R., Guo, D., Qi, D., and Li, S. (2024). No Free Lunch: Retrieval-Augmented Generation Undermines Fairness in LLMs, Even for Vigilant Users. arXiv.10.18653/v1/2025.findings-emnlp.984 ↗
49. Lost in the Middle: How Language Models Use Long Contexts10.1162/tacl_a_00638 ↗
50. Askell, A., Bai, Y., Chen, A., Drain, D., Ganguli, D., Henighan, T., Jones, A., Joseph, N., Mann, B., and DasSarma, N. (2021). A General Language Assistant as a Laboratory for Alignment. arXiv.
51. Approximate Statistical Tests for Comparing Supervised Classification Learning Algorithms10.1162/089976698300017197 ↗
52. Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences, Lawrence Erlbaum Associates.
53. Ren, S., Guo, D., Lu, S., Zhou, L., Liu, S., Tang, D., Sundaresan, N., Zhou, M., Blanco, A., and Ma, S. (2020). CodeBLEU: A Method for Automatic Evaluation of Code Synthesis. arXiv.
54. The proof and measurement of association between two things10.1093/ije/dyq191 ↗
55. Weighted kappa: Nominal scale agreement provision for scaled disagreement or partial credit10.1037/h0026256 ↗
56. The measurement of observer agreement for categorical data10.2307/2529310 ↗
57. Muresan, S., Nakov, P., and Villavicencio, A. (2022). UniXcoder: Unified Cross-Modal Pre-training for Code Representation. Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), Association for Computational Linguistics.
58. 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.
59. OpenAI (2025, December 26). Introducing GPT-5. OpenAI Blog, 2025. Available online: https://openai.com/index/introducing-gpt-5.
60. Anthropic (2025, December 26). Introducing Claude 4. Anthropic News. Available online: https://www.anthropic.com/news/claude-4.
61. Rafailov, R., Sharma, A., Mitchell, E., Ermon, S., Manning, C.D., and Finn, C. (2024). Direct Preference Optimization: Your Language Model is Secretly a Reward Model. arXiv.
62. (2026, January 15). RunPod: GPU Cloud for AI. Available online: https://console.runpod.io.