The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
tes BGE
Ishaan Jaffer0abf450b7e0f
diff --git a/litellm/llms/vertex_ai/vertex_embeddings/bge.py b/litellm/llms/vertex_ai/vertex_embeddings/bge.pyindex 1bfa362ee98..b8979f55880 100644--- a/litellm/llms/vertex_ai/vertex_embeddings/bge.py+++ b/litellm/llms/vertex_ai/vertex_embeddings/bge.py@@ -123,14 +123,29 @@ class VertexBGEConfig:Returns:EmbeddingResponse: The transformed response in OpenAI format++ Raises:+ KeyError: If response doesn't contain 'predictions'+ ValueError: If predictions is not a list or contains invalid data"""+ if "predictions" not in response:+ raise KeyError("Response missing 'predictions' field")+_predictions = response["predictions"]++ if not isinstance(_predictions, list):+ raise ValueError(f"Expected 'predictions' to be a list, got {type(_predictions)}")embedding_response = []# BGE models don't return token counts, so we estimate or set to 0input_tokens = 0for idx, embedding_values in enumerate(_predictions):+ if not isinstance(embedding_values, list):+ raise ValueError(+ f"Expected embedding at index {idx} to be a list, got {type(embedding_values)}"+ )+embedding_response.append({"object": "embedding",diff --git a/tests/test_litellm/llms/vertex_ai/test_bge_response_transformation.py b/tests/test_litellm/llms/vertex_ai/test_bge_response_transformation.pynew file mode 100644index 00000000000..a3f28678229--- /dev/null+++ b/tests/test_litellm/llms/vertex_ai/test_bge_response_transformation.py@@ -0,0 +1,93 @@+"""+Test BGE response transformation validation.++This test verifies that the BGE response transformer properly validates+and handles different response formats.+"""++import os+import sys++sys.path.insert(+ 0, os.path.abspath("../../../..")+)++import pytest++from litellm.llms.vertex_ai.vertex_embeddings.bge import VertexBGEConfig+from litellm.types.utils import EmbeddingResponse+++def test_bge_response_transformation_success():+ """+ Test successful BGE response transformation.++ Verifies that a valid BGE response is properly transformed+ to OpenAI format.+ """+ response = {+ "predictions": [+ [0.1, 0.2, 0.3],+ [0.4, 0.5, 0.6]+ ],+ "deployedModelId": "123456",+ "model": "projects/test/models/bge-base"+ }++ model_response = EmbeddingResponse()+ result = VertexBGEConfig.transform_response(+ response=response,+ model="bge-small-en-v1.5",+ model_response=model_response+ )++ assert result.object == "list"+ assert len(result.data) == 2+ assert result.data[0]["embedding"] == [0.1, 0.2, 0.3]+ assert result.data[1]["embedding"] == [0.4, 0.5, 0.6]+ assert result.data[0]["index"] == 0+ assert result.data[1]["index"] == 1+ assert result.model == "bge-small-en-v1.5"+++def test_bge_response_missing_predictions():+ """+ Test BGE response transformation with missing predictions field.++ Verifies that a KeyError is raised when the response doesn't+ contain the required 'predictions' field.+ """+ response = {+ "deployedModelId": "123456",+ "model": "projects/test/models/bge-base"+ }++ model_response = EmbeddingResponse()++ with pytest.raises(KeyError, match="Response missing 'predictions' field"):+ VertexBGEConfig.transform_response(+ response=response,+ model="bge-small-en-v1.5",+ model_response=model_response+ )+++def test_bge_response_invalid_predictions_type():+ """+ Test BGE response transformation with invalid predictions type.++ Verifies that a ValueError is raised when predictions is not a list.+ """+ response = {+ "predictions": "not-a-list"+ }++ model_response = EmbeddingResponse()++ with pytest.raises(ValueError, match="Expected 'predictions' to be a list"):+ VertexBGEConfig.transform_response(+ response=response,+ model="bge-small-en-v1.5",+ model_response=model_response+ )+