Design a Semantic Cache for Repeated LLM Questions in Google Assistant
Last updated: November 29, 2026
Quick Overview
Many users ask the assistant nearly identical questions, and each LLM call is expensive. Design a semantic cache that serves a stored answer when a new question means the same thing, without returning wrong or stale answers.
0
0
0 solved
Many users ask the assistant nearly identical questions, and each LLM call is expensive. Design a semantic cache that serves a stored answer when a new question means the same thing, without returning wrong or stale answers.
A practical cost-reduction question for teams serving LLM features at scale. The interviewer checks how you define a match, pick a similarity threshold, scope the cache to avoid leaking personalized answers, and invalidate time-sensitive content.
What the Interviewer Expects
- Embed queries and look up nearest neighbors with a threshold
- Only cache non-personal, non-time-sensitive answers
- Scope keys by language, locale and model version
- Set invalidation and TTL policies
- Measure hit rate and answer quality impact
Key Topics to Cover
How to Approach This
- Start by mapping the business objective to a concrete ML objective and metric.
- Cover the full pipeline: data collection, feature engineering, model selection, training, serving.
- Discuss online vs offline evaluation. Plan an A/B test to validate real-world impact.
- Address the serving latency budget and whether batch or real-time inference is needed.
- Think about the data flywheel: how user feedback improves the model over time.
Possible Follow-up Questions
- Are 'How tall is the Eiffel Tower' and 'How tall is the Tokyo Tower' a cache hit?
- How do you choose the similarity threshold?
- How do you handle a model version change?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice ML System Design ProblemsSample Answer
Requirements
Goal: cut LLM calls for repeated general questions by a meaningful fraction while keeping answers correct. Only cache answers that do not depend on the user (no 'my calendar') or on real-time data (we...
High-Level Design
- Cacheability classifier: decides whether a query is general and stable.
- Normalizer and embedder: small sentence embedding model.
- Vector store: ANN index partitioned by (language, ...