From 3fab69dd316aff675b1cda08cf98a85c1f371f09 Mon Sep 17 00:00:00 2001 From: Hasnaat Hussain Date: Sun, 30 Aug 2026 19:00:11 +0500 Subject: [PATCH] fix: preserve mapped embedding dimensions Signed-off-by: Hasnaat Hussain --- litellm/utils.py | 16 ++++++------- .../test_embedding_optional_params.py | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index 082bb3d3a2d..89a9de3d1ed 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3752,6 +3752,14 @@ def get_optional_params_embeddings( optional_params = non_default_params else: optional_params = non_default_params + if ( + (litellm.drop_params is True or resolved_drop_params is True) + and (custom_llm_provider == "azure" or custom_llm_provider in litellm.openai_compatible_providers) + and "text-embedding-3" not in model + and "dimensions" in optional_params + and "dimensions" not in allowed_openai_params + ): + optional_params.pop("dimensions", None) final_params = add_provider_specific_params_to_optional_params( optional_params=optional_params, @@ -3764,14 +3772,6 @@ def get_optional_params_embeddings( if "extra_body" in final_params and len(final_params["extra_body"]) == 0: final_params.pop("extra_body", None) - if ( - (litellm.drop_params is True or resolved_drop_params is True) - and (custom_llm_provider == "azure" or custom_llm_provider in litellm.openai_compatible_providers) - and "text-embedding-3" not in model - and "dimensions" not in (allowed_openai_params or ()) - ): - final_params.pop("dimensions", None) - return final_params diff --git a/tests/test_litellm/litellm_core_utils/test_embedding_optional_params.py b/tests/test_litellm/litellm_core_utils/test_embedding_optional_params.py index 6a044a5680a..a5381f67c71 100644 --- a/tests/test_litellm/litellm_core_utils/test_embedding_optional_params.py +++ b/tests/test_litellm/litellm_core_utils/test_embedding_optional_params.py @@ -49,3 +49,27 @@ def test_embedding_dimensions_drop_params_for_openai_compatible_provider(provide assert explicitly_allowed["dimensions"] == 512 finally: litellm.drop_params = previous_drop_params + + +@pytest.mark.parametrize( + ("provider", "model"), + [ + ("nvidia_nim", "nvidia_nim/nv-embedqa-e5-v5"), + ("fireworks_ai", "fireworks_ai/nomic-ai/nomic-embed-text-v1.5"), + ("dashscope", "dashscope/text-embedding-v3"), + ("hosted_vllm", "hosted_vllm/Qwen/Qwen3-Embedding-0.6B"), + ], +) +def test_embedding_dimensions_preserved_for_provider_mappings(provider, model): + previous_drop_params = litellm.drop_params + try: + litellm.drop_params = True + optional_params = litellm.utils.get_optional_params_embeddings( + model=model, + custom_llm_provider=provider, + dimensions=128, + ) + finally: + litellm.drop_params = previous_drop_params + + assert optional_params["dimensions"] == 128