LLM See, LLM Do: Enhancing Repository-Aware Code Generation in LLMs Through Logical Context and Usage Knowledge
Large language models (LLMs) have significantly advanced automatic code generation. Although they have demonstrated remarkable ability in writing standalone code, they still struggle with real-world repository-level coding tasks due to the lack of repository-specific knowledge. Existing studies typically employ retrieval-augmented generation (RAG) approaches to retrieve relevant context to guide LLMs’ generation. However, these approaches fail to ensure the logical relevance and the usability of retrieved results, leading to suboptimal code generation. To address this problem, we propose LogiCoder , a novel RAG approach that leverages logical relationships within code repositories to retrieve usage knowledge for LLMs. Specifically, LogiCoder first builds a dependency graph to identify candidate callee functions. By tracing their call relationships, LogiCoder retrieves their usage examples from the entire repository. Then it integrates the most contextually similar ones with semantic search results via re-ranking. These top-ranked examples are eventually incorporated into LLMs’ prompts to enhance their repository awareness during code generation. We apply LogiCoder to five widely-used LLMs and evaluate it on the DevEval benchmark. Experimental results show that on challenging tasks that require cross-file calls, LogiCoder achieves a new state-of-the-art Pass@1 of 44.58%, with relative improvements of up to 27.26% in Pass@1 and 14.71% in Recall@1 over existing baselines. Ablation studies confirm the effectiveness of each component in LogiCoder .
Authors
- Youren Chen (ORCID: https://orcid.org/0009-0007-0315-9681)
- Tanghaoran Zhang (ORCID: https://orcid.org/0000-0001-7241-9730)
- Yuxin Zhao (ORCID: https://orcid.org/0000-0003-1921-4714)
- Xinjun Mao (ORCID: https://orcid.org/0000-0001-6003-5748)
- Zhang Zhang (ORCID: https://orcid.org/0000-0002-9914-026X)
- Yao Lu (ORCID: https://orcid.org/0000-0002-3520-5829)
- Yue Yu (ORCID: https://orcid.org/0000-0002-9865-2212)
- Kang Yang (ORCID: https://orcid.org/0000-0003-2313-7141)
Institutions
- National University of Defense Technology (CN)
- Peng Cheng Laboratory (CN)
Publication Details
- Journal
- ACM Transactions on Software Engineering and Methodology
- Published
- 2026-10-03
- DOI
- https://doi.org/10.1145/3849809
- Primary Topic
- Software Engineering Research
- Type
- article
- Field-Weighted Citation Impact
- 0.00