arXiv:2510.08850cs.SEcs.AI2025-10

用微调大模型直接从自然语言问句中精准定位代码文件路径。

Repository-Aware File Path Retrieval via Fine-Tuned LLMs

  • 用AST和仓库内容生成带文件路径的答案,训练模型理解代码上下文。
  • 在PyTorch等项目上达到91%精确匹配,59%召回率,跨文件定位能力强。
  • 适合开发工具、AI编程助手构建者,提升代码搜索准确性。

现代代码库中,开发者和AI编程助手常难以回答‘这个功能如何工作?’或‘缺陷在哪引入?’等问题。传统关键词或信息检索方法忽略语义和跨文件关联,而大模型虽懂自然语言却缺乏项目特定细节。本文提出一种文件路径检索方法:通过QLoRA与Unsloth优化,对Qwen3-8B模型进行微调,直接根据自然语言查询预测相关文件路径。为构建训练数据,提出六种代码感知策略,利用抽象语法树(AST)结构和仓库内容生成真实问答对,答案为文件路径集合,涵盖单文件到层级仓库摘要。在Flask、Click、Jinja、FastAPI和PyTorch等Python项目上微调,测试集上最高达91%精确匹配和93%召回率,显著优于单一策略训练。在包含约4000个Python文件的PyTorch仓库中仍实现59%召回率,显示良好可扩展性。分析表明多层次代码信号有助于模型推理跨文件上下文,讨论了数据集设计、上下文长度限制及未来与代码智能系统集成的可能性。

原文摘要 · Abstract (English)

Modern codebases make it hard for developers and AI coding assistants to find the right source files when answering questions like "How does this feature work?" or "Where was the bug introduced?" Traditional code search (keyword or IR based) often misses semantic context and cross file links, while large language models (LLMs) understand natural language but lack repository specific detail. We present a method for file path retrieval that fine tunes a strong LLM (Qwen3-8B) with QLoRA and Unsloth optimizations to predict relevant file paths directly from a natural language query. To build training data, we introduce six code aware strategies that use abstract syntax tree (AST) structure and repository content to generate realistic question-answer pairs, where answers are sets of file paths. The strategies range from single file prompts to hierarchical repository summaries, providing broad coverage. We fine tune on Python projects including Flask, Click, Jinja, FastAPI, and PyTorch, and obtain high retrieval accuracy: up to 91\% exact match and 93\% recall on held out queries, clearly beating single strategy training. On a large codebase like PyTorch (about 4,000 Python files), the model reaches 59\% recall, showing scalability. We analyze how multi level code signals help the LLM reason over cross file context and discuss dataset design, limits (for example, context length in very large repos), and future integration of retrieval with LLM based code intelligence.

代码搜索大模型路径预测微调

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。