TL;DR
CoRoVA introduces a novel context compression framework for retrieval-augmented code completion that replaces bulky text prompts with a few continuous vector tokens. By training a lightweight projector with a specialized composite loss, it slashes Time-to-First-Token (TTFT) latency by 20-38% while preserving the high-quality generation benefits of repository-level context.
What Problem Does This Paper Address?
Large Language Models (LLMs) excel at code completion when provided with repository-level context, such as functions, classes, or types defined in entirely different files. Retrieval-Augmented Generation (RAG) is typically used to fetch these relevant code snippets and append them to the prompt.
However, this creates a massive bottleneck: long text prompts drastically increase the "prefill" computation time, leading to high Time-to-First-Token (TTFT) latency. In interactive environments like modern IDEs (e.g., VS Code, Cursor), even a small millisecond delay breaks the developer's flow, making vanilla RAG impractical for real-time suggestions.
Methods
CoRoVA (Compressed Representations for Vector-Augmented Code Completion) shifts the heavy lifting of context processing offline. During repository indexing, it uses a frozen pretrained encoder (such as Qwen3-Embedding or UniXCoder) to compress each retrieved code snippet into a single dense vector.
At inference time, a lightweight Multi-Layer Perceptron (MLP) projector maps these dense vectors directly into the token embedding space of a frozen reader LLM (e.g., Qwen2.5-Coder). This turns hundreds of text tokens into just a few continuous "virtual" tokens (e.g., 10 tokens for 10 retrieved chunks), drastically shortening the prompt.
To train this projector effectively without fine-tuning the underlying LLM, the authors introduce a single-stage pipeline optimized by a three-part composite loss function:
- Cross-Entropy Loss: Standard next-token prediction to maintain basic language fluency.
- RL-based Loss (SCST): Uses Self-Critical Sequence Training to directly optimize sequence-level code metrics (Exact Match and Edit Similarity) using greedy decoding as a baseline.
- Cosine Alignment Loss: A novel regularizer that forces the projector to preserve the pairwise distances and distinctions between different retrieved chunks.
Datasets
- The Stack (Python subset): Used for initial ablation studies and hyperparameter tuning (150k code completion examples).
- The Stack v2 (Python and Java): Used for main evaluations, filtered with strict repository-level constraints (at least 10 files per repo, minimum 40 lines of code per file) to ensure a rich cross-file context environment.
- Benchmarks: Evaluated on established code completion benchmarks including CCEvalLong, RepoEval, and RepoEvalApi.
Key Insights and Ideas
- Token-level vs. Sequence-level Mismatch: Standard cross-entropy loss optimizes for the very next token, which doesn't correlate well with whether a full line of generated code is functionally correct. Incorporating reinforcement learning (SCST) bridges this gap by directly rewarding sequence-level metrics like Edit Similarity.
- Dimensional Collapse: The authors discovered that without explicit regularization, the MLP projector quickly learns to map all code embeddings into an almost identical, flat subspace where the LLM can no longer tell the retrieved chunks apart. The Cosine Alignment loss acts as a vital fix to keep representations distinct.
- Text RAG vs. Code RAG Divergence: Techniques that work well for natural language context compression (like the KL-divergence distillation used in frameworks like xRAG) actually degrade performance when applied to code completion tasks.
Key Results
- Massive Latency Savings: CoRoVA achieves a 20-38% reduction in TTFT across various model sizes (1.5B to 14B parameters) compared to uncompressed vanilla RAG.
- Extreme Prompt Shrinkage: It shrinks the input prompt by 502 tokens by compressing 512 tokens of raw text context down to just 10 continuous vector tokens.
- Maintained Quality: CoRoVA significantly outperforms no-context baselines and beats token-space compression methods (like token pruning or LLM-based summarization), capturing the lion's share of vanilla RAG's quality gains with virtually zero online latency overhead.
Limitations and Future Work
- RL Compute Intensity: The current RL training relies on computationally efficient SCST. The authors suggest exploring more advanced but compute-heavy alignment algorithms like Group Relative Policy Optimization (GRPO) to further boost alignment with developer metrics.
- Structural Encoders: While they tested abstract syntax tree (AST) representations via UniXCoder, general code embeddings performed better. They note that future work should revisit structural/graph-based signals as more powerful graph encoders emerge.
Summary updated