Unveiling and Consulting Core Experts in Retrieval-Augmented M o E -based LLM s (2024)

Abstract: Retrieval-Augmented Generation (RAG) significantly improved the ability of Large Language Models (LLMs) to solve knowledge-intensive tasks. While existing research seeks to enhance RAG performance by retrieving higher-quality documents or designing RAG-specific LLMs, the internal mechanisms within LLMs that contribute to RAG’s effectiveness remain underexplored. In this paper, we aim to investigate these internal mechanisms within the popular Mixture-of-Expert (MoE)-based LLMs and demonstrate how to improve RAG by examining expert activations in these LLMs. Our controlled experiments reveal that several core groups of experts are primarily responsible for RAG-related behaviors. The activation of these core experts can signify the model’s inclination towards external/internal knowledge and adjust its behavior. For instance, we identify core experts that can (1) indicate the sufficiency of the model’s internal knowledge, (2) assess the quality of retrieved documents, and (3) enhance the model’s ability to utilize context. Based on these findings, we propose several strategies to enhance RAG’s efficiency and effectiveness through expert activation. Experimental results across various datasets and MoE LLMs show the effectiveness of our method.

## introduction retrieval-augmented generation (rag, @xcite @xcite has shown significant achievements in enhancing large language models @xcite @xcite . by retrieving relevant documents from external knowledge bases and incorporating them into the context, rag allows llms to access query-relevant and up-to-date information, thereby improving their performance on a variety of knowledge-intensive nlp tasks @xcite . despite these achievements, rag faces many challenges @xcite . for instance, long retrieved documents introduce additional inference cost @xcite , irrelevant or erroneous retrieved documents may lead to increased hallucinations @xcite , and llms might not effectively utilize related information from context @xcite . although significant efforts have been made to improve the quality of retrieved documents @xcite and train specialized models for rag @xcite , there is limited research examining rag from the perspective of llms' internal mechanisms. in this paper, we aim at paying more attention to the internal states of retrieval-augmented llms, focusing on mixture-of-expert (moe)-based llms @xcite whose inner expert activations naturally reveal their internal states. specifically, moe-based llms comprise a set of experts that are often activated differently depending on the input context. we believe that certain core experts within the models play a vital role in managing specific types of contexts and regulating model behaviors. as a consequence, examining the function of these experts in conjunction with rag can enhance our understanding of rag's benefits and provide insights into how it can be further improved to address the aforementioned challenges. we present contrastive expert activation inspection (ceai), a simple but effective method for inspecting internal mechanisms of moe-based llms. ceai works by comparing the activation of experts given contrastive contexts, which are designed to induce opposite model behaviors. as illustrated in figure 1 , ceai helps discover three types of rag-related experts that exhibit unique activation patterns, namely cognizant experts, quality experts, and in-context experts. identified by inspecting activations when the moe-based llms generate correct versus incorrect answers, cognizant experts determine the sufficiency of the model's internal knowledge to response to user queries on its own. quality experts and in-context experts, on the other hand, assess the quality of retrieved documents and adjust the model's information utilization abilities from the context, respectively. based on these findings, we propose a trainingfree adaptive rag method by investigating and manipulating the activation of experts in moebased llms. specifically, we let the activation of cognizant experts and quality experts serve as indicators of unnecessary retrieval and low-quality documents. by avoiding unnecessary retrieval and filtering out low-quality documents, the efficiency of rag can be improved. we additionally enhance the model's ability to utilize contextual information by adjusting the activation of in-context experts. moreover, we design data recipes and metrics to enhance the comprehensiveness of adaptive rag evaluation. experimental results across various datasets show the advantages of our method. our codes are publicly available at https:// github.com/xzhou20/expert-rag . our contribution can be summarized as follows: ## application on adaptive rag recent research has increasingly focused on adaptive rag (arag), which reduces retrieval cost and enhances rag performance by enabling retrieval only when necessary @xcite . given the considerable role our identified experts fulfill in such scenarios, it is intuitive to use them to improve rag. in this section, we first introduce our method in §4.1, followed by the experimental setup in §4.2. finally, we show the effectiveness of our method in §4.3. ## conclusion in this paper, we explore the impact of expert activation within moe-based llms in the context of rag. we introduce ceai, a method that compares differences of expert activation frequency in contrasting scenarios to identify core experts responsible for specific scenarios. we identify three types of core experts for rag: cognizant experts, quality experts, and in-context experts. we further demonstrate how the activation of core experts can predict scenarios and enhance model behaviors. building on these insights, we propose an expert-based adaptive rag method and several methods for comprehensive arag evaluation. our experiments across multiple datasets confirmed the effectiveness of enhancing rag via expert activation.