Skip to main content
The semantic_cache policy serves cached completions for repeated requests — either exact (normalized text equality), semantic (embedding similarity), or both. It embeds the prompt, looks for a close match in the configured vector store, and returns the cached response on a hit. It runs in two stages: pre_request (lookup) and post_response (populate).

Settings

SettingTypeDefaultNotes
modeenumsemanticexact, semantic, or both.
scopeenumconsumerconsumer isolates entries per consumer; global shares them gateway-wide.
vector_storeenumredisredis, pgvector, or in_memory.
similarity_thresholdnumber0.85Cosine similarity in (0, 1] required for a hit.
ttl_secondsintEntry lifetime in seconds (takes precedence over ttl).
ttlduration24hLegacy duration form, superseded by ttl_seconds.
embedding.providerstringopenaiEmbedding provider used to vectorize requests.
embedding.modelstringtext-embedding-ada-002Embedding model.
embedding.api_keystringCredential for the embedding provider.
cache_only_on_statusint[][200]Status codes whose responses may be cached.
bypass_headerstringX-Cache-BypassRequest header whose presence bypasses lookup + store.
skip_if_tools_presentbooltrueSkip caching when the request/response involves tool calls.
skip_if_streamingboolfalseSkip caching for streaming requests/responses.

On a hit

The cached response is returned and the proxy sets cache headers (X-Cache-Status: HIT and a similarity score). To skip the cache for a single request, send the configured bypass_header (default X-Cache-Bypass); the fresh response still populates the cache.
Tune similarity_threshold carefully: too low risks serving a cached answer for a meaningfully different prompt; too high reduces hit rate. Start at 0.9 and lower it while watching answer quality.