fix(caching): forward metadata to embedding in valkey semantic sync path - #32494
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR fixes a metadata forwarding gap in the synchronous
Confidence Score: 5/5The change is safe to merge — two isolated one-line fixes that bring the sync embedding calls in line with an already-correct async path. The diff is minimal and mechanically consistent: the sync calls now pass exactly the same metadata=kwargs.get("metadata") argument that the async calls already used. The fix is verified by two new tests that spy on _get_embedding and would fail if the argument were missing, matching the pattern of the pre-existing async tests. No existing tests were modified, no mock behavior was weakened, and no real network calls are made. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/caching/valkey_semantic_cache.py | Two one-line fixes: sync set_cache and get_cache now pass metadata=kwargs.get("metadata") to _get_embedding, matching the async paths and RedisSemanticCache. |
| tests/test_litellm/caching/test_valkey_semantic_cache.py | Two new regression tests use spy functions to verify metadata is forwarded in the sync paths, mirroring the existing async test pattern. No real network calls, no existing tests modified. |
Reviews (1): Last reviewed commit: "fix(caching): forward metadata to embedd..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Relevant issues
Fixes #32324
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
In-process caching logic, so proof is a regression test on the sync
set_cache/get_cachepaths that spies the embedding call and asserts the request metadata is forwarded. Captured before/after on this branch.Before (on
litellm_internal_staging): the sync path callsself._get_embedding(prompt)with no metadata, so the spy seesNone:After:
Type
🐛 Bug Fix
Changes
The async crash originally reported in #32324 (
_get_async_embeddingreceiving**kwargssuch ascache_key) was already fixed by #32295, which changed the two async embedding calls to passmetadata=kwargs.get("metadata"). The synchronousset_cacheandget_cachepaths invalkey_semantic_cache.pywere left callingself._get_embedding(prompt)with no metadata at all, so the embedding request lost the request metadata (used for embedding spend attribution and per-deployment routing). This diverged from both the async valkey path andRedisSemanticCache, whose sync path already passesmetadata=kwargs.get("metadata").This aligns the two sync calls with the async valkey path and Redis:
_get_embeddingalready accepts an optionalmetadataargument, so no signature change is needed.Added
test_set_cache_passes_metadata_to_get_embeddingandtest_get_cache_passes_metadata_to_get_embedding, mirroring the existing async metadata-forwarding tests. Both fail on the pre-fix sync calls and pass after.Link to Devin session: https://app.devin.ai/sessions/b6199691266e4c468b8c05cfe279e788