Repository-level code completion with adaptive segmentation and fused retrieval
摘要
Code completion is of significant importance for improving development efficiency, reducing errors, and improving code quality. The development of code completion models is continuously evolving and has achieved significant progress, but existing code completion models still have limitations in accuracy for repository-level code-completion tasks that span multiple files and have a large number of cross-file dependencies. State-of-the-art retrieval augmented generation (RAG) results have motivated the use of the context of the entire codebase for repository-level code completion tasks to improve the prediction accuracy of large language models. In this study, we target RAG techniques to address the issues of constraints from current code completion models. To address the issue of code logic fragmentation caused by fixed-line segmentation, we prioritize code logical integrity and propose an adaptive segmentation strategy combined with a fused retrieval framework based on RAG technology and code structure analysis. We propose a structure-aware adaptive segmentation strategy that constructs functionally complete retrieval databases by analyzing structural units such as classes and functions. We use the fusion retrieval mechanism integrating both textual and functional similarity matching to enhance the quality and relevance of retrieved cross-file contexts. Experimental results on the CrossCodeEval benchmark demonstrate that our fused retrieval method achieves significant performance improvements over existing models.