Abstract
Bojian Xiong, Yikun Lei, Xikai Liu, Shaowei Zhang, Pengyun Zhu, Yan Liu, Yongqi Leng, Ling Shi, Meizhi Zhong, Yurong Zhang, Yan Gao, Yiwu, Yao Hu, Deyi Xiong. Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing: Industry Track.
2025.
Introduction
Large Language Models (LLMs) have demonstrated exceptional capabilities in generating isolated code snippets. However, applying these models to repository-level code repair—where bugs are often buried within massive, multi-file software projects—remains a significant challenge. The primary obstacles are "context bloat," where irrelevant code obscures the bug, and the complex inter-dependencies between files that require deep semantic understanding.
To address these issues, researchers from Tianjin University and Xiaohongshu Inc. have introduced Think-Search-Patch (TSP). TSP is a retrieval-augmented reasoning framework designed to navigate repository complexities by decomposing the repair process into three distinct stages: reasoning, fine-grained retrieval, and standardized patching.
The TSP Framework
The TSP framework moves away from monolithic code generation in favor of a structured, sequential pipeline. This approach ensures that the model maintains a clear reasoning path from the initial bug report to the final code fix.
- Think Stage: The model begins by analyzing the issue description. Rather than immediately searching for code, it performs a semantic analysis to decompose the problem into sub-tasks and constructs a precise search query. This "reasoning-first" approach ensures that the subsequent retrieval is targeted and relevant.
- Search Stage: Using the queries from the Think stage, the system retrieves relevant code snippets. A key innovation here is the use of fine-grained indexing. By utilizing an Abstract Syntax Tree (AST), TSP indexes code at the class and function levels rather than the file level. This reduces the average recalled context length by approximately 78%, effectively filtering out the "noise" of irrelevant boilerplate code.
- Patch Stage: In the final stage, the model uses the retrieved context to localize the flaw and generate a standardized patch in a diff format.
Specialized Training Strategy
The effectiveness of TSP is driven by a two-stage training process designed to optimize the model's collaborative reasoning:
- Supervised Fine-Tuning (SFT): The researchers developed a custom 60,000-sample dataset (the TSP Dataset) to train models to follow the three-stage workflow. This dataset was built by augmenting existing code-repair data with explicit search modules.
- Direct Preference Optimization (DPO): To minimize errors in intermediate reasoning (such as ineffective search queries), the team employed GPT-4o as a judge to identify and correct successful reasoning paths. DPO was then used to train the model to prefer these successful paths, enhancing the reliability of the entire pipeline.
Experimental Results
The TSP framework was evaluated on SWE-bench Lite, a benchmark consisting of 300 real-world GitHub issues. The results demonstrate that TSP significantly outperforms traditional Retrieval-Augmented Generation (RAG) methods.
Key performance metrics include:
- Superior Pass Rates: The TSP-Qwen2.5-Coder-14B model achieved an 8.33% pass rate, a substantial improvement over GPT-4 (1106) using standard RAG (2.67%).
- Search Accuracy: TSP-trained models showed a dramatic increase in retrieval precision. The 14B model reached a search accuracy of 64.8%, compared to 28.7% for its base version.
- Token Efficiency: By focusing on class and function-level snippets, the TSP framework consumed significantly fewer tokens than file-level RAG (3724.56 vs. 16933.77 tokens on average), making it both faster and more cost-effective.
Conclusion and Future Work
Think-Search-Patch represents a significant step forward in repository-level code repair by combining fine-grained retrieval with structured reasoning. While it currently follows a linear pipeline, the authors suggest that future iterations could incorporate "agentic" behaviors, such as dynamic decision-making and iterative search loops, to further bridge the gap between automated tools and human developers. Currently, TSP provides a robust, efficient, and highly accurate framework for maintaining complex software repositories.
Summary updated