Repository navigation
Python: Fix Bedrock Cohere embeddings when embedding_types is set - #14678
Open
alexcastgonz (pcbeingused333) wants to merge 1 commit into
Open
alexcastgonz (pcbeingused333) wants to merge 1 commit into
alexcastgonz (pcbeingused333) wants to merge 1 commit into
Conversation
When embedding_types is set, Cohere on Bedrock returns the embeddings keyed by type (a dict) instead of a list of vectors, and parse_text_embedding_response rejected it with ServiceInvalidResponseError. Return the float embedding when present, otherwise the first type in the response.
alexcastgonz (pcbeingused333)
deployed
to
github-app-auth
October 29, 2026 12:37 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Typed embedding responses can accept malformed vectors or select inconsistent encodings across a batch, potentially causing dimension errors.
2 open issues
What changed in this PR
This PR extends the Python Bedrock Cohere embedding parser to handle responses keyed by embedding type, addressing failures when embedding_types is requested.
Changes:
- Accept typed responses, preferring
floatand otherwise selecting the first returned type. - Preserve the existing plain-list response path.
- Add tests for typed embeddings, request forwarding, and empty or malformed typed responses.
| File | Description |
|---|---|
python/tests/unit/connectors/ai/bedrock/services/test_bedrock_text_embedding_generation.py |
Adds successful and invalid typed-response test cases. |
python/semantic_kernel/connectors/ai/bedrock/services/model_provider/bedrock_cohere.py |
Adds extraction of embeddings from type-keyed responses. |
Review effort: Balanced
| if isinstance(embeddings, dict): | ||
| # With `embedding_types` set, the embeddings are keyed by type ({"float": [[...]], "int8": [[...]]}). | ||
| # Return the float embedding when it was requested, otherwise the first type in the response. | ||
| embeddings = embeddings.get("float") or next(iter(embeddings.values()), None) |
| if isinstance(embeddings, dict): | ||
| # With `embedding_types` set, the embeddings are keyed by type ({"float": [[...]], "int8": [[...]]}). | ||
| # Return the float embedding when it was requested, otherwise the first type in the response. | ||
| embeddings = embeddings.get("float") or next(iter(embeddings.values()), None) |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation and Context
BedrockTextEmbeddingaccepts the Cohereembedding_typesoption and forwards it in the request body. With it set, Cohere on Bedrock returns the embeddings keyed by type ({"embeddings": {"float": [[...]], "int8": [[...]]}}) instead of a plain list of vectors, andparse_text_embedding_responseonly accepted a list, so the call failed withServiceInvalidResponseError: The response from Cohere model does not contain embeddings.even though the request succeeded.Description
parse_text_embedding_responseinbedrock_cohere.pynow also accepts the keyed form: it returns thefloatembedding when that type is present, otherwise the first type in the response. The plain list form and the error for missing or malformed embeddings are unchanged.Tests (
tests/unit/connectors/ai/bedrock/services/test_bedrock_text_embedding_generation.py): typed responses (float only, float plus int8, int8 only) and the plain list throughgenerate_embeddingswithembedding_typesin the settings, and empty or malformed typed responses still raisingServiceInvalidResponseError.tests/unit/connectors/ai/bedrock: 123 passed; 3 of the new cases fail without the change. Not run against the real Bedrock API.Contribution Checklist
Disclosure: this change was prepared with an AI coding assistant (Claude) working for the account owner.