在本页上,前缀缓存(也称为提示缓存或上下文缓存)是减少 LLM 推理中的延迟和成本的最有效技术之一。
It’s especially useful in production workloads with repeated prompt structures, such as chat systems, AI agents, and RAG pipelines。
这个想法很简单:通过缓存现有查询的 KV 缓存,共享相同前缀的新查询可以跳过重新计算提示的该部分。
前缀缓存与简单的语义缓存不同,在简单的语义缓存中,完整的输入和输出文本存储在数据库中,只有完全匹配(或类似的查询)才能命中缓存并立即返回。
During prefill, the model performs a forward pass over the entire input and builds up a key-value (KV) cache for attention computation。
The resulting KV pairs for each token are stored in GPU memory。
来源:HackerNews New











