AI & Software Engineering
Researchers Propose Treating Code Structurally, Not Linguistically, to Boost Multi-File AI Code Generation
A new framework called Hydra outperforms existing methods by mapping code repositories as structured hierarchies instead of applying natural-language retrieval strategies.
Large language models have become adept at completing isolated code snippets, yet they struggle when tasked with generating functions that depend on other files, classes, and variables scattered throughout a repository. The problem, according to researchers submitting work to arXiv, stems from treating code like prose rather than structured programs.
The Core Problem with Current Methods#
Existing retrieval-augmented generation (RAG) systems borrow techniques from natural language processing, breaking repositories into chunks and ranking results by similarity. This approach creates two critical blind spots: chunking fragments code logic, destroying connections between related units, and similarity-based matching misses true dependencies such as imported functions or inherited classes that a new function actually needs to work. When a CodeLLM asks "what context should I use?" it often gets usage examples that look similar—but are functionally irrelevant.
Hydra's Three-Part Solution#
Researchers introduced Hydra, a framework that recognizes code as a structured system. The approach rests on three pillars:
- Structure-aware indexing: Code repositories are mapped as hierarchical trees of functions, classes, and variables, preserving the actual relationships between components.
- Dependency-aware retriever (DAR): Rather than guessing which code is "relevant," the system explicitly traces which functions, variables, and classes a target function truly requires.
- Hybrid retrieval: DAR's precise dependencies combine with similarity-based methods to furnish both essential building blocks and practical usage patterns.
Benchmark Results#
Testing on DevEval and RepoExec—two demanding benchmarks requiring implementation of real-world functions with complex repository context—Hydra achieved new state-of-the-art scores. The gains exceed 5% on Pass@1 (the rate of generating working code on the first attempt), and the framework enables smaller models to reach the performance of much larger language models using conventional retrieval methods.
The finding has broader implications: treating code as code, not language, may be key to scaling AI-assisted development beyond single-file tasks.