SpecAgent提前分析代码库,提升补全质量并降低延迟。
SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion
- 在索引阶段预探索文件,构建未来编辑的推测性上下文。
- 相比最优基线,代码生成准确率提升9-11%(相对48-58%),延迟显著下降。
- 提出无未来信息泄露的合成评测集,评估更真实可靠。
大语言模型在代码任务中表现优异,但在真实软件仓库中常因项目特定API和跨文件依赖而受限。检索增强方法通过推理时注入仓库上下文缓解此问题,但低推理延迟预算影响了检索质量或引入可感知延迟。我们提出SpecAgent,通过在索引阶段异步预探索文件,构建预测未来编辑的推测性上下文,实现高质量上下文计算且隐藏延迟。其推测性机制提升了代码生成质量。此外,我们发现现有基准存在未来上下文泄露问题,导致性能虚高。为此,我们构建了一个无泄露的合成基准,支持更真实的评估。实验表明,SpecAgent在多个基准上绝对提升9-11%(相对提升48-58%),同时显著降低推理延迟。
原文摘要 · Abstract (English)
Large Language Models (LLMs) excel at code-related tasks but often struggle in realistic software repositories, where project-specific APIs and cross-file dependencies are crucial. Retrieval-augmented methods mitigate this by injecting repository context at inference time. The low inference-time latency budget affects either retrieval quality or the added latency adversely impacts user experience. We address this limitation with SpecAgent, an agent that improves both latency and code-generation quality by proactively exploring repository files during indexing and constructing speculative context that anticipates future edits in each file. This indexing-time asynchrony allows thorough context computation, masking latency, and the speculative nature of the context improves code-generation quality. Additionally, we identify the problem of future context leakage in existing benchmarks, which can inflate reported performance. To address this, we construct a synthetic, leakage-free benchmark that enables a more realistic evaluation of our agent against baselines. Experiments show that SpecAgent consistently achieves absolute gains of 9-11% (48-58% relative) compared to the best-performing baselines, while significantly reducing inference latency.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。