Overview
A semantic cache stores model responses keyed by a prompt embedding. When a new prompt arrives, it is embedded and compared with cached prompts by vector-similarity; if the best match clears a threshold, the stored response is returned and the model call is skipped. It differs from prompt-cache, which reuses a processed prefix but still generates a fresh answer.
Use it only where many users ask near-identical questions and a slightly approximate answer is acceptable, such as FAQ bots and documentation search. The threshold is the risk: too loose and different questions get the same answer. Tune it on labeled pairs of real queries and start strict.
Scope the cache key to everything the answer depends on. Never share entries across users or tenants when the answer uses account state, include the data or prompt version in the key, and expire entries when the underlying data changes. Each lookup adds an embedding call and a vector search, so measure the hit rate before keeping it.
Example
“How do I reset my password?” is cached with response R. “I forgot my password, how can I reset it?” scores above the threshold and returns R without a model call.
Related
- embeddings-semantic-cache: implementation and threshold tuning.
- prompt-cache: prefix reuse, which keeps answers fresh.
- embedding: the cache key.
- vector-similarity: the metric behind hits.
- cost-control: where caching fits among cost levers.