microsoft/semantic-kernel · error · ServiceInvalidResponseError
The response from Cohere model does not contain embeddings.
Error message
The response from Cohere model does not contain embeddings.
What it means
Raised by the Cohere (Bedrock) text-embedding response parser when the response dict has no 'embeddings' key, that key is not a list, or the list is empty. The parser then dereferences response['embeddings'][0], so it defends all three conditions up front.
Source
Thrown at python/semantic_kernel/connectors/ai/bedrock/services/model_provider/bedrock_cohere.py:96
# endregion
# region Text Embedding
def get_text_embedding_request_body(text: str, settings: BedrockEmbeddingPromptExecutionSettings) -> Any:
"""Get the request body for text embedding for Cohere Command models."""
return remove_none_recursively({
"texts": [text],
"input_type": settings.extension_data.get("input_type", "search_document"),
"truncate": settings.extension_data.get("truncate", None),
"embedding_types": settings.extension_data.get("embedding_types", None),
})
def parse_text_embedding_response(response: dict[str, Any]) -> list[float]:
"""Parse the response from text embedding for Cohere Command models."""
if "embeddings" not in response or not isinstance(response["embeddings"], list) or len(response["embeddings"]) == 0:
raise ServiceInvalidResponseError("The response from Cohere model does not contain embeddings.")
return response.get("embeddings")[0] # type: ignore
# endregion
View on GitHub (pinned to c028a0c7dc)
Solutions
- Confirm the model_id is a Cohere embedding model such as cohere.embed-english-v3 or cohere.embed-multilingual-v3, not a Command chat model.
- Check the raw response body; if Cohere returns a validation error (e.g. invalid input_type/truncate), fix the extension_data settings accordingly.
- Ensure the text passed to embed is non-empty so remove_none_recursively does not strip the 'texts' field.
- Upgrade semantic-kernel and boto3 so the Cohere response schema the parser reads matches what Bedrock returns.
Example fix
// before settings.extension_data["input_type"] = "" // after settings.extension_data["input_type"] = "search_document"
Defensive patterns
Strategy: validation
Validate before calling
def is_valid_cohere_embedding_response(response: dict) -> bool:
return (
isinstance(response, dict)
and isinstance(response.get("embeddings"), list)
and len(response["embeddings"]) > 0
) Type guard
from typing import Any
def is_cohere_embedding_response(resp: Any) -> bool:
return isinstance(resp, dict) and isinstance(resp.get("embeddings"), list) and bool(resp["embeddings"]) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInvalidResponseError
try:
embeddings = await service.generate_embeddings([text])
except ServiceInvalidResponseError as e:
if "does not contain embeddings" in str(e):
logger.error("Cohere embedding call failed; check input_type/truncate extension data")
raise Prevention
- Use a Cohere embedding model ID (cohere.embed-english-v3).
- Set extension_data input_type to a valid Cohere value (search_document/search_query/classification).
- Inspect the raw response when first integrating to confirm the 'embeddings' field shape.
When it happens
Trigger: Called from BedrockTextEmbeddingService -> parse_text_embedding_response for a Cohere embedding model (e.g. cohere.embed-english-v3). Fires when the Cohere payload omits 'embeddings', returns it as a non-list, or returns an empty list (Cohere rejected the input text, or returned an error/status object instead).
Common situations: Using a Cohere chat model ID instead of a Cohere embedding model ID; Cohere rejecting input because input_type extension data is invalid; Bedrock throttling returning an error body; the 'texts' array in the request was empty after remove_none_recursively; version skew between Cohere embedding response schema and the parser.
Related errors
- The response from Amazon Titan model does not contain embedd
- Unsupported Cohere model: {modelId}
- Unsupported service type
- Response is null
- An error occurred while initializing the {nameof(IEmbeddingG
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c8325d2558762e8d.
Report an issue: GitHub.