LLavaCode: Compressed Code Representations for Retrieval-Augmented Code Generation
Daria Cherniuk, Nikita Sukhorukov, Nikita Sushko, Daniil Gusak, Danil Sivtsov, Elena Tutubalina, Evgeny Frolov
TL;DR
The paper tackles latency bottlenecks in retrieval-augmented code generation for interactive IDEs by compressing retrieved code into compact, semantically meaningful embeddings using a LLaVA-like projection. It introduces LlavaCode, a single-stage framework where only a lightweight projector is trained to map encoder embeddings into the code-LLM embedding space, with a composite loss that combines cross-entropy, REINFORCE-based sequence rewards (EM and ES), and a cosine-alignment term to prevent representation collapse, while keeping the encoder and reader LLM frozen. Empirical results on the Python subset of The Stack show 20-38% reductions in TTFT and improvements in EM/ES over baselines with negligible latency increases, and ablations demonstrate the benefit of the combined loss and the detrimental effect of KL-loss in this setting. The work also explores code modalities like ASTs and encoder choices, and discusses deployment scenarios (disaggregated vs colocated) and future directions, including RL variants and language expansion.
Abstract
Retrieval-augmented generation has emerged as one of the most effective approaches for code completion, particularly when context from a surrounding repository is essential. However, incorporating context significantly extends sequence length, leading to slower inference - a critical limitation for interactive settings such as IDEs. In this work, we introduce LlavaCode, a framework that compresses code into compact, semantically rich representations interpretable by code LLM, enhancing generation quality while reducing the retrieved context to only a few compressed single-token vectors. Using a small projector module we can significantly increase the EM and ES metrics of coding model with negligible latency increase. Our experiments demonstrate that compressed context enables 20-38% reduction in Time-to-First-Token (TTFT) on line completion tasks compared to full-RAG pipelines.
