arXiv(opens in a new tab)cs.LGJun 2024Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2406.00456

Mix-of-Granularity: Optimize the Chunking Granularity for Retrieval-Augmented Generation

Zijie Zhong, Hanwen Liu, Xiaoya Cui, Xiaofan Zhang, Zengchang Qin

Zijie Zhong

Shanghai AI Laboratory

zhongzijie@pjlab.org.cn

Hanwen Liu

Beihang University

liuhwen@buaa.edu.cn

Xiaoya Cui

Beihang University

xiaoya@buaa.edu.cn

Xiaofan Zhang ∗^{*}

Shanghai AI Laboratory

zhangxiaofan@pjlab.org.cn

Zengchang Qin ∗^{*}

Beihang University, theSight Technology

zcqin@buaa.edu.cn

Abstract

Integrating information from various reference databases is a major challenge for Retrieval-Augmented Generation (RAG) systems because each knowledge source adopts a unique data structure and follows different conventions. Retrieving from multiple knowledge sources with one fixed strategy usually leads to under-exploitation of information. To mitigate this drawback, inspired by Mix-of-Expert, we introduce Mix-of-Granularity (MoG), a method that dynamically determines the optimal granularity of a knowledge source based on input queries using a router. The router is efficiently trained with a newly proposed loss function employing soft labels. We further extend MoG to MoG-Graph (MoGG), where reference documents are pre-processed as graphs, enabling the retrieval of distantly situated snippets. Experiments demonstrate that MoG and MoGG effectively predict optimal granularity levels, significantly enhancing the performance of the RAG system in downstream tasks. The code of both MoG and MoGG are released in https://github.com/ZGChung/Mix-of-Granularity.

1 Introduction

Retrieval-Augmented Generation (RAG) (Lewis et al., 2020) has become a popular method for enhancing Large Language Models (LLMs). The core concept of RAG involves retrieving relevant information from external knowledge bases to provide additional context to the LLM, enabling it to generate more precise and grounded responses. RAG offers a promising and practical solution to mitigate LLMs' hallucinations because (1) it can be applied to any LLM, even those accessible only via APIs, and (2) the reference information is easy to modify or update. Many LLM-based products are supported by RAG systems, with examples spanning various industries such as customer service, advertising and marketing, education and e-learning, healthcare, and e-commerce and retailing (Khan, 2023; Xiong et al., 2024; Soman and Roychowdhury, 2024; Ke et al., 2024; Radeva et al., 2024).

The quality of the retrieved snippets is crucial for the final generation, consequently, much research has focused on the retrieval phase. Currently, most RAG systems follow the Dual-Encoder Architecture (Dong et al., 2022) (DEA) paradigm, in which the reference documents are divided into small snippets (chunks), encoded by specific encoders, and then stored in the vector database (e.g. FAISS (Johnson et al., 2017) or Neo4j (Company, 2012)) as embeddings. Thanks to its scalability, the DEA paradigm shows great potential for connecting LLMs with knowledge database of different formats, including knowledge graphs, textbooks, or Wikipedia articles.

Optimizing the chunk size of the reference knowledge database is essential for enhancing the precision and recall during the retrieval phase. However, this optimization presents significant challenges in the implementation of RAG systems for two primary reasons: (1) An optimal chunking size needs to be determined for each knowledge database due to their dissimilar data structures and information densities. For example, the optimal chunking size for medical textbooks is longer than the one for Medical Knowledge Graph Database (MKGD like Hetionet (Himmelstein et al., 2017)), as Medical textbooks typically contain lengthy passages, while an MKGD consists of entities represented by shorter terms. (2) Even within a single knowledge database, using a uniform chunking size for all input queries can yield suboptimal retrieval results, as the queries themselves exhibit varying levels of granularity. As shown in Figure 1), when the user asks about one disease (fine-grained question), chunking the reference document in finer granularity is better; whereas, when the user asks

∗^{*}Corresponding authors

Figure

Figure 1: MoG automatically selects the optimal granularity when extracting information from the reference database (scenarios 1 and 2), achieving both high pertinence and coverage. When relevant information is dispersed across distant sections (scenario 3), the reference documents are pre-processed as graph, then MoGG is applied to retrieve these separate snippets from the best hopping range.

for broader information (coarse-grained question), a more coarse granularity is preferred. In practice, the optimal "uniform chunking size" is determined through parameter tuning, which is not only tedious but also does not guarantee high precision and recall.

Therefore, the community calls for a method to dynamically determine the optimal chunking size, for which we propose the Mix-of-Granularity (MoG). We draw inspiration from Mix-of-Experts (Chen et al., 2022), which is a machine learning architecture that dynamically selects the most pertinent “expert sub-network” for each input token using a router module. Similarly, MoG involves leveraging a router to select the best granularity levels from which the reference snippets are extracted.

Even with this flexibility newly introduced, MoG still has difficulty dealing with broader queries that require distantly situated snippets, e.g. snippets stored in different knowledge databases. In such cases (cross-document question in Figure 1), adjusting only the granularity is not helpful because the necessary information is so distantly located that it can never be covered by a reasonably large chunking window. To better answer these broader queries, we extend MoG to MoG-Graph (MoGG). In MoGG, the reference documents are pre-processed as a graph, allowing relevant snippets to be included as neighbors of each other, regardless of their distance in the original databases. This extension further improves the performance of cross-source retrieval.

When training MoG(G) under the supervised learning setting, the backward propagation is blocked by the top-k selection at the end of the retrieval phase, which is a common practice in most RAG systems. To solve it, we introduce a loss function using soft labels. Soft labels are approximate training signals generated using offline algorithms or models like TF-IDF (Ramos, 2003) or RoBERTa (Liu et al., 2019). With the soft labels, the top-k selection is excluded from the training process, thus the issue of backward propagation is circumvented and the training is accelerated.

In conclusion, the main contributions of this work are:

(1) We propose MoG, which dynamically determines the optimal granularity level for retrieval with the help of a router, achieving a balanced trade-off between precision and recall.

(2) We extend MoG to MoGG by reorganizing the reference document in the form of a graph, thereby further improving the quality of cross-source retrieval involving multiple knowledge databases.

(3) We introduce a loss function utilizing soft labels to overcome the challenges associated with training with top-k selection.

References (1)

  • The router is trained with soft labels, which are approximate training signals that can only teach the model to distinguish the 1st and 2nd optimal granularity level from the rest