Skip to content
RED SAGSkills
mediumAI Engineer (LLM & Generative AI) interview question

What kinds of caching can you use in an LLM application, and what are the risks of each?

What the interviewer wants to hear

  • Provider prompt caching for repeated prefixes needs stable prompt order
  • Exact-match response caching is safe but hits rarely
  • Semantic caching raises hit rate but risks false hits
  • Cache keys must include user, permissions, model and prompt version
  • Use expiry and invalidation when source data changes

Model answer

I think in three layers. First, provider prompt caching: if long system prompts, tool definitions or documents are a stable prefix, the provider reuses that work, cutting cost and latency, so I put static content first and changing content last. Second, exact-match caching of full responses keyed by normalised input, model and prompt version. It is safe but only hits for repeated questions. Third, semantic caching, which returns a stored answer for a similar question. It raises hit rates but can return wrong answers when phrasing is close but meaning differs, so I use a strict threshold, measure false hits on labelled pairs, and skip it for actions. For all of them, the cache key must include user or tenant and permissions so nobody gets someone else data, and entries need expiry when sources change.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium AI Engineer (LLM & Generative AI) questions