Repository navigation
feat(caching): add valkey-semantic cache backend and fix semantic cache scope keys #30675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yassin-berriai
merged 1 commit into
litellm_internal_staging
from
litellm_valkey_semantic_cache
Jun 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redis-semanticandqdrant-semanticentriesget_cache_key()now excludesmessages,prompt, andinputfrom the hashed key for every semantic cache type — including the pre-existingredis-semanticandqdrant-semanticbackends. Any instance that has been running one of those backends will find that every stored entry becomes permanently unreachable after upgrading: the SHA-256 scope tag changes for every document, so all KNN filter lookups miss indefinitely. Dropping the cache silently on upgrade violates the backwards-compatibility rule; the fix should be opt-in (e.g.litellm.semantic_cache_scope_fix = True) so operators can schedule the cold-start window. Newvalkey-semanticdeployments are unaffected since they have no prior entries to lose.Rule Used: What: avoid backwards-incompatible changes without... (source)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional, and I think a flag is the wrong call here.
The entries this invalidates were only ever reachable by a byte-identical prompt, because the prompt was baked into the scope key and the KNN filter required an exact key match, so semantic matching never actually ran. The warm cache that goes cold on upgrade therefore only held exact-prompt repeats, which is the single case where a semantic cache adds nothing over a plain exact cache. Keeping the old key format preserves nothing of value.
The impact is also self-healing and bounded. Semantic cache entries are TTL'd and best-effort: an orphaned entry sits until its TTL and expires, and a lookup miss just re-calls the provider, so there is no correctness impact and no data loss, only a one-time cold start for the remainder of the existing TTL. The new key additionally appends the authenticated tenant identity, so it is strictly more isolated than before, never less.
An opt-in flag would default every existing redis-semantic and qdrant-semantic deployment to the broken behavior, so semantic caching keeps silently not working until someone finds the flag, and it adds a second code path and config surface to preserve a cache state with no value. Defaulting to the correct behavior is the better trade. An operator who wants to reclaim the orphaned entries immediately can flush the index or shorten the TTL; otherwise it clears itself within one TTL.