AI systemssemantic cachingLLM cacheembedding cache

Semantic cache

Definition

A semantic cache stores prompt embeddings with their responses and, for each new prompt, returns the response of the most similar stored prompt if the similarity exceeds a threshold; otherwise it calls the model and stores the new pair.

In practice

Exact-match caches rarely hit natural-language prompts because people phrase the same question differently. A semantic hit skips a slow, billed generation, so the cache effectively adds model capacity under a fixed token quota. Every request pays for an embedding call and a vector search, a few to tens of milliseconds, even on a miss. It differs from provider prompt caching, which reuses computation for a repeated prompt prefix but still generates a new answer.

The threshold trades hit ratio for correctness: a lower one always raises hits and silently adds false hits, answers to a different question. Tune it on labelled pairs, scope entries by tenant, user permissions and model version, and invalidate by source and version tags. Avoid it where small wording changes alter the answer, such as numbers, dosages or legal terms.

Example

At a cosine threshold of 0.92, 31% of support questions hit the cache with a measured 0.5% false-hit rate; lowering it to 0.85 raises hits to 44% but false hits to 4%.