Prompt Caching
In this article
- Lay out a request so the part that never changes comes first and a provider's cache can reuse it.
- Predict which edits to a request make the next call miss the cache.
- Compute the input cost of one call with no cache, on a hit and on a write, and find the hit rate at which caching starts to pay.
- Say why one customer's data never belongs in a prefix that every customer shares.
- Terms defined here: prompt caching, KV cache, stable prefix, cache invalidation, hit rate, cache TTL.
Overview
In many applications each request largely repeats the one before, and without caching the model processes all of it again on every call. [2] In an invented example, Brightline, a home-internet provider, runs a support assistant on its website that answers customers and can look up an order, issue a refund of at most $50 and hand a conversation to a person on the support team. Each call sends about 5,000 tokens, about 4,000 of them the same every time; a token is one of the small pieces text is cut into for a model. Afterwards you can order a request so the provider, the company serving the model, reuses the repeated part, predict which edits break that, and tell from three prices whether it pays.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- Reusing the start of a request
- Putting the stable part first
- What a hit and a write cost
- How long a prefix lives
- Changing the prefix
- Keeping customers out of the prefix
- Does caching pay for Brightline?
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions