CodexGraph: Bridging Large Language Models and Code Repositories via Code Graph Databases

TL;DR

CodexGraph enhances LLM performance on codebases via code graph databases, significantly improving retrieval accuracy.

cs.SE 🔴 Advanced 2024-08-08 40 views
Xiangyan Liu Bo Lan Zhiyuan Hu Yang Liu Zhicheng Zhang Fei Wang Michael Shieh Wenmeng Zhou
LLM codebase graph database software engineering code retrieval

Key Findings

Methodology

CodexGraph abstracts codebases into graph databases, leveraging graph query language flexibility to enable LLMs to construct and execute queries for precise, structure-aware retrieval and navigation. The system uses static analysis to extract code graphs and stores them using a unified graph database schema.

Key Results

  • On CrossCodeEval, CodexGraph with GPT-4o improves EM by 17.1%.
  • On SWE-bench, achieves Pass@1 of 36.02%, significantly outperforming baselines.
  • In EvoCodeBench, Recall@1 reaches 11.87%, showcasing superior code generation capability.

Significance

CodexGraph holds significant value in both academia and industry. It addresses limitations of existing methods in handling large codebases, enhancing retrieval precision and efficiency, and advancing automated software engineering.

Technical Contribution

CodexGraph introduces code graph databases as flexible, universal interfaces, significantly enhancing LLMs' ability to navigate and understand codebases without expert knowledge, supporting multiple code tasks.

Novelty

CodexGraph is the first to integrate LLMs with graph databases for codebase retrieval and navigation, overcoming limitations of traditional similarity-based retrieval methods.

Limitations

  • Memory issues may arise when handling complex codebase dependencies.
  • Limited support for language-specific code structures.
  • Further optimization of graph database query efficiency is needed.

Future Work

Future work includes expanding to more programming languages, optimizing graph database performance, and developing smarter query generation mechanisms.

AI Executive Summary

Current large language models face significant challenges in handling large codebases, primarily relying on similarity retrieval or manual tools, leading to low recall and poor generality. CodexGraph introduces code graph databases as flexible, universal interfaces, enabling LLMs to efficiently retrieve and navigate codebases. Experiments show CodexGraph excels in multiple benchmarks, notably improving retrieval accuracy and efficiency on CrossCodeEval and SWE-bench. While CodexGraph excels in handling complex code structures, memory usage and query efficiency issues must be addressed to enhance real-world performance.

Deep Analysis

Background

As large language models are increasingly applied to code generation and understanding tasks, effectively handling large codebases has become a critical research topic. Traditional methods mainly rely on similarity retrieval or manual tools, facing low recall and poor generality issues.

Core Problem

Existing methods face low recall when handling large codebases and rely on expert knowledge, making them difficult to adapt to diverse code tasks. This problem limits the advancement of automated software engineering.

Innovation

CodexGraph abstracts codebases into graph databases, leveraging graph query language flexibility to enable LLMs to construct and execute queries for precise, structure-aware retrieval and navigation.

Methodology

  • �� Use static analysis to extract code graphs
  • �� Store using a unified graph database schema
  • �� Leverage graph query language for query construction and execution
  • �� Provide flexible, structure-aware retrieval and navigation

Experiments

CodexGraph is evaluated on CrossCodeEval, SWE-bench, and EvoCodeBench. Advanced LLMs like GPT-4o are used as baselines to compare performance across different methods.

Results

On CrossCodeEval, CodexGraph with GPT-4o improves EM by 17.1%. On SWE-bench, achieves Pass@1 of 36.02%, significantly outperforming baselines. In EvoCodeBench, Recall@1 reaches 11.87%.

Applications

CodexGraph can be applied to code debugging, code comment generation, and unit testing, offering broad application prospects in practical software engineering tasks.

Limitations & Outlook

Memory issues may arise when handling complex codebase dependencies. Limited support for language-specific code structures. Further optimization of graph database query efficiency is needed.

Plain Language Accessible to non-experts

Imagine you're in a massive library searching for books. Traditional methods are like finding books by title or author, but if the title is vague or the author unknown, it's hard to find. CodexGraph is like a super-smart librarian who knows not only every book's name and author but also their content and relationships. So even if you know just a little, it can help you find what you need.

ELI14 Explained like you're 14

Imagine playing a massive multiplayer online game with lots of quests and characters. Traditional methods are like finding quests by character names, but sometimes names aren't clear. CodexGraph is like a super assistant who knows each character's backstory and quest relationships. So even if you know just a little, it helps you find the right quest!

Glossary

Large Language Model (LLM)

A large-scale neural network model capable of processing and generating natural language text.

Used for code generation and understanding tasks.

Codebase

A collection of source code files used in software development.

CodexGraph extracts code graphs from it.

Graph Database

A database designed to store and query graph-structured data.

Used to store code graphs and execute queries.

Static Analysis

A method of analyzing code structure and properties without executing the code.

Used to extract code graphs.

Graph Query Language

A language used to query graph databases, such as Cypher.

Used for query construction and execution.

Open Questions Unanswered questions from this research

  • 1 How to further optimize graph database query efficiency?
  • 2 How to expand to more programming languages?
  • 3 How to address memory usage issues?

Applications

Immediate Applications

Code Debugging

Quickly locate code errors using CodexGraph, improving debugging efficiency.

Long-term Vision

Automated Software Engineering

Achieve more efficient software development processes through smarter code retrieval and generation.

Abstract

Large Language Models (LLMs) excel in stand-alone code tasks like HumanEval and MBPP, but struggle with handling entire code repositories. This challenge has prompted research on enhancing LLM-codebase interaction at a repository scale. Current solutions rely on similarity-based retrieval or manual tools and APIs, each with notable drawbacks. Similarity-based retrieval often has low recall in complex tasks, while manual tools and APIs are typically task-specific and require expert knowledge, reducing their generalizability across diverse code tasks and real-world applications. To mitigate these limitations, we introduce CodexGraph, a system that integrates LLM agents with graph database interfaces extracted from code repositories. By leveraging the structural properties of graph databases and the flexibility of the graph query language, CodexGraph enables the LLM agent to construct and execute queries, allowing for precise, code structure-aware context retrieval and code navigation. We assess CodexGraph using three benchmarks: CrossCodeEval, SWE-bench, and EvoCodeBench. Additionally, we develop five real-world coding applications. With a unified graph database schema, CodexGraph demonstrates competitive performance and potential in both academic and real-world environments, showcasing its versatility and efficacy in software engineering. Our application demo: https://github.com/modelscope/modelscope-agent/tree/master/apps/codexgraph_agent.

cs.SE cs.AI cs.CL