arXiv:2603.06593cs.CLcs.LG2026-03被引 1

用分层向量缓存替代长代码片段,实现低延迟代码补全。

Hierarchical Embedding Fusion for Retrieval-Augmented Code Generation

  • 离线构建代码库的分层向量索引,线上用少量伪令牌调用。
  • 在RepoBench上达到与片段检索相当的准确率,单卡延迟低于1秒。
  • 适合追求高速度、高可扩展性的代码生成系统开发者。

检索增强型代码生成常依赖大量检索到的代码片段作为解码器输入,导致在线推理成本随代码库规模增长,并引入长上下文噪声。本文提出分层嵌入融合(HEF),一种两阶段代码库表征方法:首先,离线使用小型融合模型将代码库块压缩为可复用的密集向量层级;其次,线上接口将少量检索到的向量映射为学习得到的伪令牌,供代码生成器使用。该方法将数千个检索令牌替换为固定数量的伪令牌,同时保留对代码库级信息的访问能力。在RepoBench和RepoEval数据集上,采用18亿参数流水线的HEF实现了与基于片段检索基线相当的精确匹配准确率,且在单张A100 GPU上中位延迟低于1秒。相比实验中的图结构与迭代检索系统,HEF将中位端到端延迟降低13至26倍。此外,我们引入了效用加权似然信号用于训练上下文过滤,并报告了伪令牌预算、嵌入模型及对有害检索鲁棒性的消融研究。总体表明,分层稠密缓存是实现低延迟、仓库感知代码补全的有效机制。

原文摘要 · Abstract (English)

Retrieval-augmented code generation often conditions the decoder on large retrieved code snippets. This ties online inference cost to repository size and introduces noise from long contexts. We present Hierarchical Embedding Fusion (HEF), a two-stage approach to repository representation for code completion. First, an offline cache compresses repository chunks into a reusable hierarchy of dense vectors using a small fuser model. Second, an online interface maps a small number of retrieved vectors into learned pseudo-tokens that are consumed by the code generator. This replaces thousands of retrieved tokens with a fixed pseudo-token budget while preserving access to repository-level information. On RepoBench and RepoEval, HEF with a 1.8B-parameter pipeline achieves exact-match accuracy comparable to snippet-based retrieval baselines, while operating at sub-second median latency on a single A100 GPU. Compared to graph-based and iterative retrieval systems in our experimental setup, HEF reduces median end-to-end latency by 13 to 26 times. We also introduce a utility-weighted likelihood signal for filtering training contexts and report ablation studies on pseudo-token budget, embedding models, and robustness to harmful retrieval. Overall, these results indicate that hierarchical dense caching is an effective mechanism for low-latency, repository-aware code completion.

代码生成检索增强向量缓存低延迟

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