Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in generating standalone code snippets, navigating the complexities of full-scale production repositories remains a significant challenge. Developers often describe large codebases as a "jungle" where logical dependencies, inheritance patterns, and cross-file imports create a dense web of information. Current solutions generally fall into two categories: similarity-based Retrieval-Augmented Generation (RAG), which treats code as unstructured text chunks, and task-specific tools that are rigid and difficult to maintain.
CodexGraph addresses these limitations by providing a structured, graph-based interface for LLMs. By representing a codebase as a queryable graph database, CodexGraph enables models to perform precise, structure-aware navigation, mimicking the way human developers explore code using an Integrated Development Environment (IDE).
The CodexGraph Framework
1. Graph Construction and Schema
CodexGraph utilizes static analysis to index a repository into a graph database (e.g., Neo4j). This process occurs in two distinct phases. First, Shallow Indexing identifies primary symbols such as Modules, Classes, and Functions, capturing their metadata and signatures. Second, Edge Completion uses Abstract Syntax Trees (AST) to map logical relationships between these symbols.
The resulting schema includes relationship types such as CONTAINS, INHERITS, USES, and HAS_METHOD. This structured representation allows the system to handle complex scenarios like multi-inheritance and cross-file dependencies that typically baffle standard text-based retrieval methods.
2. Agentic Workflow: "Write then Translate"
To interact with the graph, CodexGraph employs a specialized agentic pipeline designed to reduce the reasoning burden on the primary model.
- Primary LM Agent: Analyzes the user's high-level request (e.g., a bug report or a feature request) and formulates a Natural Language Query (NLQ).
- Translation LM Agent: Converts the NLQ into a precise Cypher query. This division of labor ensures high syntactic accuracy and allows the primary agent to focus on high-level problem-solving.
This workflow supports iterative navigation. If the initial query results are insufficient, the agent can issue follow-up queries to explore the graph further, effectively "walking" through the codebase until the necessary context is gathered.
Experimental Evaluation
The authors evaluated CodexGraph across three major benchmarks: CrossCodeEval (cross-file completion), SWE-bench Lite (real-world bug fixing), and EvoCodeBench (repository-level generation).
Key Results
- CrossCodeEval (Lite): Using GPT-4o, CodexGraph achieved an Exact Match (EM) of 27.90%, significantly outperforming the BM25 baseline (21.20%) and the "No RAG" baseline (10.80%).
- SWE-bench Lite: The system resolved 22.96% of issues, matching the performance of AutoCodeRover, a tool specifically engineered for this benchmark. This demonstrates that a general-purpose graph interface can be as effective as specialized, task-specific tools.
- Scaling with Model Capability: The performance gap between top-tier models like GPT-4o and smaller models widened when using CodexGraph, suggesting that more capable models are better at leveraging structured database interfaces.
Discussion and Future Work
Ablation studies highlight that the "edges" (relationships) in the graph are critical; removing them causes performance to drop sharply. This confirms that understanding how code connects is more important for repository-level tasks than simply identifying individual symbols.
Despite its success, CodexGraph faces challenges regarding indexing overhead—building a graph for a massive repository like Scikit-Learn can take several hours. Additionally, the current implementation is focused on Python. Future work will involve extending support to Java and C++, optimizing token consumption from verbose query results, and exploring the integration of dynamic analysis to capture runtime behaviors.
Summary updated