Abstract
Repository-level code completion requires integrating cross-file context, yet faces a "Context-Latency Conundrum": increasing context for accuracy often degrades inference speed. We present REPOFUSE, a framework that fuses two distinct context types—Analogy Context (similar functional logic) and Rationale Context (semantic architectural definitions)—to optimize prompts. By employing Rank Truncated Generation (RTG), REPOFUSE achieves up to a 60% improvement in Exact Match accuracy while reducing inference latency by nearly 27%.
Introduction
Modern Large Language Models (LLMs) excel at local code completion but struggle with repository-level tasks where dependencies reside in external files. While Retrieval-Augmented Generation (RAG) can provide this cross-file context, it introduces a significant trade-off. Developers typically require completion results within 200 milliseconds, but long, context-heavy prompts significantly slow down model inference. This "Context-Latency Conundrum" necessitates a more surgical approach to prompt construction.
Methodology: The REPOFUSE Framework
REPOFUSE addresses the efficiency challenge by prioritizing the quality of context over quantity. It utilizes a "Dual Context" strategy:
- Analogy Context (AC): This component retrieves code snippets from the repository that exhibit similar functional patterns to the current task. It provides the model with examples of how similar logic has been implemented elsewhere.
- Rationale Context (RC): This provides the "vocabulary" of the codebase, including class taxonomies, method signatures, and API definitions. It is powered by a specialized Code Knowledge Graph that maps interdependencies.
To manage prompt length, REPOFUSE introduces Rank Truncated Generation (RTG). RTG ranks retrieved information based on relevance scores (semantic or lexical) and selects only the top-tier items to fit within a predefined token budget. This ensures that the most critical information is preserved even in highly constrained windows.
Experimental Evaluation
The framework was evaluated using the CrossCodeEval benchmark, focusing on Python across 471 repositories. Testing spanned multiple Code LMs, including StarCoder, DeepSeek-Coder, and CodeLlama (1B to 7B parameters).
Key Results
The primary finding is the synergistic effect of combining AC and RC. While AC provides the logic, RC provides the necessary structural definitions. Together, they allow the model to resolve complex completions that single-context methods fail to address.
Quantitative highlights include:
- Accuracy Boost: An Exact Match (EM) improvement of 40.90% to 59.75% over single-context baselines.
- Efficiency: A 26.8% reduction in inference latency. Notably, REPOFUSE with a 512-token window outperformed single-context methods using 4096 tokens, demonstrating that high-quality, truncated context is superior to exhaustive, noisy prompts.
- Resource Efficiency: The system achieved superior accuracy while utilizing only 75.4% of the context length typically required by other state-of-the-art methods.
Discussion and Future Work
The success of REPOFUSE at small truncation sizes proves that effective repository-level completion depends on precise context selection. However, limitations remain. The current analyzer may include redundant program constructs, suggesting a need for more lightweight pruning. Additionally, the current implementation focuses on prefix-based completion; integrating "Fill-in-the-Middle" (FIM) techniques to account for code suffixes could further enhance precision. Future research will also explore the scalability of this approach with models exceeding 7B parameters.
Conclusion
REPOFUSE effectively resolves the Context-Latency Conundrum by fusing functional analogies with semantic rationales. By delivering higher accuracy with shorter prompts, it provides a viable path for deploying sophisticated repository-level completion in latency-sensitive production environments.
Summary updated