Skip to main content
QUICK REVIEW

[Paper Review] Accelerating Inference of Retrieval-Augmented Generation via Sparse Context Selection

Yun Zhu, Jia-Chen Gu|arXiv (Cornell University)|May 25, 2024
Domain Adaptation and Few-Shot LearningComputer Science3 citations
TL;DR

This paper proposes Sparse RAG, a method that accelerates retrieval-augmented generation by selectively attending to only the most relevant retrieved documents during decoding. By using LLMs to assess document relevance via control tokens and loading only high-quality key-value caches, Sparse RAG reduces latency and improves generation quality without sacrificing performance, achieving state-of-the-art efficiency and effectiveness across short- and long-form tasks.

ABSTRACT

Large language models (LLMs) augmented with retrieval exhibit robust performance and extensive versatility by incorporating external contexts. However, the input length grows linearly in the number of retrieved documents, causing a dramatic increase in latency. In this paper, we propose a novel paradigm named Sparse RAG, which seeks to cut computation costs through sparsity. Specifically, Sparse RAG encodes retrieved documents in parallel, which eliminates latency introduced by long-range attention of retrieved documents. Then, LLMs selectively decode the output by only attending to highly relevant caches auto-regressively, which are chosen via prompting LLMs with special control tokens. It is notable that Sparse RAG combines the assessment of each individual document and the generation of the response into a single process. The designed sparse mechanism in a RAG system can facilitate the reduction of the number of documents loaded during decoding for accelerating the inference of the RAG system. Additionally, filtering out undesirable contexts enhances the model's focus on relevant context, inherently improving its generation quality. Evaluation results of two datasets show that Sparse RAG can strike an optimal balance between generation quality and computational efficiency, demonstrating its generalizability across both short- and long-form generation tasks.

Motivation & Objective

  • To address the high inference latency in retrieval-augmented generation (RAG) caused by long input sequences from multiple retrieved documents.
  • To improve computational efficiency without degrading generation quality in both short- and long-form generation tasks.
  • To eliminate the need for external classifiers or separate retrieval ranking models by integrating context assessment and generation into a single, unified process.
  • To enable efficient, low-latency inference on resource-constrained devices by reducing key-value cache loading during decoding.

Proposed method

  • Sparse RAG uses a two-stage process: massive pre-filling, where all retrieved documents are encoded in parallel to generate full key-value caches, and selective decoding, where only relevant documents are attended to.
  • It employs special control tokens to prompt the LLM to assess each retrieved document's relevance and decide whether to include it in the decoding phase.
  • The model dynamically drops low-quality or irrelevant documents during decoding, reducing the number of key-value cache loads and lowering memory and computation overhead.
  • The method integrates document relevance assessment and response generation into a single autoregressive process, avoiding the need for separate ranking models.
  • It leverages decoder-only LLM architectures natively, making it compatible with modern LLMs without architectural modifications.
  • The approach is designed to be agnostic to foundation model size, supporting both small (e.g., Gemini XS) and large (e.g., Gemini XXS) models.
Figure 1 : An overview of Sparse RAG at inference. Each of the retrieved documents will be assessed by LLMs to decide whether to keep or drop by estimating a relevance score. Then, load the documents that are considered to keep for generation.
Figure 1 : An overview of Sparse RAG at inference. Each of the retrieved documents will be assessed by LLMs to decide whether to keep or drop by estimating a relevance score. Then, load the documents that are considered to keep for generation.

Experimental results

Research questions

  • RQ1Can a sparse attention mechanism in RAG reduce decoding latency while maintaining or improving generation quality?
  • RQ2How does integrating relevance assessment and generation into a single process affect inference efficiency and output quality?
  • RQ3To what extent can Sparse RAG reduce key-value cache loading without degrading performance across different model sizes?
  • RQ4What is the upper bound performance of Sparse RAG when provided with perfect per-document relevance labels?
  • RQ5How does Sparse RAG compare to dense-RAG and PCW-RAG in terms of latency and generation quality across diverse generation tasks?

Key findings

  • Sparse RAG achieved a 52% to over 55% reduction in end-to-end latency compared to baseline dense-RAG when generating responses of varying lengths.
  • On the PopQA dataset, Sparse RAG achieved 68.26 EM and 72.26 F1 with only 6.27 key-value cache loads on the Gemini XS model, outperforming both RAG and PCW-RAG in both quality and efficiency.
  • On the Biography dataset, Sparse RAG achieved 67.17 EM and 71.16 F1 on the Gemini XXS model, demonstrating consistent gains across model sizes.
  • When provided with golden per-context labels, Sparse RAG improved to 26.76 F1 and 21.16 DS, indicating strong potential under ideal assessment conditions.
  • The method reduced computational overhead significantly, with tokens per second (t/s) performance improving substantially compared to dense-RAG, especially with larger context windows.
  • Sparse RAG maintained high performance across both short- and long-form generation tasks, proving its generalizability.
(a) Decoding speed with different number of memories
(a) Decoding speed with different number of memories

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.