LLM See, LLM Do: Enhancing Repository-Aware Code Generation in LLMs Through Logical Context and Usage Knowledge
Open Access
- 3 October 2026
- journal article
- Published by Association for Computing Machinery (ACM) in ACM Transactions on Software Engineering and Methodology
Abstract
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 .Keywords
This publication has 42 references indexed in Scilit:
- BLAZE: Cross-Language and Cross-Project Bug Localization via Dynamic Chunking and Hard Example LearningIEEE Transactions on Software Engineering, 2025
- Instruct or Interact? Exploring and Eliciting LLMs' Capability in Code Snippet Adaptation Through Prompt Engineering2025
- A3-CodGen: A Repository-Level Code Generation Framework for Code Reuse With Local-Aware, Global-Aware, and Third-Party-Library-AwareIEEE Transactions on Software Engineering, 2024
- RetypeR: Integrated Retrieval-based Automatic Program Repair for Python Type Errors2024
- What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs?2023
- FACER: An API usage-based code-example recommender for opportunistic reuseEmpirical Software Engineering, 2021
- Leveraging usage similarity for effective retrieval of examples in code repositories2010
- Reciprocal rank fusion outperforms condorcet and individual rank learning methods2009
- Coefficient of Variation1998
- THE DISTRIBUTION OF THE FLORA IN THE ALPINE ZONE.1New Phytologist, 1912