Skip to content

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]

fix(bedrock): normalize encoding_format base64 to float for cohere embed models

mateo-berria3eac3f7716f
diff --git a/litellm/llms/bedrock/embed/cohere_transformation.py b/litellm/llms/bedrock/embed/cohere_transformation.py
index d1c9ceb99d1..8a17bb9d595 100644
--- a/litellm/llms/bedrock/embed/cohere_transformation.py
+++ b/litellm/llms/bedrock/embed/cohere_transformation.py
@@ -20,7 +20,9 @@ class BedrockCohereEmbeddingConfig:
def map_openai_params(self, non_default_params: dict, optional_params: dict) -> dict:
for k, v in non_default_params.items():
if k == "encoding_format":
- optional_params["embedding_types"] = v if isinstance(v, list) else [v]
+ optional_params["embedding_types"] = [
+ "float" if fmt == "base64" else fmt for fmt in (tuple(v) if isinstance(v, list) else (v,))
+ ]
elif k == "dimensions":
optional_params["output_dimension"] = v
return optional_params
diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py
index 6381e1a1274..b34d8360183 100644
--- a/tests/test_litellm/test_utils.py
+++ b/tests/test_litellm/test_utils.py
@@ -4433,6 +4433,22 @@ class TestBedrockCohereEmbeddingDispatch:
)
assert optional_params.get("embedding_types") == ["float"]
+ @pytest.mark.parametrize(
+ "model",
+ [
+ "cohere.embed-english-v3",
+ "cohere.embed-multilingual-v3",
+ "cohere.embed-v4:0",
+ ],
+ )
+ def test_cohere_embed_models_map_base64_to_float(self, model):
+ optional_params = litellm.utils.get_optional_params_embeddings(
+ model=model,
+ encoding_format="base64",
+ custom_llm_provider="bedrock",
+ )
+ assert optional_params.get("embedding_types") == ["float"]
+
def test_cohere_embed_english_v3_maps_dimensions(self):
optional_params = litellm.utils.get_optional_params_embeddings(
model="cohere.embed-english-v3",