Repository navigation
fix(embeddings): unwrap extra_body for providers with their own embedding handlers - #51335
kerry-berri merged 10 commits into
Conversation
…ding handlers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…and keep lint gates flat Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
[Medium impact] The latest changes appear safe to merge, with no new actionable findings. SummaryThis PR sends
Reviews (5) · Last reviewed commit: "fix(embeddings): keep the shared handler..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…nused merge helper Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ative embedding transform Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…t and mapped params cannot be replaced Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1546031. Configure here.
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
…red handler so extra_body never replaces the input Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… router batch limit relies on extra_body.input Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Handwritten 1-3 sentence description
"extra_body" fields were being dropped when being sent to certain embedders. The fields are now being sent in the provider body.
Details
TLDR
Problem this solves:
extra_bodyon embeddings only worked for providers that call the OpenAI SDK orbase_llm_http_handlerextra_bodykey, so fields were dropped or the provider 400edextra_bodyinside its own and sent bothHow it solves it:
extra_body_fields/split_extra_bodyinlitellm/llms/base_llm/embedding/transformation.pypull the caller'sextra_bodyout ofoptional_paramsbase_llm_http_handler.embeddingdoes, so allowlists like Gemini's_filter_embed_paramsno longer drop them. Bedrock merges into every invoke body, Gemini into everyrequests[]entry, Vertex text and multimodal intoparameters, Ollama and SageMaker into the request bodymodel_id,aws_*,vertex_projectand the other control keys are read fromoptional_params, and the transformed body wins, so a client body cannot override auth, routing, the input or a mapped paramNvidiaNimEmbeddingConfig.map_openai_paramsmerges the nestedextra_bodyinstead of nesting ittest_bedrock_embedding_signs_the_body_it_sendsreplays SigV4 over the wire body and compares theAuthorizationheaderUser Flow
Before: a developer asks a Bedrock Titan embedding for 256 dimensions through
extra_bodyand gets a provider error{"model": "titan-embed-text-v2", "input": "hello world", "extra_body": {"dimensions": 256}}Malformed input request: extraneous key [extra_body] is not permitted, surfaced as a BadRequestErrorgemini-embedding-001withextra_body: {"outputDimensionality": 8}returns 200 but a 3072-float vector, the setting was droppedAfter: the same requests honor the
extra_bodyfieldsextra_body: {"dimensions": 256}to the Titan modelextra_body: {"outputDimensionality": 8}return 8-float vectorsLinear ticket
Resolves LIT-10698
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Shared setup. Two proxies from the same config, one from a worktree at the merge base on port 4001 and one from the branch tip on port 4002, no database and no Redis (the change is request translation only, nothing is shared across workers). Both logged
Running 2 workers.config.yaml (env vars GEMINI_API_KEY, VERTEX_AI_DEVIN_SERVICE_ACCOUNT_JSON, LITELLM_MASTER_KEY, AWS profile litellm-dev)
Client, run once per model with the
extra_bodyshown in the output lines. The script prints the HTTP status and the returned vector length.Before (801e139)
The Ollama
truncate: falsewas dropped intooptions, so Ollama silently truncated the 700 token input.After (41aa0a1)
extra_bodyfieldOllama now receives
truncate: falseand refuses the oversized input, which is what the caller asked for. Ollama ran locally from the v0.40.16 GitHub release (ollama-linux-amd64.tar.zst, sha256 verified against the releasesha256sum.txt) withall-minilm.SageMaker and NVIDIA NIM have no live endpoint on the QA box, they are covered by the capture tests in
tests/unit/llms/sagemaker/test_sagemaker_embedding_voyage.pyandtests/unit/llms/nvidia_nim/test_nvidia_nim.py, each of which fails on main.Type
🐛 Bug Fix
Caveats (if any)
Medium
extra_bodyis the raw provider body, so a Vertex multimodal caller writes{"dimension": 128}and a Bedrock Titan caller{"dimensions": 256}, the OpenAI styledimensionskwarg is still mapped per providerLow
extra_bodyon a collision, so a client cannot swap the embeddedinputpast guardrails or override a mapped param (Cohereinput_type, NovataskType), covered bytest_bedrock_embedding_extra_body_cannot_replace_the_input_or_a_mapped_param.base_llm_http_handleris left as is, thereextra_bodystill wins, because the router's embedding batch limit (test_extra_body_input_at_limit_reaches_provider) relies onextra_body.inputreplacing the input on that pathlintandunitreds at earlier pushes were main-side (chore: move config and docs off the repo root #50966 movedruff-tests.toml, fix(cost-map): drop the duplicate gemini/gemini-decision-1 entry that fails the root unit job on main #51341 fixed the duplicate cost map key, chore: move scripts and runtime sources under litellm #51006 moved the lint scripts underlitellm/scripts/), all merged inFinal Attestation