BEAVER: Structure-Aware Page Selection 기반 학습 불필요 계층적 Prompt Compression
BEAVER: A Training-Free Hierarchical Prompt Compression Method via Structure-Aware Page Selection
TL;DR Highlight
긴 문서를 페이지 단위로 구조화해서 토큰을 잘라내지 않고 압축하니, LongLLMLingua보다 26.4배 빠르면서 성능은 동등하거나 더 좋다.
Who Should Read
RAG 파이프라인이나 긴 문서 처리 시 LLM 추론 비용과 지연을 줄이고 싶은 백엔드/ML 엔지니어. 특히 128k 이상의 컨텍스트를 실시간으로 처리해야 하는 서비스 개발자.
Core Mechanics
- 토큰을 하나씩 잘라내는 기존 방식 대신, 문서를 '페이지' 단위 2D 텐서로 바꿔서 GPU 병렬처리를 극대화함
- 학습이 전혀 필요 없어서 Qwen3-0.6B부터 32B까지 어떤 모델에도 꽂으면 바로 동작 (플러그앤플레이)
- QueryPlanner가 Anchor(문서 앞부분 고정), Flow(쿼리 바로 앞 맥락), Flash(점수 높은 페이지) 세 가지를 조합해 인간의 독해 방식을 모방
- 의미(Semantic)와 키워드 일치(Lexical) 점수를 ITF(자주 나오는 단어 가중치 낮추기) 가중치와 함께 섞어 중요 페이지를 선별
- RULER 벤치마크 멀티 니들 검색에서 기존 SOTA(LLMLingua-2: 47.9점)를 거의 2배 차이로 압도 (BEAVER: 83.7점)
- Sentence Smoothing으로 선택된 페이지의 경계를 문장 단위로 확장해 잘린 문장 문제를 방지
Evidence
- 128k 토큰 컨텍스트 압축 지연: BEAVER 1.20s vs LongLLMLingua 31.7s → 26.4배 빠름 (A100 80GB 기준)
- RULER 벤치마크 평균: BEAVER 83.7점 vs LLMLingua-2 47.9점 (2위 대비 약 75% 향상), Single-Needle 100% 정확도
- LongBench Single-Doc QA: BEAVER 40.7점으로 모든 방법 중 최고 (LLMLingua-2: 29.8점, LongLLMLingua: 39.0점)
- Qwen3-0.6B에서 Dense 모델 대비 성능 보존율 98% (LLMLingua-2: 42%, LongLLMLingua: 33%)
How to Apply
- RAG 파이프라인에서 retrieved chunk들을 LLM에 넘기기 전에 BEAVER로 먼저 압축하면, 컨텍스트 윈도우 절약 + 추론 지연 단축을 동시에 달성할 수 있음
- 코드 분석이나 법률 문서처럼 키워드 정확도가 중요한 경우 λ 파라미터를 낮춰(Lexical 비중 증가) 정확한 토큰 매칭을 강화하고, 추상적 요약 태스크는 λ를 높여(Semantic 비중 증가) 의미 중심 압축으로 전환
- 기존에 LongLLMLingua나 LLMLingua-2를 쓰고 있다면, 학습된 모델 없이 Qwen3-8B 임베딩만으로 교체 가능하고 LLaMA3-8B 임베딩으로 바꿔도 성능 차이 0.3점 수준이라 백본 선택에 자유로움
Code Example
# BEAVER 압축 파이프라인 개념 예시 (https://cslikai.cn/BEAVER/ 참고)
from beaver import BEAVER
# 초기화: 백본 임베딩 모델 지정 (학습 불필요)
compressor = BEAVER(
embedding_model="Qwen/Qwen3-8B",
page_size=64, # M: 페이지당 토큰 수
fusion_weight=0.7, # γ: mean/max pooling 융합 비율
lambda_score=0.7, # λ: Semantic vs Lexical 비율 (코드/식별자 많으면 낮추기)
anchor_pages=4, # kanc: 앞부분 항상 보존할 페이지 수
flow_window=4, # wflow: 쿼리 직전 보존할 페이지 수
)
# 긴 문서 + 쿼리를 받아서 압축된 컨텍스트 반환
long_document = "...128k 토큰짜리 긴 문서..."
query = "iPhone 15 Pro의 일반 고객 가격은?"
compressed_context = compressor.compress(
context=long_document,
query=query,
token_budget=3000 # 목표 압축 토큰 수
)
# 압축된 컨텍스트를 LLM에 전달
response = llm.generate(compressed_context + "\n\n" + query)Terminology
Related Resources
Original Abstract (Expand)
The exponential expansion of context windows in LLMs has unlocked capabilities for long-document understanding but introduced severe bottlenecks in inference latency and information utilization. Existing compression methods often suffer from high training costs or semantic fragmentation due to aggressive token pruning. In this paper, we propose BEAVER, a novel training-free framework that shifts compression from linear token removal to structure-aware hierarchical selection. BEAVER maximizes hardware parallelism by mapping variable-length contexts into dense page-level tensors via dual-path pooling, and preserves discourse integrity through a hybrid planner combining semantic and lexical dual-branch selection with sentence smoothing. Extensive evaluations on four long-context benchmarks demonstrate that BEAVER achieves comparable performance to state-of-the-art (SOTA) methods like LongLLMLingua. Notably, on the RULER benchmark, BEAVER maintains high fidelity in multi-needle retrieval where baselines deteriorate. Regarding efficiency, BEAVER reduces latency by 26.4x on 128k contexts, offering a scalable solution for high-throughput applications. Our code is available at https://cslikai.cn/BEAVER/.