This paper proposes a method for acquiring external knowledge and up-to-date information to improve the efficiency of inference and text generation of large-scale language models (LLMs). To overcome the limitations of the existing search engine, we introduce the Search-R1 framework based on reinforcement learning (RL). In Search-R1, the LLM autonomously generates multiple search queries during the step-by-step inference process and optimizes the inference process by utilizing the search results. It performs stable RL learning by using the token masking technique and a simple result-based reward function. Experimental results on seven question-answering datasets show that Search-R1 improves the performance by 41% in the Qwen2.5-7B model and 20% in the Qwen2.5-3B model compared to the existing RAG technique. In addition, we present experimental analysis results on the RL optimization method, LLM selection, and search result length dynamics. The code and model checkpoints are open to the public on GitHub.