Skip to main content
QUICK REVIEW

[Paper Review] Reinforcement Learning for Optimizing RAG for Domain Chatbots

Mandar Kulkarni, Praveen Tangarajan|arXiv (Cornell University)|Jan 10, 2024
Topic ModelingComputer Science18 citations
TL;DR

The paper develops a policy-based RL approach external to a RAG pipeline to decide whether to fetch FAQ context, achieving ~31% token savings with GPT-4 evaluation and slight accuracy gains on a domain FAQ chatbot. It also shows in-house embeddings outperform public models for retrieval and OOD detection.

ABSTRACT

With the advent of Large Language Models (LLM), conversational assistants have become prevalent for domain use cases. LLMs acquire the ability to contextual question answering through training, and Retrieval Augmented Generation (RAG) further enables the bot to answer domain-specific questions. This paper describes a RAG-based approach for building a chatbot that answers user's queries using Frequently Asked Questions (FAQ) data. We train an in-house retrieval embedding model using infoNCE loss, and experimental results demonstrate that the in-house model works significantly better than the well-known general-purpose public embedding model, both in terms of retrieval accuracy and Out-of-Domain (OOD) query detection. As an LLM, we use an open API-based paid ChatGPT model. We noticed that a previously retrieved-context could be used to generate an answer for specific patterns/sequences of queries (e.g., follow-up queries). Hence, there is a scope to optimize the number of LLM tokens and cost. Assuming a fixed retrieval model and an LLM, we optimize the number of LLM tokens using Reinforcement Learning (RL). Specifically, we propose a policy-based model external to the RAG, which interacts with the RAG pipeline through policy actions and updates the policy to optimize the cost. The policy model can perform two actions: to fetch FAQ context or skip retrieval. We use the open API-based GPT-4 as the reward model. We then train a policy model using policy gradient on multiple training chat sessions. As a policy model, we experimented with a public gpt-2 model and an in-house BERT model. With the proposed RL-based optimization combined with similarity threshold, we are able to achieve significant cost savings while getting a slightly improved accuracy. Though we demonstrate results for the FAQ chatbot, the proposed RL approach is generic and can be experimented with any existing RAG pipeline.

Motivation & Objective

  • Motivate efficient domain-specific chatbots by reducing LLM token costs in RAG setups.
  • Show that an in-house embedding model with infoNCE outperforms public embeddings for domain FAQ retrieval and OOD detection.
  • Propose and evaluate a policy-gradient RL agent that decides when to fetch FAQ context to minimize costs.
  • Demonstrate that combining RL-based context selection with a similarity threshold yields substantial token savings without sacrificing accuracy.

Proposed method

  • Train an in-house embedding model with infoNCE loss for domain FAQ retrieval.
  • Compare in-house embedding with public models on top-1/top-3 retrieval accuracy for English and Hinglish queries.
  • Use GPT-4 as a reward evaluator to convert Good/Bad ratings into numeric rewards for policy gradient training.
  • Develop a policy network external to RAG that chooses FETCH or NO_FETCH actions based on state (previous queries, actions, and current query).
  • Train the policy with policy gradient and entropy regularization using trajectories of (state, action, reward).
  • Combine the RL policy with a similarity-threshold (SimThr) to further reduce token usage.
Figure 1: Proposed policy agent based architecture for optimizing RAG for domain chatbots.
Figure 1: Proposed policy agent based architecture for optimizing RAG for domain chatbots.

Experimental results

Research questions

  • RQ1Can an external policy model learn when to fetch FAQ context to reduce LLM token usage without harming answer quality?
  • RQ2Does an in-house domain-tuned embedding model improve retrieval accuracy and OOD detection over public embeddings?
  • RQ3How does RL-based context selection interact with a similarity-threshold rule to optimize RAG costs?
  • RQ4What is the impact of using GPT-4 as an automatic evaluator for training a policy in a RAG setting?

Key findings

  • The in-house embedding model trained with infoNCE achieves higher top-1/top-3 accuracy than public e5-base-v2 for English and Hinglish queries.
  • The in-house model yields better in-domain and OOD discrimination, enabling a similarity threshold to selectively skip retrieval.
  • RL-based policy external to RAG can reduce token usage by ~31% on a test session of 91 queries when combined with a similarity threshold, with slightly improved accuracy.
  • GPT-4 ratings can be transformed into rewards to drive policy gradient updates for action selection.
  • Using GPT-2 as policy model also yields token savings (~25%), indicating the approach generalizes across policy architectures.
  • Different reward shaping can influence token savings (e.g., ~30% with alternate shaping).

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.