From beb87fc3d35799d0ebc4d2af0b2487c31f080455 Mon Sep 17 00:00:00 2001 From: Jonathan Doughty Date: Sun, 31 May 2026 09:39:52 -0400 Subject: [PATCH] Fix hosted vLLM embedding encoding format defaults --- .../hosted_vllm/embedding/transformation.py | 6 +++- ...st_hosted_vllm_embedding_transformation.py | 32 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/litellm/llms/hosted_vllm/embedding/transformation.py b/litellm/llms/hosted_vllm/embedding/transformation.py index 9c3e8c6c7cc..785f0750447 100644 --- a/litellm/llms/hosted_vllm/embedding/transformation.py +++ b/litellm/llms/hosted_vllm/embedding/transformation.py @@ -110,10 +110,14 @@ class HostedVLLMEmbeddingConfig(BaseEmbeddingConfig): if model.startswith("hosted_vllm/"): model = model.replace("hosted_vllm/", "", 1) + request_optional_params = optional_params.copy() + if isinstance(request_optional_params.get("encoding_format"), list): + request_optional_params.pop("encoding_format") + return { "model": model, "input": input, - **optional_params, + **request_optional_params, } def transform_embedding_response( diff --git a/tests/test_litellm/llms/hosted_vllm/embedding/test_hosted_vllm_embedding_transformation.py b/tests/test_litellm/llms/hosted_vllm/embedding/test_hosted_vllm_embedding_transformation.py index 35c0a63573f..fed92a6665b 100644 --- a/tests/test_litellm/llms/hosted_vllm/embedding/test_hosted_vllm_embedding_transformation.py +++ b/tests/test_litellm/llms/hosted_vllm/embedding/test_hosted_vllm_embedding_transformation.py @@ -8,13 +8,11 @@ especially ensuring that encoding_format is not included when not provided. import json import os import sys -from unittest.mock import MagicMock, Mock, patch +from unittest.mock import Mock, patch import pytest -sys.path.insert( - 0, os.path.abspath("../../../../..") -) # Adds the parent directory to the system path +sys.path.insert(0, os.path.abspath("../../../../..")) # Adds the parent directory to the system path import litellm from litellm.llms.hosted_vllm.embedding.transformation import ( @@ -92,9 +90,7 @@ class TestHostedVLLMEmbeddingTransformation: headers={}, ) - assert ( - "encoding_format" not in result - ), "encoding_format should not be in request when not provided" + assert "encoding_format" not in result, "encoding_format should not be in request when not provided" def test_encoding_format_not_included_when_none(self): """ @@ -142,6 +138,24 @@ class TestHostedVLLMEmbeddingTransformation: assert result["encoding_format"] == "base64" + def test_encoding_format_list_is_not_included(self): + """Test that list-valued encoding_format defaults are not sent.""" + input_data = ["hello world"] + optional_params = { + "dimensions": 384, + "encoding_format": ["float", "base64", "ubyte", "int8"], + } + + result = self.config.transform_embedding_request( + model=self.model, + input=input_data, + optional_params=optional_params, + headers={}, + ) + + assert result["dimensions"] == 384 + assert "encoding_format" not in result + def test_get_supported_openai_params(self): """Test that supported OpenAI parameters are correctly listed.""" supported = self.config.get_supported_openai_params(self.model) @@ -283,9 +297,7 @@ class TestHostedVLLMEmbeddingTransformation: sent_data = json.loads(call_kwargs["data"]) # Assert that encoding_format is NOT in the sent data - assert ( - "encoding_format" not in sent_data - ), "encoding_format should not be in request when not provided" + assert "encoding_format" not in sent_data, "encoding_format should not be in request when not provided" assert sent_data["model"] == "BAAI/bge-small-en-v1.5" assert sent_data["input"] == ["Hello world"]