CatCoder: Repository-Level Code Generation with Relevant Code and Type Context

Quick Overview

CatCoder successfully addresses repository-level code generation by fusing relevant code snippets with type context, achieving a 17.35% pass rate on Java unit tests compared to RepoCoder's 3.45% pass rate, demonstrating that providing structurally and contextually rich input significantly outperforms relying solely on retrieval or general context.

Key Points: CatCoder achieved a 17.35% success rate on Java unit tests, significantly outperforming RepoCoder's 3.45% success rate on the same tests. The core technique involves fusing relevant code snippets (retrieval) with type context (structural information) into a single, highly contextualized prompt. When code retrieval was removed, the performance of the method dropped significantly, indicating the necessity of both retrieval and type context. The experiment included both Java and Rust codebases, showing that the structured context approach improved performance across different languages. For Java, the improvement was substantial (17.35% vs 3.45%), while for Rust, the improvement was less dramatic but still present, suggesting language-specific benefits. The method relies on building a 'blueprint' or 'contract' of the code structure and then feeding this context to the LLM to generate code that correctly interacts with existing structures. The time taken for the CatCoder approach was around 1.5 seconds per prompt, fast enough for interactive use.

Context: The video discusses CatCoder, a novel framework designed to improve Large Language Model (LLM) code generation, specifically for tasks requiring context across an entire repository rather than just isolated snippets. The central challenge addressed is providing the LLM with enough structural and contextual information so that the generated code integrates seamlessly into the existing codebase, avoiding fundamental logic errors or reliance on non-existent helper functions or types.

Detailed Analysis

CatCoder significantly improves repository-level code generation by fusing two critical types of information: relevant code snippets retrieved from the repository (retrieval context) and deep structural context derived from the code's blueprint and type system. The primary finding is that this fusion yields massive performance gains, evidenced by CatCoder achieving a 17.35% pass rate on Java unit tests, compared to RepoCoder's 3.45% rate, which relied only on retrieval. The researchers found that removing the type context alone caused performance to plummet, confirming that the structural blueprint is crucial for generating code that correctly interacts with existing classes, interfaces, and methods. The process involves three steps: relevant code retrieval, type context extraction (using specialized static analyzers for languages like Java and Rust), and finally, fusing these two contexts into one highly informed prompt for the LLM. This approach allows smaller models to perform significantly better, even outperforming larger models on specific benchmarks, because the context explicitly defines the necessary structure and relationships, preventing the LLM from making fundamental logical errors or guessing required types.

Raw markdown version of this recap