All lessons in AI Engineering: From Foundation Models to Evaluated Applications

Budget KV Memory and Prefix Reuse

Calculate admission limits, shared-prefix savings, and retention tradeoffs during tool gaps.

90 minutes · Members lesson · preview

What you will learn

  • Calculate KV-cache capacity with explicit architecture, precision, and allocation assumptions.
  • Distinguish logical shared-prefix savings from physical allocation and request admission.
  • Choose and test a retention policy for paused agent sessions.

Your model fits on the device, but the server runs out of memory when several long conversations become active. The persistent key and value state can be the limiting resource. Extend the workload contract with an admission budget that accounts for active lengths, shared prefixes, and expected growth.

Budget 90 minutes: 20 for calculations, 45 for a capacity model or bounded measurement, and 25 for invalidation and pressure tests. Use binary units for device-memory calculations and label metadata, workspace, and fragmentation assumptions. A spreadsheet is sufficient for the calculation track.

Choose another lesson