SmartRAG: Jointly Learn RAG-Related Tasks From the Environment Feedback

## Abstract

Abstract RAG systems consist of multiple modules to work together. However, these modules are usually separately trained. We argue that a system like RAG that incorporates multiple modules should be jointly optimized to achieve optimal performance. To demonstrate this, we design a specific pipeline called SmartRAG that includes a policy network and a retriever. The policy network can serve as 1) a decision maker that decides when to retrieve, 2) a query rewriter to generate a query most suited to the retriever, and 3) an answer generator that produces the final response with/without the observations. We then propose to jointly optimize the whole system using a reinforcement learning algorithm, with the reward designed to encourage the system to achieve the best performance with minimal retrieval cost. When jointly optimized, all the modules can be aware of how other modules are working and thus find the best way to work together as a complete system. Empirical results demonstrate that the jointly optimized SmartRAG can achieve better performance than separately optimized counterparts.

## 1 Introduction

Although large language models(LLMs) (Chowdhery et al., ; Touvron et al., ; Chung et al., ) have demonstrated exceptional capabilities across various domains, addressing knowledge-related issues beyond model parameters remains a challenging task (Mallen et al., ; Min et al., ). Retrieval-augmentation generation(RAG) effectively enhances model performance in these scenarios by retrieving additional information from external tools (Ram et al., ).

RAG systems usually consist of multiple modules including at least a retriever and a generator. Some systems may have other modules like a reranker (Glass et al., ), a decision maker deciding when to retrieve (Jeong et al., ; Wang et al., ), a query rewriter (Ma et al., ; Tan et al., ) or a verifier (Lewis et al., ; Izacard et al., ). These modules are often hand-designed and separately optimized. One of the issues is that the golden answer of the intermediate modules are usually not accessible. What is worse, sometimes the golden answer is model-dependent or retriever-dependent. For example, Asai et al. () uses the result of GPT4 (Achiam et al., ) as the ground truth for the decision maker, which can be suboptimal. A question that GPT4 can answer without retrieval may need retrieval for other base models, meaning that the golden answer for the decision maker is model-dependent. In this sense, optimizing each module separately will obviously be suboptimal.

We argue that a system like RAG that incorporates multiple modules should be jointly optimized in an end-to-end manner. For this purpose, we design a RAG system, namely SmartRAG, and jointly optimize it using reinforcement learning, with environment feedback as supervision.

Figure: Figure 1: Overview of SmartRAG. The policy network takes the original question and optional observations as input and generates an action that can be interpreted as a decision-maker and the corresponding parameters. If the policy decides to retrieve, the retriever will be called to obtain the observation that updates the state. Otherwise, the policy network will output the final answer. SmartRAG is optimized using a reinforcement learning algorithm with a properly designed reward.
Refer to caption: x1.png

Specifically, SmartRAG includes two core building blocks, a policy network, and a retriever, as shown in Figure 1. The policy network can serve as three different roles. Firstly, it should decide whether to retrieve or not based on the input state, which includes the input question and optional observations. The second role is query rewriter. If the policy network decides to retrieve the database, it will also output the search query that better suits the retriever than the original question. The last role is answer generator. If the policy network thinks it is already able to answer the question based on the current information, it should generate an appropriate final response.

To optimize such a system, the only supervision should come from the environment, rather than a proxy “golden” answer generated by another model. For SmartRAG, the primary goal is to correctly answer the question while the secondary goal is to minimize the retrieval cost. With this guideline, we can design a reward function that encourages the whole system to correctly answer the question with minimal retrieval trials.

We validate the effectiveness of SmartRAG on various datasets, demonstrating that our SmartRAG outperforms its counterparts with separately optimized modules. We also systematically analyze the properties of SmartRAG, showcasing that it learns when to retrieve, what to retrieve and how to answer based on the observations. The integration of these competencies necessitates a high degree of inter-module awareness, which in turn enhances the system’s overall performance.

Our contribution lies in three aspects:

- 1.
We design SmartRAG, a system that includes a policy network and a retriever. The policy network can serve as three different roles related to RAG. With this design, our SmartRAG system can be optimized using an RL framework.
- 2.
We propose using PPO to jointly optimize our SmartRAG to achieve better performance than training each related module separately.
- 3.
Empirical results demonstrate the effectiveness of our method on various tasks. Systematic analysis are also applied to help us better understand how SmartRAG works and why it outperforms previous algorithms.

## 2 Related Work

### 2.1 Retrieval-Augmented Generation

Retrieval augmentation techniques have been utilized to acquire external knowledge, which aids language models in achieving superior performance across a broad spectrum of tasks (Guu et al., ; Gao et al., ; Hu & Lu, ). Previous research has primarily concentrated on ”what to retrieve”(Khandelwal et al., ; Ram et al., ) and ”how to utilize the retrieved information”(Khattab et al., ).

Recently, some studies have begun to explore when to use retrieval to meet the varying requirements of diverse tasks (Jiang et al., ). For instance,  Mallen et al. () assesses the popularity of a query based on the frequency of its entities and recommends activating retrieval modules only when the entity frequency drops below a predetermined threshold.  Wang et al. () enhances the model’s retrieval performance by using self-knowledge to decide what they know and do not know. Self-Rag (Asai et al., ) leverages special tokens to adaptively retrieve external knowledge and confirm the output’s relevance or efficacy. Additionally, some researchers incorporated supplementary modules or classifiers to determine whether a query necessitates additional knowledge for resolution (Liu et al., ; Jeong et al., ).  Wang et al. () create a compositional unknown dataset (CuQA), and utilize the confidence words or scores to decide whether to retrieve.

Unlike previous methods, we have implemented an end-to-end approach to jointly optimize all the related tasks such that the whole system can achieve better performance.

### 2.2 Learning from Feedback

Training LLMs from feedback (Ouyang et al., ; Ji et al., ) has proven effective in enabling LLMs to understand the impact of their actions and adapt their behavior accordingly, which effectively aligns the model’s behavior with human intentions. Based on the different forms of explicit guidance, it can be categorized into four types: label-based (Guerdan et al., ), reward-based (Wu et al., ), demonstration-based (Dasari et al., ), and comparison-based approaches (Ouyang et al., ). One of the most effective training paradigms among them is reinforcement learning (Ge et al., ). The significant reason is that it is relatively easier to collect and evaluate the quality of responses compared to expert answers (Rafailov et al., ), improving proﬁciency in translation (Kreutzer et al., ), summarization (Liu et al., ), and instruction-following Ramamurthy et al. (). In retrieval augmentation, Ma et al. employs Proximal Policy Optimization (PPO) (Schulman et al., ) to refine the search query, using the match score between the predicted answer and the gold standard answer as the reward. Furthermore, this use of gold answers as feedback enables the model to learn when to utilize tools to expand its capabilities and interact with the real world (Qiao et al., ).

Different from most of the previous methods, which are solving a context bandit problem, our proposed SmartRAG contains multiple steps of interactions between the policy and the environment and learns from the environment feedback rather than human feedback.

## 3 Methodology

Let x be the input question and y be the golden answer. For RAG systems, there is usually a companion retriever $\mathcal{R}$ that takes a query q as input and returns an observation o, *i.e.* $\textbf{o}=\mathcal{R}(\textbf{q})$.

The core part of SmartRAG is a policy network $\pi_{\theta}$, which is an LLM with the parameters being $\theta$. The policy network takes the state s as input, which is a combination of the original question and the optional observations, *i.e.*

$$ $\textbf{a}\sim\pi_{\theta}(\textbf{s}=[\textbf{x},\textbf{os}]),$ (1) $$

where os is the concatenation of all the historical observations returned from the retriever while a is the action sampled from the output of the policy network. In SmartRAG, there are two different types of actions: *answer* and *retrieve*. Let $\textbf{a}_{0}$ be the first token of a. Then $\textbf{a}_{0}$ is a special token that can be either
[Answer]
or
[Retrieve]
. If $\textbf{a}_{0}=\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{
pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Retrieve]}}}$, it means that the policy thinks it necessary to retrieve with query $\textbf{a}_{1:}$, which is the rest part of a. In this case, the retriever will be called to obtain the new observation $\mathcal{R}(\textbf{a}_{1:})$ that will be appended to os. Then the policy network will be called again to produce the next action by (1). On the other hand, if $\textbf{a}_{0}=\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{
pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Answer]}}}$, it indicates that the policy network thinks there is no need for an extra retrieve and it is able to produce the right answer with $\textbf{a}_{1:}$. Thus we obtain the final answer $\hat{\textbf{y}}=\textbf{a}_{1:}$.

The SmartRAG pipeline is shown in Algorithm 1. We can set the quota for retrieval as $N$. When the number of retrieves has already met the quota, we can force the policy network to generate the answer by forcing $\textbf{a}_{0}$, which is the first output token, to be
[Answer]
. Thus we can avoid the policy network to keep retrieving if no satisfying observation is obtained from the retriever.

Figure: Algorithm 1 SmartRAG Pipeline

### 3.1 Warm-Up Using Supervised Finetuning

Since our policy network is initialized using a base LLM, the output of which does not necessarily follow our design that the first output token is either
[Retrieve]
or
[Answer]
. To achieve the output format requirements, we first warm-up the base LLM with our constructed dataset.

For each question x, we construct three different types of input-output pairs for the warm-up step. The first pair is a direct answer. In this case, the input is the original question x while the output is the golden answer prefixed with the special token
[Answer]
. Thus we have the first data point, *i.e.*

$$ $\textbf{s}=\left[\textbf{x},\textbf{os}=[]\right],\leavevmode\nobreak\ \leavevmode\nobreak\ \leavevmode\nobreak\ \textbf{a}=\left[\textbf{{\color[rgb ]{0.2,0.3,0.6}\definecolor[named]{pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Answer]}} },\leavevmode\nobreak\ \textbf{y}\right].$ (2) $$

The second data point encourages the policy network to apply retrieval action. To achieve a diverse initial state for the future RL algorithm, we ask GPT-3.5 (^1^11gpt-3.5-turbo-1106) to rewrite the original question x to produce a diverse query for the retriever. The second data point then becomes

$$ $\textbf{s}=\left[\textbf{x},\textbf{os}=[]\right],\leavevmode\nobreak\ \leavevmode\nobreak\ \leavevmode\nobreak\ \textbf{a}=\left[\textbf{{\color[rgb ]{0.2,0.3,0.6}\definecolor[named]{pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Retrieve] }}},\leavevmode\nobreak\ \text{GPT-Rewriter}(\textbf{x})\right]$ (3) $$

The third data point enables the initial policy network to know how to answer with the observations, it is constructed as

$$ $\textbf{s}=\left[\textbf{x},\textbf{os}=\mathcal{R}(\text{GPT-Rewriter}( \textbf{x}))\right],\leavevmode\nobreak\ \leavevmode\nobreak\ \leavevmode \nobreak\ \textbf{a}=\left[\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named ]{pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Answer]}}},\leavevmode\nobreak\ \textbf{y }\right].$ (4) $$

After finetuning the base LLM with the above-constructed dataset, we can obtain an initial policy network $\pi_{\theta_{0}}$ that can output with our desired format and generate reasonable results. It should be noticed that the warm-up step only provides a reasonable initial policy. It does not necessarily mean that the constructed dataset from (2) to (4) is the “golden” answer since the behavior of the policy network will be further optimized in the following reinforcement learning step.

We can further enhance the initial policy by slightly modifying the warm-up dataset. For the data points that the base LLM can already correctly answer, we remove the constructed SFT data points defined in (3) and (4). Otherwise, we remove the constructed SFT data point defined in (2). By doing so, the warm-up dataset already contains the information about whether the base LLM has the corresponding knowledge for the question, leading to a better initial policy, denoted as $\pi_{\theta_{0}^{*}}$.

### 3.2 Jointly Optimization Using Reinforcement Learning

After obtaining the initial policy $\pi_{\theta_{0}^{*}}$ in the SFT warm-up stage, we then start jointly optimizing the whole framework using reinforcement learning. Following Algorithm 1, we can generate a trajectory $(\textbf{s}^{(0)},\textbf{a}^{(0)},\textbf{r}^{(0)},...,\textbf{s}^{(T)},
\textbf{a}^{(T)},\textbf{r}^{(T)})$, where $\textbf{s}^{(t)}$, $\textbf{a}^{(t)}$ and $\textbf{r}^{(t)}$ represents the state, action and reward at the $t$-th step respectively. $T$ stands for the trajectory length and we then define the details of the reward $\textbf{r}^{(t)}$.

Our reward function is only related to the action $\textbf{a}^{(t)}$. If the policy produces a related answer, the system will get a positive reward. If the policy uses a retrieval opportunity, it should be penalized for the retrieval cost. Thus the reward function can be written as

$$ $\textbf{r}^{(t)}=\begin{cases}\mathbb{I}\left(\textbf{a}_{1:}^{(t)}, \leavevmode\nobreak\ \leavevmode\nobreak\ \textbf{y}\right)+F_{1}\left(\textbf {a}_{1:}^{(t)},\leavevmode\nobreak\ \leavevmode\nobreak\ \textbf{y}\right)& \text{if}\leavevmode\nobreak\ \leavevmode\nobreak\ \leavevmode\nobreak\ \textbf{a}^{(t)}_{0}=\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{ pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Answer]}}},\\ -\alpha&\text{if}\leavevmode\nobreak\ \leavevmode\nobreak\ \leavevmode\nobreak \ \textbf{a}^{(t)}_{0}=\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{ pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Retrieve]}}}.\end{cases}$ (5) $$

Here $\mathbb{I}$ is the identity function. It equals to $1$ if the two arguments are identical and equals to 0 0 otherwise. Besides the exact match reward term, we also add a soft match term in $\textbf{a}_{0}^{(t)}=\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{
pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Answer]}}}$ case, which is the $F_{1}$ score between $\textbf{a}_{1:}^{(t)}$ and y. In addition, $\alpha$ is a positive constant penalizing the retrieval cost. The overall objective then becomes

$$ $\mathbb{E}_{\pi_{\theta}}\left[\sum_{t=0}^{T}\gamma^{t}\leavevmode\nobreak\ \cdot\leavevmode\nobreak\ \textbf{r}^{(t)}\right],$ (6) $$

where $\gamma$ is the discount factor.

By such a design, we encourage the whole SmartRAG system to produce the correct answer with a minimal number of retrieval trials. As a result, the system will only retrieve when the model does not inherently know the answer to the question while the retriever happens to have the related knowledge. The system will not call the retriever when the base LLM already knows the answer or neither the base LLM nor the retriever does not know the correct answer. All the modules in the SmartRAG pipeline work as a whole system rather than as separate independent parts.

We optimize the objective (6) using proximal policy optimization (PPO) (Schulman et al., ).

## 4 Experiments

Dataset.   Following Ma et al. (), we use three open-domain QA datasets for evaluation, namely PopQA (Mallen et al., ), AmbigNQ (Min et al., ) and HotpotQA (Yang et al., ). Besides, we also use other datasets like TrivialQA (Joshi et al., ), OpenBookQA (Mihaylov et al., ), MedQA-cn (Jin et al., ) and ARC-c (Clark et al., ) for more analysis and comparisons. All the details of the related datasets are shown in Appendix A.1.

Retriever.   We utilize Bing search engine as our retriever $\mathcal{R}$, which offers a broad knowledge scope and ensures up-to-date factual information. The search engine will return multiple results given a query. We select the top $K$ results and concatenate the snippets from these results as the observation. We leave how to utilize these snippets to the answer generator. In our experiments, we set $K=4$ without other clarifications.

Training Details.   In the SFT warmup stage, we finetune the network for $1$ epoch with the learning rate being $3e-4$. The batch size is set to be $8$. In the reinforcement learning stage, we use an on-policy sampling strategy. For each iteration, we sample many trajectories such that the total length of all these trajectories is $5120$. The policy network is then trained for $1$ epoch on these samples with the learning rate being $2e-6$ and batch size being $32$. The retrieval penalty $\alpha$ in (5) is set to $0.2$ and the retrieval quota $N$ is specified to be $1$ to fairly compare with other baselines.

More implementation details are introduced in Appendix A. We compare our method with the following baselines.

Vanilla RAG   retrieves the search engine using the input question. Then it asks the LLM to generate the final answer with the observations returned from the search engine in a few-shot manner.

SFT RAG   uses the same pipeline as our SmartRAG. Similar to Vanilla RAG, it uses the input question to retrieve the search engine. We then finetune the answer generator given the input question along with the observations.

GPT4 Rewriter + SFT RAG   adds a query rewrite module than SFT RAG. We ask GPT4, which is one of the most powerful LLMs, to rewrite the search query before feeding it to the search engine. In this case, all the modules are still separately optimized.

ReAct   (Yao et al., ) uses the inherent ability of the base network to decide how to retrieve and answer using chain-of-thought (CoT) (Wei et al., ). It can also self-reflect the previous queries and answers to arrive at the final answer.

IRCoT   (Trivedi et al., ) enhances each step of the CoT generation process by incorporating knowledge retrieval steps during the generation process. Note that both ReAct and IRCoT use multi-step retrieval such that the retrieval cost is higher than other baselines and our SmartRAG.

All the above baselines use at least one time of retrieve. To further show the baseline without any retrieval, we also compare with two extra baselines, namely ICL (In-Context Learning) which is simply a few-shot inference, and SFT which is directly finetuned on the golden answer.

**Table 1: Performance on open-domain QA datasets. Bold numbers indicate the best result while underlined number indicates the second-best result.**
| Model | PopQA | AmbigNQ | HotpotQA | Average |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| EM | F1 | EM | F1 | EM | F1 | EM | F1 |  |
| Flan-T5 large |  |  |  |  |  |  |  |  |
| ICL | 7.03 | 10.16 | 2.47 | 7.30 | 12.46 | 20.42 | 7.32 | 12.63 |
| SFT | 12.76 | 17.70 | 4.56 | 10.92 | 12.72 | 19.72 | 10.01 | 16.11 |
| Vanilla RAG | 34.36 | 38.80 | 30.72 | 40.16 | 22.06 | 32.57 | 29.05 | 37.18 |
| SFT RAG | 38.15 | 42.05 | 31.63 | 41.05 | 24.01 | 34.03 | 30.93 | 38.68 |
| GPT4 Rewriter + SFT RAG | 39.27 | 42.68 | 33.43 | 42.40 | 24.12 | 34.33 | 32.27 | 39.80 |
| SmartRAG(ours) | 42.50 | 45.95 | 33.71 | 42.75 | 25.54 | 35.23 | 33.29 | 41.25 |
| LlaMa-2 7B |  |  |  |  |  |  |  |  |
| ICL | 21.79 | 24.61 | 18.63 | 27.12 | 17.62 | 25.60 | 19.35 | 29.11 |
| SFT | 27.91 | 31.54 | 22.47 | 31.28 | 20.74 | 29.52 | 23.71 | 30.78 |
| ReAct (Yao et al., ) | 27.21 | 31.49 | 22.45 | 31.24 | 21.91 | 29.83 | 23.86 | 30.85 |
| IRCoT (Trivedi et al., ) | 9.22 | 17.93 | 13.52 | 25.94 | 17.42 | 27.13 | 13.39 | 23.67 |
| Vanilla RAG | 32.26 | 40.06 | 33.12 | 46.20 | 24.18 | 34.94 | 29.82 | 40.40 |
| SFT RAG | 38.71 | 42.33 | 36.58 | 46.09 | 25.59 | 35.15 | 33.64 | 41.19 |
| GPT4 Rewriter + SFT RAG | 42.22 | 46.04 | 36.13 | 46.02 | 25.29 | 35.38 | 34.54 | 42.49 |
| SmartRAG(ours) | 44.32 | 47.60 | 37.89 | 47.76 | 26.60 | 36.42 | 36.27 | 43.93 |

We compare our proposed SmartRAG with all the baselines in Table 1. Following Jeong et al. (); Asai et al. (), we use two different types of base LLMs, *i.e.* Flan-T5 large (Chung et al., ) and LlaMa2-7B (Touvron et al., ). Two different metrics are adopted in the comparison: the exact match (EM) and the F1 score. In this table, ICL and SFT show the results without retrieval. the performance is very poor, indicating that retrieving is necessary for these datasets. All the algorithms that have retrieve-related modules significantly increase the performance. By jointly optimizing all the related modules, our SmartRAG is able to outperform all the counterparts that use separately optimized modules. This validates our argument that joint optimization is necessary to make all the modules properly work together to achieve optimal performance. In addition, we find that GPT4 Rewriter + SFT RAG sometimes performs worse than SFT RAG, meaning that the rewritten query provided by GPT4 may be worse than the original question. In this sense, the query rewritten by GPT4 is just reasonable but not golden.

We only provide the result of ReAct and IRCoT for the LlaMa2 base model because these two methods produce extremely poor results on Flan-T5. Without any adaptation to the real application, which includes tasks that are either model-dependent or retriever-dependent, simply using the inherent reasoning ability of the base models has no means of achieving optimal performance.

### 4.1 SmartRAG Learns When to Retrieve

The first token of the action a indicates whether to retrieve or not. In practice, the policy network outputs a Bernoulli distribution over $\{\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{pgfstrokecolor}{rgb}{
0.2,0.3,0.6}{[Answer]}}},\textbf{{\color[rgb]{0.2,0.3,0.6}\definecolor[named]{
pgfstrokecolor}{rgb}{0.2,0.3,0.6}{[Retrieve]}}}\}$, we can manually set up a threshold on the logit of
[Answer]
to control the retrieval ratio. Figure 2 shows the F1 score of SmartRAG with different thresholds. We compare SmartRAG with two baselines. The first one is SFT. Since it does not have any decision maker for whether to retrieve, it only has two states: full retrieve and no retrieve. The second baseline is SKR (Wang et al., ), which trains a small module to decide whether to retrieve. The golden answer is provided by whether the answer generation module can produce the correct result. We can see that the results of SmartRAG is to the upper left side of the other methods, meaning that SmartRAG can produce a similar F1 score with less retrieval cost. On both PopQA and HotpotQA datasets, SmartRAG can even produce a higher F1 score with less retrieval percentage than SKR. To achieve this, SmartRAG should put more retrieval efforts on the scenarios when retrieval does bring benefit. These are instances where the base LLMs lack inherent knowledge of the correct answer, yet the necessary information is encompassed within the database.

A deduction about the above arguments is that SmartRAG should not retrieve anything if the database hardly contains any useful knowledge. This is indeed the case for the Bing search engine on OpenBookQA, MedQA-cn and ARC-c datasets. We list the retrieval percentage and accuracy on these datasets in Table 2. SFT and SFT RAG produce extremely close accuracy since the database contains very little knowledge of these datasets. The SKR method still produces a high retrieval percentage, which wastes the retrieval resources. Our SmartRAG is aware of the property of the database and learns not to retrieve it in these cases.

Figure: Figure 2: F1 Score of different retrieval percentage across three datasets on Flan-T5-large.
Refer to caption: x2.png

**Table 2: Results of different one-choice questions on Flan-T5-large. All the methods produce similar accuracy since the database does not contain the useful answer. Our SmartRAG learns not to retrieve for it does not bring any benefit in these cases.**
| Method | Retrieval Percentage | Accuracy |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
| OpenBookQA | MedQA-cn | ARC-c | OpenBookQA | MedQA-cn | ARC-c |  |
| SFT | 0.00 | 0.00 | 0.00 | 67.20 | 31.66 | 54.95 |
| SFT RAG | 100 | 100 | 100 | 68.20 | 31.11 | 56.99 |
| SKR (Wang et al., ) | 5.60 | 84.29 | 9.98 | 67.20 | 31.89 | 54.86 |
| SmartRAG | 0.00 | 0.00 | 0.00 | 66.60 | 33.31 | 55.72 |

### 4.2 SmartRAG Learns What to Retrieve

Once SmartRAG decides to retrieve the database, the next task is what to retrieve. Directly searching the original question produces suboptimal performance, as Table 1 already demonstrates. In this section, we showcase how SmartRAG rewrites the retrieving query in Table 3 with two examples. In the first question Who was the producer of 9, directly searching the question cannot provide any useful information because the term 9 is quite confusing. As a result, the retriever does not return any useful information and thus the final answer is wrong. The rewritten query Who produced the movie 9 is aware that 9 is a movie name and explicitly uses the term movie 9 to retrieve. With this modification, the returned observation is more related and contains the correct answer, which is then output by the answer generator in the next step. In the second example, the subject of the original question is makkah royal clock tower hotel. Directly searching the question returns information about the hotel with no messages related to the start date of construction for the hotel. The subject is modified to start date of the construction by the policy network, making the search more accurate.

**Table 3: Comparison between observations with orignal questions and rewritten queries.**
| Question 1: Who was the producer of 9? |
| --- |
| Golden Answer: Shane Acker |
| Observation with original question: 5 Things to Know About THE9, China 2019s New Pop Idol Group: Predicting the shelf-life of a pop act is never straightforward, but it will be interesting to see just how long THE9 stick around given the rapid demise of boyband Nine Percent, who were spawned by 2018-2019s Idol Producer. |
| Output:<br>[Answer]<br>Tim Burton |
| Rewritten Query: Who produced the movie 9? |
| Observation with rewritten query: 9 (2009) - IMDb: Shane Acker first made 9 (2009) as a ten minute short film while he was still at UCLA. It was nominated for Best Animated Short at the Oscars, and although it didn’t win, Acker was offered the chance to expand it into a feature film. |
| Output:<br>[Answer]<br>Shane Acker |
| Question 2: When was the contruction of the makkah royal clock tower hotel started? |
| Golden Answer: 2004 |
| Observation with original question: Ryugyong Hotel: Ryugyong Hotel was designed by North Korean firm Baikdoosan Architects and Engineers, which is also the contractor of the project before 1992, the firm had built the building to its full height before the construction suspended in 1992. … However, considering Ryugyong Hotel is 112 meters shorter than Willis Tower, 360,000 square meters is still … |
| Output:<br>[Answer]<br>1992 |
| Rewritten Query: Start date of construction for the Makkah Royal Clock Tower Hotel |
| Observation with rewritten query: Makkah Royal Clock Tower, Saudi Arabia - World Construction Network: The Makkah Royal Clock Tower complex, also known as the Abraj Al-Bait Towers, located near Masjid al Haram in Mecca, Saudi Arabia, is a mixed residential and hotel complex. Construction on the complex was started in 2004 and finished in 2012. |
| Output:<br>[Answer]<br>2004 |

To further validate that the query rewrite module does play its role in enhancing the overall performance, we replace all the retrieving queries in SmartRAG with the original question. The evaluation result is shown in Table 4 (comparing lines SmartRAG and Replace Query). Replacing the rewritten query in SmartRAG with the original question does degrade the performance on all the datasets over both exact match and F1 score metrics. We also introduce a new metric hit. It tracks the ratio of observations that contain the golden answer.

**Table 4: Comparison to replace the query with the original questions and replace the generator with the pre-RL warm-up model.**
| Method | PopQA | AmbigNQ | HotpotQA |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| EM | F1 | hit | EM | F1 | hit | EM | F1 | hit |  |
| Replace Query | 39.13 | 42.98 | 50.49 | 33.41 | 42.19 | 49.31 | 24.31 | 34.04 | 33.83 |
| Replace Generator | 40.95 | 43.87 | 52.59 | 33.23 | 42.02 | 49.78 | 25.63 | 35.04 | 35.89 |
| SmartRAG | 42.50 | 45.95 | 52.59 | 33.71 | 42.75 | 49.78 | 25.54 | 35.23 | 35.89 |

### 4.3 SmartRAG Learns How to Answer

Given the correct time to retrieve and the proper query for retrieval, the system should also learn how to well utilize the observations from the retriever to produce the final answer. To validate that SmartRAG learns how to answer with the observations, we replace the final answer generation step with the version before PPO. Note that this generator before PPO is already finetuned with data points that contain observations from the retriever. So it also learns how to answer based on the observations. The only difference is that it is not jointly optimized with other modules.

Table 4 (comparing lines SmartRAG and Replace Generator) shows the replacement also degrades the performance on most of the metrics. The hit metric remains the same because they use the same queries for retrieving and thus have exactly the same observations. Two examples are presented in Table 5. In both examples, the correct answer is included in the observations (highlighted in green). SmartRAG can correctly find the answer from the lengthy information. However, the answer generator before PPO either finds the wrong information (the first example) or hallucinates the wrong answer (the second example).

**Table 5: Improvement of answer from observation between before and after PPO.**
| Question 1: Who was the screenwriter for On the Beach? |
| --- |
| Golden Answer: Nevil Shute |
| Observation: On the Beach, Summary and Facts, Britannica - Encyclopedia Britannica: On the Beach, American dramatic film, released in 1959, that was set in the aftermath of an imagined World War III. It was based on the apocalyptic novel of the same name by Nevil Shute. The fatal fallout of nuclear war in the year 1964 serves as the fictional backdrop for romance between a navy On the Beach (1959) - FilmAffinity: On the Beach is a film directed by Stanley Kramer with Gregory Peck, Ava Gardner, Fred Astaire, Anthony Perkins …. |
| Before PPO Output:<br>[Answer]<br>Stanley Kramer |
| After PPO Output:<br>[Answer]<br>Nevil Shute |
| Question 2: What’s the most points scored in an nba game by a single team? |
| Golden Answer: 186 |
| Observation: NBA Single Game Leaders and Records for Points: Checkout the complete list of NBASingle Game Leaders and Records for and more on Basketball-Reference.com. Year-by-Year Top 10: Checkout the complete list of NBA and ABAYear-by-Year Top 10 Leaders and Records for and more on Basketball-Reference.com … shows the teams that scored the most points in one game in NBA history, including regular season and Playoffs. Most points scored by a team in an NBA game: On Dec. 13, 1983, the Detroit Pistons set the single-game scoring record for an NBA team with 186 points in an all-time shootout against the Nuggets. Detroit defeated Denver 186-184 in… Who has scored the most points in a single NBA game? - ESPN: On March 2, 1962, Wilt Chamberlain set the NBA’s single-game scoring record with 100 points in the Philadelphia Warriors’ 169-147 win over the New York Knicks. The NBA didn’t add the… |
| Before PPO Output:<br>[Answer]<br>370 |
| After PPO Output:<br>[Answer]<br>186 |

### 4.4 Influence of the Initial Policy

Figure: Figure 3: Influence of different initial policies for SmartRAG.
Refer to caption: x5.png

We have proposed two initial policies in Section 3.1. To study how the initial policies can influence the final performance, we start from both initial policies and go through the same PPO procedure. The exact match and F1 score of the initial policy and final policy for both initializations are shown in Figure 3. $\pi_{\theta_{0}}$ (initial policy 1) clearly performs worse than $\pi_{\theta_{0}^{*}}$ (initial policy 2) because the corresponding warm up dataset contains less information. Applying PPO enhances both policies. The final policy with better initialization still outperforms its counterpart with worse initialization, indicating that a well-designed initial policy benefits the PPO procedure.

## 5 Conclusion

We introduce SmartRAG, a novel framework that can decide when to retrieve, what to retrieve, and how to answer with/without the retrieved observations. All these functions are accomplished by a policy network and a companion retriever. SmartRAG jointly optimizes the whole system using reinforcement learning. Empirical results show that SmartRAG outperforms previous methods whose modules are separately optimized. For systems comprising multiple modules, it is necessary to optimize them from a holistic perspective—a challenge we reserve for future research endeavors.

#### ETHICAL CONCERNS

This paper primarily focuses on an end-to-end RAG framework that addresses the questions of when to retrieve, what to retrieve, and how to answer within a single LLM. Our method utilizes open-source datasets and Bing retrieval for training and testing, with all data being publicly accessible. While our approach demonstrates the ability to effectively enhance the model’s decision-making capabilities and improve the accuracy of retrieved information, as well as the final answers, we hope that this design—more aligned with real-world applications—can enhance the efficiency of RAG pipelines. Furthermore, we aspire for this promising framework to be applied across various LLM decision-making scenarios.

#### REPRODUCIBILITY STATEMENT

The details of experiment settings are provided in Section 4, and a more detailed description and implementation setting can be found in Appendix A. All datasets and models used in our work are publicly available. Additionally, we have uploaded our code in the supplementary materials and will open-source it upon acceptance of the paper.

## Appendix

[sections]
\printcontents[sections]l1

## Appendix A Experimental Details

### A.1 Details of Raw Datasets

A concise summary of the utilized datasets is presented below:

- •
PopQA (Mallen et al., ) consists of 14k questions designed to encompass factual information in the long tail, potentially overlooked by widely used QA datasets. It is an entity-centric, open-domain QA dataset featuring entities with varying levels of popularity.
- •
AmbigNQ (Min et al., ) provides a disambiguated version of Natural Questions(NQ) (Kwiatkowski et al., ). For ambiguous questions in NQ, minimal constraints are introduced to refine them into multiple similar yet more specific questions
- •
HotpotQA (Yang et al., ) is a multi-hop dataset derived from Wikipedia. The questions are diverse and not limited by any predefined knowledge bases or schemas. HotpotQA is an English Wikipedia question-answering dataset consisting of approximately 113K crowd-sourced questions, designed to require the introductory paragraphs of two Wikipedia articles for answering. Each question is accompanied by two gold paragraphs and a set of sentences within these paragraphs, identified by crowd workers as supporting facts essential for answering the question.
- •
TriviaQA (Joshi et al., ) is a large-scale, text-based question-answering dataset consisting of 950K question-answer pairs derived from 662K documents, sourced from both Wikipedia and the web.
- •
OpenBookQA (Mihaylov et al., ) consists of 5,957 multiple-choice questions, each with four possible answers. The dataset is supplemented with external fundamental scientific facts, requiring a deep understanding of these facts to answer the questions accurately.
- •
MedQA-cn (Jin et al., ) compiles questions from the National Medical Board Examinations of Mainland China. It serves as a challenging benchmark, encompassing a wide range of medical knowledge, including patient profiles, disease symptoms, and drug dosage requirements. This diversity necessitates a contextual understanding to accurately respond to the questions presented.
- •
ARC-c (Clark et al., ) contains complex questions that demand deep reasoning, integration of multiple information sources, and advanced inferential capabilities. This subset pushes AI models beyond basic text matching, requiring them to address ambiguity and engage in sophisticated problem-solving, testing the depth of their reasoning and comprehension.

The scale of the data used in the paper is presented in Table 6. To reduce the number of training iterations, we combined the three datasets for joint training. It is worth noting that this cross-dataset training presents a more challenging task, and we employed multi-dataset training during both the warm-up and PPO training phases. To mitigate the long-tail issues arising from distribution differences among the datasets, we utilized only 20k samples from the HotpotQA dataset to align with the scales of the PopQA and AmbigNQ datasets. Additionally, for the multiple-choice questions, we limited our training to 2k samples from both OpenBookQA and MedQA-en.

### A.2 Details of Warm Dataset Collection

**Table 6: Details of raw datasets.**
| Datasets | Category | Training Set | Test Set |
| --- | --- | --- | --- |
| PopQA | Open Domain | 13.0k | 0.7k |
| AmbigNQ | Open Domain | 19.4k | 5.8k |
| HotpotQA | Open Domain | 90.4k | 7.4k |
| TriviaQA | Open Domain | 78.8k | 8.8k |
| OpenBookQA | Scientific Knowledge | 5.0k | 0.5k |
| MedQA-en | Medical Domain | 10.2k | 1.3k |
| ARC-c | Commonsense reasoning | 1.1k | 1.2k |

In the earlier mentioned process of handling the warm-up dataset, we utilized datasets of the same scale as those used in training for multi-task warm-up. Each question presents three options: a direct response, generating a query, and responding based on the retrieved content. The answer content comes directly from the dataset, while the search query is generated by GPT-3.5. The prompt we provided to GPT-3.5 is: ‘Assuming you are a professional retrieval model, rewrite the following question into a query that is more suitable for retrieval: {Question}’. Based on this, the warm-up model responds to each question with a 50% probability of either providing a direct answer or an answer after retrieval, making it difficult to determine the importance of retrieval for each question. However, this setup offers reinforcement learning and a balanced initial state to explore different decision-making strategies.

As mentioned in Section 4.4, a better initial state can lead to improved results; therefore, we refined the SFT data for initial policy 2. We divided the data into two categories based on the model’s ability to provide direct answers in the training set (F1 score $\geq$ 0.2): one where the model can answer correctly to some extent, and another where the answers are entirely incorrect. During warm-up, for the first category, the model only provides direct responses, while for the second, it generates a query and answers based on the retrieved content. Under this warm-up training strategy, the model acquires a certain level of retrieval decision-making capability. This reasoning stems from the idea that if the model can provide correct answers on its own, there is no need to rely on external retrieval. Through joint training in our framework, the model further becomes aware of the effectiveness of the database, optimizes its query retrieval, and refines the answer generation, allowing it to explore a better state beyond the warm-up phase.

### A.3 Training and inference Details

Retriever   We utilize the Bing search engine as our retriever, which does not require candidate index construction like dense retrievers, nor predefined candidates as in traditional resources. Instead, it offers a broad knowledge scope and ensures up-to-date factual information. We concatenate snippets from all retrieved web pages, selecting relevant sentences identified by Bing—much like entering a query into a browser, then gathering the text displayed on the search results page. The results obtained through this concatenation method resemble summaries of each webpage, encapsulating the core content of the retrieved information within a constrained length. The search engine will return multiple results given a query. We select the top $K$ results and concatenate the snippets from these results as the observation. In our experiments, we set $K=4$ without other clarifications.

Model   Since our framework employs a single model to handle all tasks within the RAG system, we employed models of varying sizes for training. To further explore the effects of different architectures and model sizes, we conducted experiments on the Flan-T5 series models. In addition, we trained a Llama2 7B model to validate the effectiveness of our framework on a larger model. It is noteworthy that, since we use PPO for training, it requires optimizing the policy model, value model, and reference model simultaneously. To reduce memory consumption and improve training speed, we applied LoRA (Hu et al., ) for tuning LlaMa-7B.

Settings   We use 4 Nvidia A100 with 80GB memory to train our models. For the SFT warmup stage, we use the following training parameters: a learning rate of 3e-4, a batch size of 8, and to prevent overfitting, the number of epochs is set to 1. For reinforcement learning, we set the sampling steps to 5120, 10 threads, 512 steps for each. After sampling, the policy network is trained for 1 epoch, with a learning rate of 2e-6 and batch size of 32.

Retrieval reward   For the penalized retrieval reward $\alpha$ in equation 5, we assign a value of -0.2. This decision is motivated by the substantial influence this parameter exerts on the training dynamics. A high setting would drive the model to predominantly opt for retrieval, whereas a low setting would discourage retrieval altogether. Given the explicit nature of this retrieval reward, any significant deviation from the retrieval-generated reward during the model’s sampling process may prompt the model to adopt an overly simplistic strategy. Consequently, this could hinder the reinforcement learning process, limiting the model to either a retrieval-only or non-retrieval optimization approach, thus compromising its ability to sample diverse examples effectively.

Table: Table 7: Instructions for two-step RAG in SmartRetriverX.

Generation Details   During the reinforcement learning training phase, to ensure sampling diversity and obtain samples reflecting different decision-making strategies, we employ Top-K decoding with K set to 50. This means that at each time step, the top K most probable candidate words from the probability distribution are selected, while the probabilities of the other words are set to zero. The probabilities of these K candidate words are then renormalized to sum to 1, forming a new probability distribution. A word is then randomly sampled from this new distribution as the output for the current time step. This process is repeated until an end token is generated or the maximum length is reached.

During inference, we use Beam Search for decoding. For the first token that determines when to retrieve, we apply a threshold-based approach (Asai et al., ): if the confidence score of the generated query exceeds the threshold, retrieval is performed; otherwise, the model directly provides an answer.

List of Instructions   The entire inference process consists of either one or two steps. The first step involves either directly answering or generating a query. If a query is generated, a second step follows, which entails answering based on the content retrieved according to the query. Table 7 presents the instructions utilized in both steps. To ensure consistency in instruction during the fine-tuning process, we designed the two instructions to maintain as similar a format as possible; the instruction for the second step incorporates only one additional component: the retrieved content observation. We employed the same data format across all datasets, and for multiple-choice questions, we incorporated the candidate answers into the instruction of the question.

## Appendix B Analysis

### B.1 Training Process

Our training process includes both warm-up training and reinforcement learning training. The figure illustrates the changes in iteration reward, KL reward, policy loss, and value loss during the reinforcement learning phase. The iteration reward, corresponding to the reward in the equation, shows an upward trend throughout the training process, indicating that the model is exploring in the right direction. The increase in KL divergence reward indicates that the model’s strategy is being updated, with growing divergence from the previous strategy. At the same time, the loss trends of the policy model and value model are almost the opposite of the reward trend, which aligns with the typical training process of oscillating convergence followed by stable oscillations.

Figure: Figure 4: Iteration reward, KL reward, policy loss and value loss during training.
Refer to caption: x7.png

Figure: Figure 5: Exact Match, F1 Score, and Retrieval Threshold of different retrieval number K on Flan-T5-large.
Refer to caption: x11.png

### B.2 Retrieval Number

In the retrieval-augmented framework, the number of retrieved texts also influences the model’s performance. Generally, when the number of retrieved documents is not large, an increase in the number of retrieved documents leads to greater gains for the model. This is because when the retrieved information falls within the model’s capacity to process, a larger set of documents is more likely to contain useful information. Therefore, we investigated the model’s performance when the retrieval size is K=1 and K=4 based on initial policy 1. When K=4, it represents a retrieval of more documents and a stronger retrieval capacity, allowing us to explore the impact of varying-value database on our method’s training results. The results, as shown in the figure, indicate that retrieving more documents leads to better performance. The figure also illustrates the relationship between the retrieval ratio and the threshold under different retrieval intensities. It is evident that when the retrieval database is more likely to contain relevant information, our method can demonstrate better awareness of the database, which in turn drives the model to rely more on retrieval. This aligns with real-world scenarios, where higher retrieval efficiency should increase the likelihood of the model engaging in retrieval, and vice versa. In contrast, the previous adaptive retrieval method was unable to recognize the impact of different databases.

### B.3 Dataset Transfer

Given that our framework emphasizes the importance of making the model aware of the retrieval database, we tested the model trained with our framework on the TriviaQA dataset in a data migration scenario. The goal was to explore whether this database awareness could transfer to other datasets. We categorized the TriviaQA test set into three types: the first type includes questions that can be answered correctly after supervised fine-tuning (SFT) without retrieval; the second type consists of questions that can only be answered correctly after retrieval; and the third type contains questions that cannot be answered correctly even after retrieval. Ideally, the model should avoid retrieval for the first and third types and opt for retrieval only for the second type. We tested the retrieval proportion for these three data types, and the results are presented in Table 8. It is evident that the second type of data maintains the highest retrieval percentage, while the first type has a relatively lower retrieval percentage. This indicates that in transfer testing scenarios, our model retains a certain level of database awareness.

**Table 8: Dataset Transfer on TriviaQA of Flan-T5-large.**
| Method | EM | F1 |
| --- | --- | --- |
| SFT | 47.72 | 56.99 |
| SKR | 37.51 | 45.35 |
| Ours | 48.87 | 59.17 |

### B.4 Adaptive Retrieval

Section 4.1 presents the F1 score results under the initial policy2 state. Here, we provide more comprehensive results with a different initial state, where the results for both initiate policy2 and initiate policy1 are shown in Tables 6 and 7, respectively. Nevertheless, we can observe that our approach enables the model to learn the concept of when to retrieve, resulting in improved final answers, which stem from the optimization of what to retrieve and how to answer.

Figure: Figure 6: F1 Score of different retrieval percentage across three datasets on Flan-T5-large of initial policy 2.
Refer to caption: x14.png

Figure: Figure 7: Exact Match and F1 Score of different retrieval percentage across three datasets on Flan-T5-large of initial policy 1.
Refer to caption: x17.png

### B.5 Qualitative Cases

Sections 4.2 and 4.3 have already demonstrated that SmartRAG significantly improves both the ‘what to retrieve’ and ‘how to answer’ tasks through quantitative and qualitative analyses. Table 9 and 10 presents additional cases from three datasets. Similarly, it can be observed that the reformulated queries are more effective in retrieving relevant results, and under the same retrieval conditions, the model trained with PPO also demonstrates superior performance

**Table 9: Comparison between observations with orignal questions and rewritten queries.**
| Question 1: In what city was Rafael Reyes born? |
| --- |
| Golden Answer: Cotija |
| Observation with original question: Rafael Reyes — Political leader, Conservative party — Britannica: Rafael Reyes (born 1850, Santa Rosa, New Granada2̆014died February 19, 1921, Bogot0̆0e1, Colombia) was an explorer and statesman who was president and dictator of Colombia from 1904 to 1909. He attempted to give his nation a strong one-man rule that would attract foreign investment and foster domestic industrialization. |
| Output:<br>[Answer]<br>Santa Rosa |
| Rewritten Query: Birth city of Rafael Reyes |
| Observation with rewritten query: Rafael Reyes (Leafar Seyer) Age, Wife, Children, Family, Biography …: Quick Info2̆192. Hometown: Cotija, Michoacan, Mexico. Wife: Kat Von D. Age: 47 Years. Some Lesser Known Facts About Rafael Reyes aka Leafar Seyer. |
| Output:<br>[Answer]<br>Cotija |
| Question 2: What other series is the actress who plays Malory Archer well known for? |
| Golden Answer: Arrested Development |
| Observation with original question: How ’Archer’ said goodbye to Jessica Walter on its season finale: Walter, who voiced the character of spy agency chief Malory Archer on the animated comedy series, died in March at the age of 80. Deadline subsequently reported that Walter had been working… |
| Output:<br>[Answer]<br>The Simpsons |
| Rewritten Query: Which other series is the actress known for playing Malory Archer known for? |
| Observation with rewritten query: Jessica Walter — Archer Wiki — Fandom: She performed the voice of Malory Archer, who was strongly influenced by Walter’s aforementioned role as Lucille Bluth on Arrested Development, in Archer for the first 12 seasons. Walter passed away on March 24th 2021. Season 12 served as her final television role and was released following her death. Its final episode was dedicated to her … |
| Output:<br>[Answer]<br>Arrested Development |
| Question 3: Wheelock Whitney is just one member of the Whitney Family. Where did this American family originate from? |
| Golden Answer: London, England |
| Observation with original question: Minnesota businessman Wheelock Whitney Jr. dies — AP News: Wheelock Whitney, whose fraternity brothers at Yale University included former President George H.W. Bush, was born to a prominent family in St. Cloud. He was CEO from 1963-1972 of the investment banking firm Dain and Co., which he helped turn into a regional financial powerhouse and eventually became RBC Wealth Management. |
| Output:<br>[Answer]<br>St. Cloud |
| Rewritten Query: What is the origin of the Whitney Family, including Wheelock Whitney? |
| Observation with rewritten query: Whitney History, Family Crest and Coats of Arms: Origins Available: England. Ireland. Whitney is one of the many names that the Normans brought with them when they conquered England in 1066. The Whitney family lived in Herefordshire, at the village of Whitney. Early Origins of the Whitney family. |
| Output:<br>[Answer]<br>England |

**Table 10: Improvement of answer from observation between before and after PPO.**
| Question 1: In what country is Dell? |
| --- |
| Golden Answer: America |
| Observation: Where Are Dell Computers Made?: Dell 2018s Current Manufacturing Footprint and Supplier Ecosystem. Flash forward to 2023, and Dell now operates major PC manufacturing plants in the Chinese cities of Xiamen, Chengdu, Wuhan, and Shenzhen. Dell also owns enormous PC production facilities just over the border from mainland China in Taipei and Taoyuan, Taiwan… The other Dell assembly plants are located in China, Malaysia, Brazil, and the United States. Here’s Where Dell Computers And Laptops Are Made Today: Aside from the United States, Dell’s ODM and final assembly facilities are in China, Vietnam, Taiwan, Mexico, Brazil, Ireland, Malaysia, India, Poland, and Thailand. Where Are Dell Computers Assembled? - DeviceTests: Mexico: Dell outsources the assembly of its computers to Foxconn in Mexico. Malaysia: Dell2019s assembly factory is located in Penang, Malaysia. Other places where Dell computers are assembled include Ireland, the United States of America, Singapore, Vietnam, Japan, etc. |
| Before PPO Output:<br>[Answer]<br>Canada |
| After PPO Output:<br>[Answer]<br>America |
| Question 2: What is the religion of Paul? |
| Golden Answer: Christianity |
| Observation: Paul the Apostle World History Encyclopedia: A Founder of Christianity. In the last century, scholars have come to appreciate Paul as the actual founder of the religious movement that would become Christianity. Paul was a Diaspora Jew, a member of the party of the Pharisees, who experienced a revelation of the resurrected Jesus. Paul and Jesus, The Origin of Paul’s Religion, John Gresham Machen … |
| Before PPO Output:<br>[Answer]<br>Anglicanism |
| After PPO Output:<br>[Answer]<br>Christianity |
| Question 3: Where was the think tank founded by a neoconservative political analyst born in 1952 established? |
| Gold Answer: Washington, D.C. |
| Search Query: Establishment location of the think tank founded by a 1952-born neoconservative political analyst |
| Observation: Think tanks and the knowledge2̆013policy nexus in China: For decades, institutionalized linkages with the party-state have shaped intellectual activity and subsequently, think tank agency; think tanks were anointed as either establishment oriented, being officially yoked to the party apparatus, or semi-establishment, operating with a modicum of independence but with the consent of governmental patrons. Think tanks and the knowledge2̆013policy nexus in China: For decades, institutionalized linkages with the party-state have shaped intellectual activity and subsequently, think tank agency; think tanks were anointed as either establishment oriented, being officially yoked to the party apparatus, or semi-establishment, operating with a modicum of independence but with the consent of governmental patrons. |
| Before PPO Output:<br>[Answer]<br>New York City |
| After PPO Output:<br>[Answer]<br>Washington, D.C. |

## Peer Reviews

confidence: 3
contribution: 2
initial_rating: 5
presentation: 3
questions: a) There exists many works focused on the question of "When to retrieval" in RAG, but in Section 4.1, only one baseline was selected for comparison. Incorporating a set of baseline examples into these studies would enhance comparative and analytical insights. 

b) The current baselines primarily apply process-wide optimizations, such as fine-tuning the generator, without optimizing individual modules (e.g., rewriter, generator, and decision-maker) separately. This setup limits the ability to demonstrate how joint optimization in SmartRAG resolves potential conflicts and enhances coordination across modules.
 
Detailed comments:
a) A dedicated section on the limitations and assumptions underlying SmartRAG, particularly regarding the potential latency issues in real-world applications, would be beneficial. 

b) While effective, the joint optimization approach may introduce complexity that could limit the model’s scalability, especially when applied to very large or real-time systems. Additional discussion on computational overhead and training time would strengthen the paper. 

c) Considering the potential for optimizing PPO's efficiency or exploring alternative RL algorithms to reduce training costs, it could be beneficial to further discuss these aspects, which may enhance the practicality of the framework.
soundness: 2
strengths: a) The paper introduces reinforcement learning to jointly optimize RAG components, integrating retrieval decisions, query rewriting, and answer generation as policy-driven actions, representing progress in RAG architectures.

b) The introduction of reinforcement learning further demonstrates the flexibility of RAG and explores the potential of integrating RAG with other AI technologies.

c) Evaluation across several datasets demonstrates the effectiveness of the approach.
summary: The paper introduces SmartRAG, a retrieval-augmented generation (RAG) framework designed to enhance performance through joint optimization of its modules. Unlike traditional RAG approaches, SmartRAG uses a policy network that dynamically decides when to retrieve information, what queries to use, and how to synthesize answers based on retrieved observations. Reinforcement learning with environment feedback is employed to jointly train the system, improving coordination between modules and reducing retrieval costs. Experimental results on multiple QA datasets show that SmartRAG outperforms separately optimized systems.
weaknesses: a) There exists many works focused on the question of "When to retrieval" in RAG, but in Section 4.1, only one baseline was selected for comparison. Incorporating a set of baseline examples into these studies would enhance comparative and analytical insights. 

b) The current baselines primarily apply process-wide optimizations, such as fine-tuning the generator, without optimizing individual modules (e.g., rewriter, generator, and decision-maker) separately. This setup limits the ability to demonstrate how joint optimization in SmartRAG resolves potential conflicts and enhances coordination across modules.
 
Detailed comments:
a) A dedicated section on the limitations and assumptions underlying SmartRAG, particularly regarding the potential latency issues in real-world applications, would be beneficial. 

b) While effective, the joint optimization approach may introduce complexity that could limit the model’s scalability, especially when applied to very large or real-time systems. Additional discussion on computational overhead and training time would strengthen the paper. 

c) Considering the potential for optimizing PPO's efficiency or exploring alternative RL algorithms to reduce training costs, it could be beneficial to further discuss these aspects, which may enhance the practicality of the framework.

---

confidence: 3
contribution: 2
initial_rating: 5
presentation: 3
questions: 1. Clarification on the training dataset. 
    1. Was all of the training data used for SFT and PPO?
    2. On which dataset was the EM and F1 evaluations done? Was this used as a part of the SFT or PPO process? 
2. Is SFT RAG the performance of $\pi_{\theta^*_0}$ in the setting described in Figure 1? (Was SFT RAG evaluated in the same setting as SmartRAG? where the policy network was allowed one retrieval? )
3. Assuming the availability of a powerful model (GPT-3.5) for generating the dataset for SFT is not always true. Have the authors tried using the base LLM to generate the SFT dataset?
soundness: 3
strengths: 1. The main contribution of this work is the end to end trining of the RAG framework. The authors do a good job in analyzing the proposed framework (Section 4.1-4.4) 

2. The paper is generally well written.
summary: This paper proposes a new Smart RAG framework that consists of two parts. (1)Policy Network and (2) Retriever. The policy network decides whether to retrieve or not based on the input state (question + initial observation), and generates an appropriate query to obtain the required information form the retriever. The system is trained in an end-end method using supervised fine tuning and PPO.
weaknesses: The proposed method is not generalizable. 

1. The proposed method is very domain specific and requires the training of the entire module for each dataset.
2. The generalizability of the approach is further curtailed by the availability of datasets with true final answers. (Which is needed for SFT and  PPO) 
3. The end to end framework requires complete retraining if any part of the framework is changed.

---

confidence: 3
contribution: 2
initial_rating: 5
presentation: 2
questions: 1. Why does the policy network serve three roles in the model? What's the motivation behind it? Won't these three roles conflict with each other?
2. The optimization of the whole system is dependent on the feedback from the RL framework. How to distinguish whether a low reward is caused by a wrong policy or inaccurate retrieval?
3. Why is the retrieval percentage of SKR in Figure 2 fixed at 0.8?
4. In Section 4.1, the author states that *OpenBookQA, MedQA-cn, and ARC-c datasets* have nothing to retrieve from the Bing search engine. If that's the case, why does SFT RAG yield the best performance in 2 out of 3 cases with the highest retrieval ratio?
soundness: 2
strengths: 1. The proposed SmartRAG is clear and easy to understand. Some of the designs are intuitive.
2. The paper writing is relatively smooth and easy to follow.
summary: This paper proposes an integrated framework that includes multiple components of RAG. The intuition is that jointly training these components can yield optimal performance. The experiments are conducted on four benchmarks with several baselines and two backbone models. The author also conducts ablation studies to investigate SmartRAG's behavior in terms of when to retrieve, what to retrieve, and how to answer.
weaknesses: 1. Part of the setups of SmartRAG are not well-justified. Please take a look at the questions.
2. Certain experimental observations are not elaborated clearly. Please take a look at the questions.
3. The RAG baselines seem not extensive, compared with references on this topic.

---

confidence: 4
contribution: 2
initial_rating: 5
presentation: 3
questions: 1. In equation (1) where os is the concatenation of all the historical observations returned from the retriever, how do you solve the problem of LLM token limit?
2. Why [retrieve] action suffers from a 100% penalty in equation (5) of the reward design? If retrieval cost contributes to a negative reward, how about the correct answer generated from retrieved observations? Will that lead to an increase in the reward?
soundness: 3
strengths: 1. I like the idea of this paper, it consider a real problem LLM applications where the pre-trained language models and downstream RAG applications are built and optimized separately.
2. The paper is well-written, most ideas are clearly illustrated.
3. SmartRAG uses reinforcement learning methods to optimize its policy network, this is reasonable since states, actions and rewards observed in previous time steps can be used as environmental feedback instead of human feedback.
summary: The paper proposes a jointly optimization method called SmartRAG which combines the retriever, the query rewriter and the answer generator. The authors mainly use a policy network which is powered by a LLM to decide whether to retrieve or answer directly. They set up a quota limitation, the policy network can only answer the query when the quota is reached. A supervised warm-up with constructed dataset which contains direct answer, retrieved answer and observed answer is firstly applied to the policy network. This step ensures the policy network with the ability to output a [retrieve] or [answer] action. Then they design a reward at time step t of either answer or retrieve and use PPO to optimize the policy network. SmartRAG can decide the action and generate answers with/without retrieved observations.
weaknesses: 1. In the methodology part, the authors should address why there is a pre-specified quota for retrieval. RAG technicals are designed to address the lack of specific domain knowledge in the training data of a pre-trained LLM. It doesn’t make sense for the LLM-driven policy network being forced to generate the [answer] action instead of [retrieve] action when the retrieve times met the quota. I’ve never seen such a setting in industrial RAG applications. Retrieval seems necessary and provides solid answers, thus shouldn’t cause penalty even the retrieval cost of similarity search in a knowledge base do exist.
2. The optimization, however, seems not fully end-to-end. The knowledge base, which serves as a fundamental role in a RAG system, is ignored in the the design (Algorithm1 SmartRAG pipeline) and rarely mentioned in the paper. If the knowledge base is involved in the process, in methodology part, the optimization should not be tailored for specific query datasets, but remains effective even for unseen queries.

Meta-review: This paper introduces SmartRAG, a retrieval-augmented generation (RAG) framework that improves performance by jointly optimizing its components. Unlike conventional RAG methods, SmartRAG employs a policy network to dynamically determine when to retrieve information, what queries to issue, and how to synthesize responses from retrieved observations. The framework leverages reinforcement learning with environment feedback to train the system holistically, enhancing module coordination and reducing retrieval costs. Experimental results on multiple QA datasets demonstrate that SmartRAG outperforms systems with independently optimized components. The authors have added more baselines in the response, and addressed other key concerns raised by the reviewers.

Decision: Accept (Poster)