Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions litellm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3197,6 +3197,12 @@ def _check_valid_arg(supported_params: Optional[list]):
non_default_params=non_default_params, optional_params={}, kwargs=kwargs
)
elif custom_llm_provider == "vertex_ai" or custom_llm_provider == "gemini":
# OpenAI SDKs (and litellm's own client) send encoding_format="float"
# by default; float lists are exactly what the vertex API returns, so
# the param is a no-op — don't reject the provider default. Other
# values (e.g. "base64") stay on the unsupported-param path below.
if non_default_params.get("encoding_format") == "float":
non_default_params.pop("encoding_format")
Comment on lines 3199 to +3205

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Provider-specific logic placed outside llms/ directory

The encoding-format stripping is added directly to utils.py rather than to the provider's own config class. VertexAITextEmbeddingConfig (in litellm/llms/vertex_ai/vertex_embeddings/transformation.py) already owns both get_supported_openai_params() and map_openai_params() — the correct fix is to add "encoding_format" to the supported-params list and silently drop it (when "float") inside map_openai_params(). Placing the strip logic in utils.py means the behaviour won't automatically apply when the provider eventually gets a BaseEmbeddingConfig registration in get_provider_embedding_config (the early-return path would then bypass these lines entirely).

Rule Used: What: Avoid writing provider-specific code outside... (source)

supported_params = get_supported_openai_params(
model=model,
custom_llm_provider="vertex_ai",
Expand Down
51 changes: 50 additions & 1 deletion tests/test_litellm/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4714,7 +4714,6 @@ def test_reports_key_missing(self):
assert "TENCENT_API_KEY" in result["missing_keys"]



@pytest.mark.parametrize(
"model",
[
Expand All @@ -4741,3 +4740,53 @@ def test_gemini_image_models_do_not_support_reasoning(
f"{model} incorrectly classified as reasoning-capable. "
"Add 'supports_reasoning: false' to its model_cost entry."
)


class TestVertexEmbeddingEncodingFormat:
"""vertex_ai/gemini embeddings must accept encoding_format="float" — it's
the OpenAI SDK default and float lists are exactly what the vertex API
returns. Other values keep the unsupported-param behavior (drop with
drop_params, raise otherwise). Issue #33173."""

def test_encoding_format_float_is_accepted_and_dropped(self):
optional_params = litellm.utils.get_optional_params_embeddings(
model="gemini-embedding-001",
encoding_format="float",
custom_llm_provider="vertex_ai",
)
assert "encoding_format" not in optional_params

def test_encoding_format_float_accepted_for_gemini_provider(self):
optional_params = litellm.utils.get_optional_params_embeddings(
model="gemini-embedding-001",
encoding_format="float",
custom_llm_provider="gemini",
)
assert "encoding_format" not in optional_params

def test_encoding_format_base64_still_rejected_without_drop_params(self):
with pytest.raises(Exception) as excinfo:
litellm.utils.get_optional_params_embeddings(
model="gemini-embedding-001",
encoding_format="base64",
custom_llm_provider="vertex_ai",
)
assert "encoding_format" in str(excinfo.value)

def test_encoding_format_base64_dropped_with_drop_params(self):
optional_params = litellm.utils.get_optional_params_embeddings(
model="gemini-embedding-001",
encoding_format="base64",
custom_llm_provider="vertex_ai",
drop_params=True,
)
assert "encoding_format" not in optional_params

def test_dimensions_still_mapped(self):
optional_params = litellm.utils.get_optional_params_embeddings(
model="gemini-embedding-001",
encoding_format="float",
dimensions=256,
custom_llm_provider="vertex_ai",
)
assert optional_params.get("outputDimensionality") == 256
Loading