arXiv:2412.08063cs.SEcs.AI2024-12被引 6

用仓库级上下文提升代码补全准确率

ContextModule: Improving Code Completion via Repository-level Contextual Information

  • 融合用户行为、相似代码和关键符号定义三类上下文
  • 在真实开发环境中将补全准确率和接受率显著提升
  • 适合需要高精度代码补全的工程团队使用

大型语言模型(LLMs)在代码补全任务中表现出色,能实时辅助开发者生成新代码。然而,现有基于LLM的补全系统主要依赖文件内局部上下文,常忽略仓库级信息、用户行为及编辑历史等重要线索。同时,如何从大规模仓库中高效检索相关代码片段、整合用户行为数据,并在生产环境中兼顾准确性与低延迟,仍是未解难题。本文提出ContextModule框架,通过检索并集成三类仓库级上下文信息:基于用户行为的代码、相似代码片段以及关键符号定义。该框架结合跨文件用户交互分析与全局静态分析,提升了生成代码的相关性与精确度。我们还引入索引缓存等性能优化技术,确保系统满足实际编码场景的延迟要求。实验结果与工业实践表明,ContextModule显著提升了代码补全的准确率与用户采纳率。

原文摘要 · Abstract (English)

Large Language Models (LLMs) have demonstrated impressive capabilities in code completion tasks, where they assist developers by predicting and generating new code in real-time. However, existing LLM-based code completion systems primarily rely on the immediate context of the file being edited, often missing valuable repository-level information, user behaviour and edit history that could improve suggestion accuracy. Additionally, challenges such as efficiently retrieving relevant code snippets from large repositories, incorporating user behavior, and balancing accuracy with low-latency requirements in production environments remain unresolved. In this paper, we propose ContextModule, a framework designed to enhance LLM-based code completion by retrieving and integrating three types of contextual information from the repository: user behavior-based code, similar code snippets, and critical symbol definitions. By capturing user interactions across files and leveraging repository-wide static analysis, ContextModule improves the relevance and precision of generated code. We implement performance optimizations, such as index caching, to ensure the system meets the latency constraints of real-world coding environments. Experimental results and industrial practise demonstrate that ContextModule significantly improves code completion accuracy and user acceptance rates.

代码补全上下文增强LLM应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。