Tutorials · Chapter D (4/4) · ~10 min
Semantic cache lab
Try it → see it → read → next
**Cache near-duplicate queries** — skip LLM calls when similarity beats your threshold.
Try tools: Code & developers
Try yourself
Playground
Semantic cache lab
Near-duplicate questions should cache-hit — novel ones call the LLM.
What are your refund hours?
Recap
What you just did
You classified cache hit vs fresh LLM call for paraphrased questions.
Read
Sketch
def answer(q: str):
hit = cache.lookup(embed(q), threshold=0.92)
if hit: return hit.text
out = llm(q)
cache.store(embed(q), out)
return out