Large Language Models (LLMs) have demonstrated remarkable capabilities in leveraging extensive external knowledge to enhance responses in multi-turn and agentic applications, such as retrieval-augmented generation (RAG). However, processing long-context inputs introduces significant system latency and demands substantial memory for the key-value cache, resulting in reduced throughput and a fundamental trade-off between knowledge enrichment and system efficiency. While minimizing latency for long-context inputs is a primary objective for LLMs, we contend that RAG require specialized consideration. In RAG, much of the LLM context consists of concatenated passages from retrieval, with only a small subset directly relevant to the query. These passages often exhibit low semantic similarity due to diversity or deduplication during re-ranking, leading to block-diagonal attention patterns that differ from those in standard LLM generation tasks. Based on this observation, we argue that most computations over the RAG context during decoding are unnecessary and can be eliminated with minimal impact on performance. To this end, we propose REFRAG, an efficient decoding framework that compresses, senses, and expands to improve latency in RAG applications. By exploiting the sparsity structure, we demonstrate a 30.85 the time-to-first-token acceleration (3.75 improvement to previous work) without loss in perplexity. In addition, our optimization framework for large context enables REFRAG to extend the context size of LLMs by 16. We provide rigorous validation of REFRAG across diverse long-context tasks, including RAG, multi-turn conversations, and long document summarization, spanning a wide range of datasets. Experimental results confirm that REFRAG delivers substantial speedup with no loss in accuracy compared to LLaMA models and other state-of-the-art baselines across various context sizes.
대규모 언어 모델(LLMs)은 검색 증강 생성(RAG)과 같은 다중 턴 대화 및 에이전트 애플리케이션에서 외부 지식을 활용하여 응답을 강화하는 뛰어난 능력을 보여줍니다. 그러나 긴 컨텍스트 입력 처리는 상당한 시스템 지연을 초래하며 키-값 캐시를 위한 대량의 메모리가 필요하여 처리량 감소 및 지식 풍부성과 시스템 효율성 간의 근본적인 트레이드오프를 야기합니다. 본 논문은 압축, 인식, 확장을 통해 RAG 애플리케이션의 지연을 개선하는 효율적인 디코딩 프레임워크인 REFRAG를 제안합니다. 주의 희소성 구조를 활용하여 첫 단어까지의 시간(TTFT) 지연에서 30.85배 가속화(이전 연구 대비 3.75배 향상)를 달성하면서도 혼동도 손실이 없습니다. 또한 이 최적화 프레임워크는 REFRAG가 LLMs의 컨텍스트 크기를 16배 확장할 수 있게 합니다.
T개의 토큰을 포함하는 입력 시퀀스 x₁, x₂, ..., xₜ가 주어졌을 때, 처음 q개의 토큰은 주요 입력(예: 질문), 나머지 s개의 토큰은 컨텍스트(예: 검색된 단락)이며, q + s = T를 만족합니다. 목표는 TTFT 지연 및 메모리 사용을 최소화하면서 효율적으로 응답을 생성하는 것입니다.