Building with AILesson 73 of 80

Module 8 · Cost, latency and running it in production

Caching at three levels: exact, prefix and semantic

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 3 of 10 in this chapter

This chapter’s goalProduce a cost and latency budget for an AI feature at a stated scale, defend each line of it with a measurement, and operate the feature through a provider outage, a model deprecation and a tenfold traffic increase without an unplanned bill or an unplanned outage.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Three caches, three questions

“Have we answered exactly this before?” “Have we sent exactly this context before?” “Have we answered something like this before?” Each is a cache, each saves a different cost, and each fails differently. Teams that say “we added caching” usually mean one of them and are surprised by the other two.

Exact-match response cache

Key: a hash of the rendered prompt (system prompt, context, conversation and message) plus the model identifier and the parameters. Value: the response. A hit costs nothing and returns instantly.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Python, from Zero, for AI exam.

Stuck on something?Ask Sayali, your AI tutor

How to cite: Addaly (2026) ‘Caching at three levels: exact, prefix and semantic’, in Building with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/building-with-ai/caching-at-three-levels (Accessed: 29 November 2026).