AI
New System Optimizes Code Completion by Trimming Redundant Context, Preserving Cross-File Dependencies
A retrieval-augmented framework called SaraCoder uses hierarchical pruning to maximize the quality of context fed to AI code models without increasing token usage.
Retrieval-augmented generation (RAG) has proven valuable for repository-level code completion, allowing models to pull in external code snippets, documentation, and type definitions to enhance their understanding of surrounding context. Yet a fundamental bottleneck persists: language models operate within finite token budgets, and traditional retrieval methods often fill that budget with overlapping or redundant material—wasting capacity that could go toward dependencies critical for understanding how different code modules interact.
The Problem with Current Approaches#
Existing RAG-based code completion systems struggle with a basic efficiency problem. When retrieving reference code, these systems tend to fetch many similar fragments, consuming tokens without adding meaningful information. At the same time, they may neglect cross-file dependencies—definitions or identifiers that exist in other parts of a repository and are essential for proper code context. This mismatch leaves models with what researchers call "low knowledge density": abundant tokens devoted to redundant material, while genuinely useful semantic connections remain underrepresented.
How SaraCoder Reframes the Problem#
Researchers have proposed SaraCoder, a retrieval-augmented framework that treats context construction as an optimization challenge under a fixed token budget. The system operates through two main components:
- Hierarchical Feature Optimization module: Progressively prunes an over-complete candidate pool across four stages, removing redundant code snippets to free up tokens
- External-Aware Identifier Disambiguator: Strategically injects only the most critical cross-file dependency definitions into the freed space
This two-stage approach transforms the architecture into a budget-aware balancing act, weighing reference snippets against cross-file dependencies to build a denser, more semantically complete context.
Results Across Multiple Benchmarks#
Tests on CrossCodeEval and RepoEval-Updated, using various backbone code language models, demonstrate that SaraCoder consistently outperforms comparable systems such as GraphCoder and Repocoder in both code-level and identifier-level metrics. Notably, these improvements come without any increase in total token consumption. The framework also compounds gains when combined with other cross-file dependency methods, suggesting its improvements are complementary rather than redundant.

