---
title: 'LLM Cache Bandit: Knapsack & Feedback'
url: https://www.emergentmind.com/topics/llm-cache-bandit-problem
type: topic
---

# LLM Cache Bandit: Knapsack & Feedback

The **LLM cache bandit problem** denotes a family of online decision problems in which an LLM-serving system must manage a finite cache under uncertain demand, selective feedback, and resource constraints so as to reduce cumulative inference cost, latency, or stale-answer loss. In the most explicit recent formulation, the cache stores query–response pairs, query arrivals are stochastic, and heterogeneous prompt/response lengths transform cache selection from a fixed-cardinality ranking problem into a knapsack-constrained bandit problem with reverse feedback and restricted cache-update dynamics [2509.15515]. Closely related formulations extend the same bandit lens to semantic retrieval buffers with switching costs, delayed-feedback replacement, and active cache synchronization [2607.00394][2009.11330][2002.12014].

## 1. Canonical formulation

A precise formulation considers a finite query universe
\[
\mathcal{Q}=\{q_1,\dots,q_N\},
\]
with one query \(q_t\) arriving at each round \(t\in\{1,\dots,T\}\), sampled i.i.d. from an unknown distribution \(P\). Each query \(q\) has input length \(L(q)\), output length \(A(q)\), and cache footprint
\[
S(q)=L(q)+A(q).
\]
A feasible cache \(\mathcal{M}\) must satisfy the capacity constraint
\[
\mathfrak{J}=\left\{\mathcal{M}\middle|\sum_{q\in\mathcal{M}} S(q)\le M\right\}.
\]
If \(q_t\in\mathcal{M}_t\), the system returns the stored answer at zero inference cost; otherwise the LLM is invoked and incurs a random cost
\[
C(q)=C^*(q)+\epsilon_q,
\]
where \(C^*(q)=\mathbb{E}[C(q)]\) is the unknown expected inference cost and \(\epsilon_q\) is zero-mean sub-Gaussian noise, with \(C(q)\in[c_1,c_2]\) [2509.15515].

For a fixed cache \(\mathcal{M}\), the expected uncached cost is
\[
cost(\mathcal{M})=\sum_{q\in\mathcal{Q}} C^*(q)P(q)\mathbb{I}\{q\notin\mathcal{M}\}.
\]
Equivalently, the optimal static cache is
\[
\mathcal{M}^*=\argmax_{\mathcal{M}\in\mathfrak{J}}\sum_{q\in\mathcal{M}} C^*(q)P(q).
\]
The regret of an online policy relative to this oracle is
\[
Reg(T)=\mathbb{E}\left[\sum_{t=1}^{T} C(q_t)\left(\mathbb{I}\{q_t\in\mathcal{M}^*\}-\mathbb{I}\{q_t\in\mathcal{M}_t\}\right)\right].
\]
This formulation makes the problem a bandit problem because cache actions determine what is observed: on a hit, no fresh inference cost is revealed; on a miss, the learner observes the realized cost, the answer, and the size. The feedback is therefore “reverse” relative to standard bandits: observation occurs on misses, not on selected cached items [2509.15515].

A further constraint distinguishes the model from standard combinatorial bandits. Because a response is unavailable once evicted, the next cache can only be formed from the current cache plus the newly arrived query,
\[
\mathcal{M}_{t+1}\subseteq \mathcal{M}_t\cup\{q_t\}.
\]
The learner may retain statistics for evicted items, but cannot instantly reinsert them without waiting for their reappearance. This makes the action space history-dependent even when the benchmark is a static cache [2509.15515].

## 2. Query heterogeneity and the knapsack turn

The central revision in "LLM Cache Bandit Revisited: Addressing Query Heterogeneity for Cost-Effective LLM Inference" is that variable query sizes qualitatively change the problem [2509.15515]. Under uniform size, cache optimization reduces to selecting the top-\(K\) queries by \(C^*(q)P(q)\). Once sizes vary, the offline optimum becomes a \(0\)-\(1\) knapsack:
\[
\mathcal{M}^*=\argmax_{\mathcal{M}\in\mathfrak{J}}\sum_{q\in\mathcal{M}} C^*(q)P(q), \qquad
\mathfrak{J}=\left\{\mathcal{M}\middle|\sum_{q\in\mathcal{M}} S(q)\le M\right\}.
\]
A large query may force eviction of several small ones, while several small high-value queries may dominate one large expensive query. The optimization difficulty and the statistical difficulty therefore become coupled through a value-to-size tradeoff rather than a simple ranking [2509.15515].

To capture this heterogeneous-cardinality effect, the paper defines a valid cache set \(\mathfrak{V}\) as one that is as full as possible and introduces
\[
l_{max}=\max_{\mathcal{M}\in\mathfrak{V}}|\mathcal{M}|,\qquad
l_{min}=\min_{\mathcal{M}\in\mathfrak{V}}|\mathcal{M}|.
\]
These replace the fixed cardinality parameter that exists in the uniform-size case. The resulting complexity term is
\[
l(M,\mathcal{Q})=\min\{l_{max},N-l_{min}\},
\]
which enters both the problem-dependent and problem-independent regret bounds [2509.15515].

The proposed algorithm, **VSOCB** (Variable Size Online Cache Bandits), combines lower-confidence estimation, an exact knapsack oracle, an accumulation-based oracle invocation schedule, and a recommend-and-wait mechanism. It tracks total arrivals
\[
T_t^{(q)}(q)=\sum_{s=1}^{t}\mathbb{I}\{q_s=q\},
\]
total cache misses
\[
T_t^{(c)}(q)=\sum_{s=1}^{t}\mathbb{I}\{q_s\notin\mathcal{M}_s,\ q_s=q\},
\]
and accumulated observed miss cost
\[
\widetilde{C}_t(q)=\sum_{s=1}^{t}\mathbb{I}\{q_s\notin\mathcal{M}_s,\ q_s=q\}C_t(q).
\]
It then uses lower-confidence estimates for both cost and popularity, deliberately making long-unobserved cached items look less certain and therefore easier to evict, which induces exploration through cache turnover [2509.15515].

Oracle calls are not made every round. Instead, the algorithm invokes the knapsack oracle only when enough new information has accumulated, namely when either a miss count has grown multiplicatively or enough rounds have elapsed:
\[
T_t^{(c)}(q_t)\ge (1+\alpha)T_{t-1}^{(r)}(q_t)
\quad\text{or}\quad
t\ge (1+\alpha)T_{t-1}.
\]
This accumulation schedule is the paper’s main computational–statistical balancing device. It yields only
\[
O(N\log T)
\]
oracle calls while preserving regret guarantees [2509.15515].

With \(\delta=1/T\), the exact-oracle analysis gives
\[
Reg(T)\le \widetilde{O}\left(\sum_{q\in\mathcal{M}^*}\frac{P(q)N\,l(M,\mathcal{Q})}{\Delta_q}\right)
\]
and
\[
Reg(T)\le \widetilde{O}\left(\sqrt{N\,l(M,\mathcal{Q})\,T}\right).
\]
Since \(l(M,\mathcal{Q})\le M\), this implies
\[
Reg(T)\le \widetilde{O}(\sqrt{MNT}),
\]
improving the earlier \(\widetilde{O}(MN\sqrt{T})\) guarantee cited by the paper for the uniform-size Berkeley line of work. On real data from OpenAssistant with FastChat-T5-3B, using \(100\) distinct queries, \(20{,}000\) rounds, and cache size \(100\), the reported total costs are \(4162.8\) for the Berkeley-style baseline and \(3614.2\) for VSOCB, about a \(13\%\) reduction, summarized in the abstract as “approximately \(12\%\)” [2509.15515].

## 3. Alternative feedback models: delayed consequences and stale-state costs

The exact query–answer cache model is only one member of a broader family of cache bandit problems. A conceptually important precursor is "Cache Replacement as a MAB with Delayed Feedback and Decaying Costs" [2009.11330]. There the learner does not choose cache entries directly; instead each arm is a replacement policy, and the consequence of an eviction is revealed only if the evicted item is requested again later. If an action chosen at time \(t'\) is penalized at time \(t\), the delay is \(d=t-t'\), and the estimated cost is scaled as
\[
\hat{x}_{i_t}(t)=\frac{x_{i_t}(t)}{d\,p_{i_t}(t)},
\]
with feedback beyond a threshold \(m\) treated as zero. The resulting EXP4-DFDC algorithm satisfies
\[
R_{\text{EXP4-DFDC}}(T)\le 2\eta T+\frac{K\ln N}{\eta},
\]
and with
\[
\eta_{OPT}=\min\left(1,\sqrt{\frac{K\ln N}{2T}}\right),
\]
achieves \(O(\sqrt{KT\ln N})\) regret [2009.11330]. For LLM systems, the relevance is that the cost of evicting a prompt-result pair, a semantic memory, or a reusable state block is often realized only on later reuse.

A different generalization appears in "Online Learning for Active Cache Synchronization" [2002.12014]. Its **synchronization bandit** model assumes that all arms generate costs at all times, but the learner observes an arm’s instantaneous cost only when it plays that arm. Each arm \(k\) has age state
\[
\tau_k(t),
\]
mean instantaneous cost \(\overline c_k(\tau)\), and cumulative expected cost
\[
\overline C_k(\tau')=\int_0^{\tau'} \overline c_k(\tau)\,d\tau.
\]
Periodic synchronization at rate vector \(\mathbf r\) induces cost
\[
J(\mathbf r)=\frac{1}{K}\sum_{k=1}^{K} r_k\,\overline C_k\!\left(\frac{1}{r_k}\right),
\]
subject to a refresh-budget constraint
\[
\mathcal K=\left\{\mathbf r'\in[r_{\min},r_{\max}]^K\mid \|\mathbf r'\|_1=B\right\}.
\]
The MirrorSync algorithm uses random probe plays to build an unbiased gradient estimator and then applies mirror descent; its adversarial regret is
\[
O(T^{2/3})
\]
[2002.12014]. This formulation is directly aligned with stale retrieval/document caches, tool-result caches, and other persistent LLM-serving artifacts whose quality degrades as external state changes.

Together, these models show that “cache bandit” need not mean only popularity learning for exact-match hits. It can also mean learning under delayed eviction feedback, or learning refresh schedules for latent stale costs. The choice of model depends on whether the dominant uncertainty concerns reuse, delayed harm, or exogenous drift.

## 4. Semantic retrieval buffers and predictive cache population

The semantic-retrieval variant is formulated most clearly in "When Classic Cache Policies Fail: Learning-Augmented Replacement for Semantic Retrieval Buffers" [2607.00394]. There the cache state is
\[
S_t\subseteq\mathcal U,\qquad |S_t|\le K,
\]
retrieval is by embedding similarity, and the loss is continuous rather than binary:
\[
\ell_t(S_t)=1-\text{F1}(q_t,S_t).
\]
The total objective includes both miss cost and switching cost,
\[
\text{COST}(\pi,T)=\sum_{t=1}^{T}\ell_t(S_t^\pi)+\lambda\cdot N^\pi.
\]
The paper’s main empirical finding is that on semantic workloads, **LRU** and **LFU** consistently underperform the naive **FIFO** baseline because temporal locality and frequency concentration are weak. The proposed **SOLAR** framework separates modification timing from eviction content: modification is triggered by regret accumulation, while eviction uses Bayesian online learning with Beta posteriors and Thompson-style sampling. The paper reports about a **17\% modification rate**, proves a constant competitive ratio
\[
\text{CR}(\text{SOLAR})\le 3,
\]
independent of cache size and horizon under bounded stale advantage, and gives an eviction regret bound
\[
O(\sqrt{KT\log T}),
\]
matching the \(\Omega(\sqrt{KT})\) lower bound up to logarithmic factors [2607.00394]. This is a genuine LLM cache bandit formulation when the cache stores semantic memories rather than exact query–answer pairs.

A complementary but non-bandit direction is "InstCache: A Predictive Cache for LLM Serving" [2411.13820]. InstCache is not an online learning method; it is an offline predictive cache populated by likely future instructions generated from an instruction-aligned LM. The key selection rule is
\[
C=\{s:\text{NLL}(s,\text{LM})\le \sigma,\ s\in S\},
\]
and the hit-rate estimate is based on the NLL CDF. On LMSys, InstCache reports **51.34\% hit rate**, about **2x speedup**, and approximately **4.5GB** memory for **4,253,981 instruction-answer pairs** [2411.13820]. Within the LLM cache bandit literature, its role is best understood as an offline predictive prior: it supplies a model-based notion of future request likelihood, but it does not perform online exploration, regret minimization, or dynamic replacement.

The contrast between SOLAR and InstCache is revealing. SOLAR assumes online semantic retrieval with partial implicit feedback and switching costs. InstCache assumes that a strong predictive model can pre-populate an exact-match cache offline. The former is a bandit problem; the latter is supervised predictive caching. Both are relevant because practical LLM systems often need both an offline prior over likely requests and an online controller for nonstationarity and capacity pressure.

## 5. Boundary with neighboring non-bandit cache-control problems

A recurring misconception is to treat every LLM cache-management problem as a bandit. Several influential recent papers instead formulate optimization or scheduling problems with known structure and no exploration component. "XKV: Personalized KV Cache Memory Reduction for Long-Context LLM Inference" assigns per-layer KV budgets by solving a combinatorial allocation problem over retained-importance ratios; it reports **61.6\%** average KV memory reduction, **2.1x** computational efficiency improvement, and up to **5.2x** throughput increase, but it is an offline profiling-and-allocation method rather than a bandit [2412.05896]. "Reformulating KV Cache Eviction Problem for Long-Context LLM Inference" introduces **LaProx**, an output-aware token-importance score
\[
p_i \propto \|\mathbf A[:,i]\|_2\,\|\mathbf V W_O[i,:]\|_2,
\]
and shows that model performance can be maintained with only **5\%** of the KV cache while achieving up to **2\times** accuracy-loss reduction under extreme compression; again, the method is a deterministic scoring rule, not an online learner [2605.07234].

Serving-time scheduling problems make the distinction even sharper. "Apt-Serve" formulates per-iteration scheduling with a hybrid KV/hidden cache as an NP-hard knapsack-like optimization and reports up to **8.8x** improvement in effective throughput over baseline serving systems [2504.07494]. "CacheFlow" formulates KV restoration as a 3D parallel scheduling problem across tokens, layers, and GPUs, and reports **10\%–62\%** TTFT reduction [2604.25080]. "Low-Latency Edge LLM Handover via Joint KV Cache Transfer and Token Prefill" optimizes a split between KV transfer and target-side prefill, proving that the optimal split equalizes prefill and transfer delay whenever possible; it reports up to **3.1\times** and **3.7\times** improvement over pure transfer and pure prefill baselines [2603.28018]. These are online systems problems with constrained resources, but they are not bandits unless uncertainty and exploration are made explicit.

The practical implication is that the LLM cache bandit problem occupies only one region of a larger design space. When the main difficulty is unknown popularity, delayed reuse, semantic hit quality, or unobserved staleness, bandit formulations are natural. When the main difficulty is precedence-constrained restoration, per-layer allocation under profiled costs, or deterministic batch scheduling, direct optimization may be the more faithful abstraction.

## 6. Limitations, misconceptions, and open directions

The current literature makes several limitations explicit. In the heterogeneous query-answer formulation, the analysis assumes a fixed query distribution \(P\), known sizes once a query has been observed, and regret against the best static cache rather than a dynamic benchmark; experiments are also modest in scale [2509.15515]. In semantic retrieval buffers, the strongest guarantees rely on bounded stale advantage and stylized stochastic utility models, while the empirical regime is nonstationary and feedback is only implicit [2607.00394]. Predictive caches such as InstCache depend on distributional stability and exact-match coverage; drift is handled by periodic rebuilding rather than continual adaptation [2411.13820].

Another recurring misconception is that classical heuristics remain reliable baselines in all LLM settings. The evidence does not support that claim. In semantic retrieval buffers, LRU and LFU can underperform FIFO because semantic workloads may lack temporal locality and frequency concentration [2607.00394]. In long-context KV management, head-local or layer-uniform heuristics can underperform output-aware or personalized allocations [2605.07234][2412.05896]. In heterogeneous query-answer caching, local one-for-one replacement can be suboptimal because variable-size entries induce nonlocal knapsack interactions [2509.15515].

A broader synthesis is that the term “LLM cache bandit problem” now refers less to one fixed model than to a technical family. Exact query–answer reuse leads to reverse-feedback knapsack bandits [2509.15515]. Semantic memory leads to switching-cost online learning with local Bayesian eviction [2607.00394]. Stale knowledge artifacts lead to synchronization bandits with probe-based gradient estimation [2002.12014]. Delayed eviction consequences motivate delayed-feedback and decaying-cost expert aggregation [2009.11330]. This suggests that future work will likely center on contextual combinatorial bandits that incorporate variable object size, delayed and partial feedback, switching costs, nonstationarity, and cross-request resource coupling rather than on a single universal cache-bandit formalism.

Source: https://www.emergentmind.com/topics/llm-cache-bandit-problem