From Exact Hits to Close Enough: Semantic Caching for LLM Embeddings

Biton, Dvir David, Friedman, Roy

–arXiv.org Artificial Intelligence 

Abstractpreviously computed answer, avoiding redundant inference The rapid adoption of large language modelsand reducing overall latency and compute cost. Most of (LLMs) has created demand for faster responsesthese works adopt a na ıve or ad-hoc approach to managing the cache, i.e., for deciding which embeddings should beand lower costs. Semantic caching, reusing seinserted into the cache, and once the cache is full, whichmantically similar requests via their embeddings, addresses this need but breaks classic cache as-should be evicted to make room for new ones. This is desumptions and raises new challenges. In thisspite evidence from other domains that clever cache managepaper, we explore offline policies for semanticment can significantly improve caching benefits (Megiddo & Modha, 2003; Park & Park, 2017; Einziger et al., 2017).caching, We also present on-yield significantly different hit rates depending on the cache line semantic aware cache policies that combinemanagement policy chosen. This has led to a plethora of recency, frequency, and locality. Evaluations oncache management policies (Hennessy & Patterson, 2012; diverse datasets show that while frequency based Karakostas & Serpanos, 2002; Arlitt et al., 2000) as well policies are strong baselines, our novel variantas to various adaptive schemes and learning based schemes. Our findings reveal However, a universally optimal cache management policy effective strategies for current systems and high-remains an open research challenge. All code is open source. Since semantically similar queries can be answered by the same response, despite the fact that syntactically they are not exactly the same, most LLM caching solutions rely on 1. Introductionsemantic caching, in which a query is considered a hit if the cache already includes the reply to some query such that Modern large language models (LLMs) rely on embeddingthe embedding vectors of both queries are "close enough" methods to encode the semantic meaning of user queriesunder some metric such as L2 norm or cosine similarity. These embeddings enable efThe impact of this shift from exact match caching to semanficient comparison of queries, making them a cornerstone of tic caching on the vast knowledge about caching and cache natural language processing tasks, such as question answerreplacement policies is not clear a priori. LLMs have gained wide adoption in the last few years although they suffer from high compuwe take a systematic approach to studying LLM cache mantational cost, as well as significant consumption of energy, agement and, in particular, what changes, if any, are needed when moving from exact matches to semantic caching. Caching is a known technique to alleviate such limitations, 1.1. Related Work and has been applied successfully in a variety of domains.