Table of Contents
Fetching ...

Semantic Caching for Low-Cost LLM Serving: From Offline Learning to Online Adaptation

Xutong Liu, Baran Atalar, Xiangxiang Dai, Jinhang Zuo, Siwei Wang, John C. S. Lui, Wei Chen, Carlee Joe-Wong

TL;DR

This paper forms both offline optimization and online learning variants of the problem, and develops provably efficient algorithms with state-of-the-art guarantees for semantic cache eviction under unknown query and cost distributions.

Abstract

Large Language Models (LLMs) are revolutionizing how users interact with information systems, yet their high inference cost poses serious scalability and sustainability challenges. Caching inference responses, allowing them to be retrieved without another forward pass through the LLM, has emerged as one possible solution. Traditional exact-match caching, however, overlooks the semantic similarity between queries, leading to unnecessary recomputation. Semantic caching addresses this by retrieving responses based on semantic similarity, but introduces a fundamentally different cache eviction problem: one must account for mismatch costs between incoming queries and cached responses. Moreover, key system parameters, such as query arrival probabilities and serving costs, are often unknown and must be learned over time. Existing semantic caching methods are largely ad-hoc, lacking theoretical foundations and unable to adapt to real-world uncertainty. In this paper, we present a principled, learning-based framework for semantic cache eviction under unknown query and cost distributions. We formulate both offline optimization and online learning variants of the problem, and develop provably efficient algorithms with state-of-the-art guarantees. We also evaluate our framework on a synthetic dataset, showing that our proposed algorithms perform matching or superior performance compared with baselines.

Semantic Caching for Low-Cost LLM Serving: From Offline Learning to Online Adaptation

TL;DR

This paper forms both offline optimization and online learning variants of the problem, and develops provably efficient algorithms with state-of-the-art guarantees for semantic cache eviction under unknown query and cost distributions.

Abstract

Large Language Models (LLMs) are revolutionizing how users interact with information systems, yet their high inference cost poses serious scalability and sustainability challenges. Caching inference responses, allowing them to be retrieved without another forward pass through the LLM, has emerged as one possible solution. Traditional exact-match caching, however, overlooks the semantic similarity between queries, leading to unnecessary recomputation. Semantic caching addresses this by retrieving responses based on semantic similarity, but introduces a fundamentally different cache eviction problem: one must account for mismatch costs between incoming queries and cached responses. Moreover, key system parameters, such as query arrival probabilities and serving costs, are often unknown and must be learned over time. Existing semantic caching methods are largely ad-hoc, lacking theoretical foundations and unable to adapt to real-world uncertainty. In this paper, we present a principled, learning-based framework for semantic cache eviction under unknown query and cost distributions. We formulate both offline optimization and online learning variants of the problem, and develop provably efficient algorithms with state-of-the-art guarantees. We also evaluate our framework on a synthetic dataset, showing that our proposed algorithms perform matching or superior performance compared with baselines.

Paper Structure

This paper contains 20 sections, 8 equations, 2 figures, 5 algorithms.

Figures (2)

  • Figure 1: Semantic Caching System for Low-Cost LLM Serving
  • Figure 2: (a) Variation of the loss with the cache size $k$ for a fixed set of queries with $m=20$ (b) Variation of the final suboptimality gap with the stream length in the offline setting, we test the performance of Algorithm \ref{['alg:CUCB-SC']} and its offline variant CLCB-SC (c) Variation of the average regret with the number of rounds $t$ for the online setting. CUCB-SC and CLCB-SC are the online variants of Algorithm \ref{['alg:CUCB-SC']} and its LCB variant (d) Ablation study on the final average regret's change with the cache size $k$ in the online setting (e) Ablation study on the final average regret's change with the number of distinct queries $m$ in the online setting (f) Table showing the mean number of switches and runtime of the algorithms in the online setting

Theorems & Definitions (10)

  • proof : Proof of \ref{['thm:LLM_cache_main_offline']}
  • proof : Proof of \ref{['thm:online']}
  • proof : Proof of \ref{['lem:NP']}
  • proof : Proof of \ref{['lem:supermodular']}
  • proof : Proof of \ref{['thm:approx']}
  • proof : Proof of \ref{['lem:offline_concen']}
  • proof : Proof of \ref{['lem:offline_smooth']}
  • proof : Proof of \ref{['lem:online_concen']}
  • proof : Proof of \ref{['lem:online_smooth']}
  • proof : Proof of \ref{['lem:online_n_switch']}