arXiv cs.CL· Xiaohan Chen, Xiang Chen, Yu Tian, Piji Li, Sheng-Jun Huang, Songcan Chen·· 2 天前AI 评分22
SaraCoder:面向检索增强仓库级代码补全的分层上下文剪枝提升知识密度
Enhancing Knowledge Density via Hierarchical Context Pruning for Retrieval-Augmented Repository-Level Code Completion
AI 导读
SaraCoder 是一个在固定上下文预算下通过分层上下文剪枝提升知识密度的检索增强框架,其 Hierarchical Feature Optimization 模块分四阶段剪枝过完备候选池,再将释放的 token 分配给 External-Aware Identifier Disambiguator,选择性注入最必要的跨文件依赖定义。
正文 · 原文
Abstract:Retrieval-Augmented Generation (RAG) has advanced repository-level code completion by retrieving external code snippets, API documentation, or type definitions to expand the model's contextual awareness. However, under the finite token budget of the context window, existing retrieval-augmented methods often saturate the budget with highly similar or even redundant code, which not only wastes tokens but also suppresses critical cross-file dependencies, preventing synergistic interaction between semantically similar reference snippets and cross-file dependency definitions. Therefore, further gains are limited by low knowledge density in the retrieved context rather than by model capacity. We propose SaraCoder, a retrieval-augmented framework that enhances knowledge density via hierarchical context pruning under a fixed context budget. A Hierarchical Feature Optimization module prunes an over-complete candidate pool in four stages. The freed tokens are then allocated to an External-Aware Identifier Disambiguator, which selectively injects only the most necessary cross-file dependency definitions. SaraCoder transforms context construction into a budget-aware optimization problem, balancing reference snippets and cross-file dependencies to build a context that is both knowledge-dense and semantically complete. Experiments on CrossCodeEval and RepoEval-Updated, across multiple backbone code LLMs, show that SaraCoder consistently outperforms strong RAG baselines such as GraphCoder and Repocoder in both code-level and identifier-level metrics, without increasing token usage, and yields synergistic gains when combined with other cross-file methods.
| Subjects: | Software Engineering (cs.SE); Computation and Language (cs.CL); Information Retrieval (cs.IR); Programming Languages (cs.PL) |
| Cite as: | arXiv:2508.10068 [cs.SE] |
| (or arXiv:2508.10068v3 [cs.SE] for this version) | |
| https://doi.org/10.48550/arXiv.2508.10068 arXiv-issued DOI via DataCite |
Submission history
From: Xiaohan Chen [view email]
[v1]
Wed, 13 Aug 2025 11:56:05 UTC (1,412 KB)
[v2]
Mon, 13 Oct 2025 07:16:49 UTC (1,621 KB)
[v3]
Thu, 15 Oct 2026 14:15:15 UTC (2,803 KB)
来源:arXiv cs.CL · arxiv.org