Abstract
Retrieval-Augmented Language Models (RaLMs) enhance generation quality by incorporating external knowledge but suffer from significant latency in iterative settings. We present RaLMSpec, a framework that accelerates iterative RaLM serving using speculative execution. RaLMSpec predicts required documents from a fast local cache and verifies these speculations in efficient batches against a comprehensive knowledge base. Experimental results demonstrate speedups of up to 2.4x for standard RaLM serving and 7.6x for KNN-LMs, all while maintaining provable output consistency.
Introduction
RaLMs are the state-of-the-art for knowledge-intensive tasks, bridging the gap between static model weights and dynamic external information. While "one-shot" retrieval is fast, "iterative" retrieval—querying the database multiple times during generation—provides superior accuracy for complex tasks. However, the sequential nature of these retrievals creates a massive bottleneck, as the language model must pause for slow database searches. RaLMSpec addresses this by decoupling retrieval from generation through speculation.
Methodology: The RaLMSpec Framework
RaLMSpec introduces a speculative execution paradigm to the retrieval process, consisting of four primary components:
- Speculative Retrieval: The system maintains a small, high-speed local cache. Instead of querying the primary knowledge base immediately, it speculates that the necessary documents reside in this cache.
- Batched Verification: To minimize overhead, multiple speculative queries are grouped into a single batch and verified against the external database. This leverages the efficiency of modern vector databases in processing batch requests.
- Correction and Rollback: If a verification step reveals a mismatch between the cached document and the ground-truth database, the model rolls back its generation to the point of divergence and re-generates using the correct data.
- Optimal Speculation Stride Scheduler ($OS^3$): A mathematical model dynamically adjusts the "stride" (number of speculative steps) based on cache hit rates and hardware performance to maximize throughput.
Key Insights
The effectiveness of RaLMSpec stems from two observations. First, iterative RaLMs exhibit high "temporal and spatial locality," meaning the same or related documents are often accessed repeatedly, making local caching highly effective. Second, the latency of a batch retrieval is often comparable to a single retrieval; thus, batching $N$ verifications allows $N-1$ retrievals to be performed with minimal additional cost.
Evaluation and Results
RaLMSpec was evaluated on benchmarks including Wiki-QA, Natural Questions, and WikiText-103 using the full Wikipedia corpus. The framework achieved substantial performance gains:
- Standard Iterative RaLM: Speedups ranging from 1.75x to 2.39x.
- KNN-LM Serving: A massive 7.59x speedup in token-level retrieval scenarios.
Importantly, RaLMSpec is "provably correct," ensuring that the final generated text is identical to the output of a standard iterative RaLM.
Conclusion
RaLMSpec significantly reduces the serving latency of iterative RaLMs without compromising quality. By exploiting data locality and batch processing efficiency, it enables the practical deployment of high-fidelity, retrieval-heavy language models. Future work will explore multi-hop reasoning and further optimizations for asynchronous execution.
Summary updated