LibRec: Benchmarking Retrieval-Augmented LLMs for Library Migration Recommendations

Junxiao Han, Yarong Wang, Xiaodong Gu, Cuiyun Gao, Yao Wan, Song Han, David Lo, Shuiguang DengarXiv 2025 · DOI

Introduction

Modern software development relies heavily on third-party libraries. However, these dependencies often evolve into "technical debt" when they become unmaintained, suffer from security vulnerabilities, or are superseded by more efficient alternatives. The process of replacing a "source" library with a "target" library—known as library migration—is currently a labor-intensive manual task. Developers must research alternatives, compare features, and ensure compatibility. While rule-based automation exists, it lacks the flexibility to handle unseen libraries or specific developer intents.

The LibRec Framework

To address these challenges, the authors introduce LibRec, a three-stage framework designed to automate library migration recommendations using Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG).

Overview of the LibRec framework and the LibEval benchmark construction process.

The framework operates as follows:

  1. Intent Generation: Using GPT-4o, the system analyzes commit messages to extract the underlying "migration intent." This goes beyond simple replacement by identifying why a migration occurred (e.g., performance gains or security fixes).
  2. RAG Database Construction: A searchable database of historical migrations is built. LibRec employs the BM25 algorithm to retrieve relevant past migrations, providing the LLM with "in-context" examples.
  3. Target Recommendation: The LLM receives a prompt containing the source library, the developer's intent, and retrieved historical context to generate a ranked list of the top 10 recommended target libraries.

LibEval: A Large-Scale Benchmark

Alongside the framework, the authors present LibEval, a specialized benchmark comprising nearly 3,000 real-world Python library migrations sourced from 2,324 GitHub repositories. Each record includes the source-target pair and the extracted migration intent.

Distribution of migration intents across source library issues, target library advantages, and project-specific reasons.

The dataset reveals that migrations are driven by various factors. As shown in the intent distribution, "Not Maintained/Outdated" is a primary issue for source libraries (68%), while "Enhanced Features" (46%) and "Integration" (67%) are major drivers for choosing target libraries and project-specific reasons, respectively.

Key Results and Insights

The evaluation of 10 different LLMs revealed several critical findings:

  • Claude-3.7-Sonnet Leads: This model outperformed all others, achieving a Precision@1 of 56.6% and a Precision@10 of 79.2%.
  • The Importance of Context: Ablation studies showed that removing the RAG component or migration intents led to performance drops of 8.7% and 13.8% in Precision@1, respectively. This underscores that understanding the "why" (intent) and "how others did it" (history) is vital.
  • Prompting Strategies: One-shot prompting emerged as the most robust strategy, providing a better balance of reliability and performance than zero-shot or complex Chain-of-Thought (CoT) methods for this specific task.
  • Challenges in Feature Enhancement: While LLMs excel at identifying migrations for clear issues like security, they struggle more with "Enhanced Features," where the functional differences are more subtle.

Conclusion

LibRec demonstrates the potential of RAG-enhanced LLMs to streamline the library migration process. By focusing on developer intent and historical context, the framework provides highly accurate recommendations. Future work aims to expand this approach to other programming languages and move from recommending libraries to automatically generating the necessary migration code.

Summary updated

BibTeX
@misc{han2025librec,
  author = {Junxiao Han and Yarong Wang and Xiaodong Gu and Cuiyun Gao and Yao Wan and Song Han and David Lo and Shuiguang Deng},
  title = {{LibRec: Benchmarking Retrieval-Augmented LLMs for Library Migration Recommendations}},
  year = {2025},
  eprint = {2508.09791},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.09791},
}
Figure