Smart Caches provide semantic response caching. When a query is semantically similar to a previous one, the cached response is returned instantly without calling the LLM.
- Request arrives with model name set to your Smart Cache
- Query is embedded using the configured embedding model
- Semantic search finds similar previous queries in ChromaDB
- If match found (above similarity threshold): return cached response
- If no match: forward to target model, cache the response
Client Request → Smart Cache → Semantic Search
↓ ↓
Cache Hit? ChromaDB
↓ Yes ↓ No
Return Cached Forward to Target
↓
Cache Response
- ChromaDB: Required for vector storage (
CHROMA_URLenvironment variable)
In the Admin UI:
- Go to Smart Caches in the sidebar
- Click New Cache
- Configure:
| Field | Description |
|---|---|
| Name | The model name clients will use (e.g., cached-claude) |
| Target Model | The underlying model to call on cache miss |
| Similarity Threshold | How similar queries must be (0.0-1.0, default 0.95) |
| TTL (seconds) | How long to keep cached responses (0 = forever) |
| Min Response Tokens | Don't cache responses shorter than this |
| Max Response Tokens | Don't cache responses longer than this |
| Match Last Message Only | Ignore conversation history for matching |
- Click Save
Cache Name: cached-claude
Target Model: anthropic/claude-sonnet-4-5
Similarity Threshold: 0.95 (95% similar)
TTL: 86400 (24 hours)
Min Response Tokens: 50 (skip short responses)
Now use it:
# First request - calls Claude, caches response
curl http://localhost:11434/api/chat \
-d '{"model": "cached-claude", "messages": [{"role": "user", "content": "What is Python?"}]}'
# Similar request - returns cached response instantly
curl http://localhost:11434/api/chat \
-d '{"model": "cached-claude", "messages": [{"role": "user", "content": "Explain Python to me"}]}'Controls how similar a query must be to return a cached response.
| Value | Behavior |
|---|---|
0.99 |
Nearly identical queries only |
0.95 |
Very similar queries (recommended) |
0.90 |
Moderately similar queries |
0.80 |
Loosely similar queries (may return wrong answers) |
Start with 0.95 and adjust based on your use case.
How long cached responses remain valid, in seconds.
| Value | Duration |
|---|---|
0 |
Cache forever |
3600 |
1 hour |
86400 |
24 hours |
604800 |
1 week |
Consider your data freshness requirements. For factual queries about current events, use shorter TTLs.
Min Response Tokens: Skip caching very short responses that may be unhelpful or error messages.
Max Response Tokens: Skip caching very long responses to save storage space.
Recommended starting values:
- Min: 50 tokens
- Max: 4000 tokens (or leave at 0 for no limit)
When enabled, only the last user message is used for similarity matching. The conversation history is ignored.
Use cases:
- Open WebUI and other chat interfaces where each turn is independent
- FAQ-style queries where context doesn't matter
- Reducing false negatives from conversation context
When to disable:
- Multi-turn conversations where context matters
- Queries that depend on previous messages
By default, Smart Cache uses a local embedding model (bundled with LLM Relay). You can configure alternative embedding providers:
| Provider | Configuration |
|---|---|
| Local | local - Uses bundled sentence-transformers |
| Ollama | ollama:<instance> - Uses your Ollama instance |
| OpenAI | openai - Uses text-embedding-3-small |
For Ollama, you'll need to pull an embedding model first:
# On your Ollama instance
ollama pull nomic-embed-textThen configure the cache with:
- Embedding Provider:
ollama:your-instance - Embedding Model:
nomic-embed-text
Cache hits include headers:
X-LLM-Relay-Cache: hit
X-LLM-Relay-Cache-Similarity: 0.97
Cache misses:
X-LLM-Relay-Cache: miss
The Smart Cache detail page shows:
- Total requests
- Cache hit rate
- Cache entries
- Storage usage
- Start conservative - Use 0.95+ similarity threshold initially
- Monitor hit rate - Aim for 20-40% hit rate for good ROI
- Use appropriate TTL - Match your data freshness needs
- Enable match_last_message_only for chat UIs - Improves hit rate significantly
- Filter short responses - Avoid caching error messages
Currently, cache entries expire based on TTL. To manually clear the cache:
- Go to Smart Caches in the Admin UI
- Click on the cache
- Click Clear Cache
This removes all cached entries for that cache.
- Lower the similarity threshold (try 0.90)
- Enable "Match Last Message Only" for chat interfaces
- Check if queries are too varied for caching
- Raise the similarity threshold (try 0.98)
- Reduce TTL for time-sensitive content
- Disable "Match Last Message Only" if context matters
- Reduce TTL
- Set max_response_tokens to limit cached content
- Clear cache periodically
- Verify ChromaDB is running (
CHROMA_URLis set) - Check container logs for embedding errors
- Ensure target model is accessible