通过检测解码前k个词的缓存命中,提升大模型服务缓存安全性。
LaCache: Robust Semantic Caching for LLM Serving

- 对比传统仅查查询缓存,新增对前k个解码词的缓存校验。
- 可形式化证明抵御缓存污染攻击,且提升回复相关性。
- 适合注重安全的大模型服务部署者使用。
语义缓存通过嵌入向量复用语义相似请求的响应,在大模型服务中广泛应用,可加快响应速度并降低开销。然而现有方案极易遭受缓存碰撞攻击:攻击者通过构造恶意查询污染缓存,导致后续合法请求返回错误结果。本文提出LaCache,一种基于简洁而严谨设计的新语义缓存机制。核心思路是:尽管攻击者可完全控制恶意查询,却难以操控其响应——响应必须同时满足多重语义约束。因此,LaCache不仅检查查询本身的缓存命中,还额外验证其前k个(推测解码)词的缓存命中。该设计带来双重优势:首先,形式化证明了对缓存碰撞攻击的免疫能力——无法构造出同时生成恶意响应并命中良性查询的攻击;其次,增强的索引为缓存检索提供了更多语义上下文,提升回复相关性。在多种大模型与基准测试上的实证评估验证了LaCache的安全性保障与效率提升,为鲁棒语义缓存指明了可行方向。
原文摘要 · Abstract (English)
Semantic caching, which reuses responses to semantically similar requests via their embeddings, has seen growing adoption in LLM serving, offering faster responses and reduced costs. Yet existing schemes are fundamentally vulnerable to cache-collision attacks, wherein an adversary pollutes the cache by injecting crafted queries, corrupting responses to subsequent legitimate requests. We present LaCache, a novel semantic caching scheme that addresses this vulnerability through a conceptually simple yet principled redesign. The key insight is that while the adversary has full control over the adversarial query, it has far less control over its response, which must simultaneously satisfy multiple semantic constraints. Rather than checking only the cache hit of a query, LaCache additionally checks the cache hit of its first k (speculatively) decoded tokens. This design yields two concrete benefits. First, it provides formally guaranteed resilience against cache-collision attacks: we prove that it is impossible to craft adversarial queries that simultaneously elicit malicious responses and collide with benign queries. Second, the enriched index supplies additional semantic context for cache retrieval, improving response relevance. Empirical evaluation across diverse LLMs and benchmarks validates both LaCache's security guarantees and efficiency gains, pointing to a promising direction for robust semantic caching.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。