The invention relates to the technical field of
software engineering, in particular to an automatic
code review method based on retrieval enhancement generation (RAG), and relates to the technical field of
software engineering, in particular to an automatic
code review method based on RAG. The method comprises the steps that a vector
database containing historical code repair examples is constructed, after code change fragments are encoded, similar examples are retrieved, and a
retrieval result is fused to guide a generation model to complete a review task; by introducing a contrast learning mechanism, the representation capability of an
encoder is optimized, so that code snippets with similar
semantics are more closely distributed in a vector space, and the retrieval accuracy is improved; furthermore, retrieval data is organized by adopting a graph structure, a graph is constructed according to meta-information such as defect types, project affiliation and
semantic similarity, graph-guided retrieval is performed based on the graph, and a GraphRAG method is realized. According to the method, four tasks of code problem detection, problem positioning, problem type identification and optimized
code generation are automatically completed, the accuracy, consistency and
interpretability of a review result are remarkably improved, and the method is suitable for intelligent auxiliary development and quality guarantee scenes in a large-scale
software project.