-
Notifications
You must be signed in to change notification settings - Fork 82
fix: resolve AWS client SigV4 signing, forced SageMaker dep, and missing embed params #728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ing embed params - Fix SigV4 host header mismatch: update copied headers dict with correct host after URL rewrite, so AWSRequest signs with the Bedrock/SageMaker host instead of stale api.cohere.com - Add mode parameter to cohere_aws.Client to conditionally initialize boto3 clients (bedrock-runtime/bedrock vs sagemaker-runtime/sagemaker), avoiding forced SageMaker dependency for Bedrock users - Add output_dimension and embedding_types params to embed() for Embed v4 Closes #721 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add skipped integration tests (gated by TEST_AWS) covering: - BedrockClientV2 embed with SigV4 signing (validates host header fix) - cohere_aws.Client in Bedrock mode (validates mode param fix) - embed() with output_dimension and embedding_types (validates v4 params) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address review feedback: In Bedrock mode, `self._sess` was never set, so SageMaker-only methods would throw confusing AttributeErrors. Now: - Initialize `_sess=None` and `_endpoint_name=None` in Bedrock mode - Add `_require_sagemaker()` guard to connect_to_endpoint, create_endpoint, export_finetune, summarize, and delete_endpoint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes mypy attr-defined error in CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These run in CI without AWS credentials, covering: - SigV4 signing uses correct host header after URL rewrite - Mode-conditional boto3 client initialization (sagemaker vs bedrock) - Default mode is SAGEMAKER for backwards compat - embed() accepts, passes, and strips output_dimension/embedding_types Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| "input_type": input_type | ||
| "input_type": input_type, | ||
| "output_dimension": output_dimension, | ||
| "embedding_types": embedding_types, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embed response parsing breaks with embedding_types parameter
Medium Severity
Adding embedding_types to the request parameters changes the Cohere API response format, but response parsing isn't updated. When embedding_types is specified, the API returns embeddings as a dict (e.g., {"float": [[...]], "int8": [[...]]}) with response_type: "embeddings_by_type", instead of a flat List[List[float]]. Both _bedrock_embed and _sagemaker_embed unconditionally pass response['embeddings'] to the Embeddings constructor, which expects a list. This causes len() and iteration on the returned Embeddings object to silently produce wrong results.


Summary
headersdict passed toAWSRequestfor signing contained the staleapi.cohere.comhost instead of the rewritten Bedrock/SageMaker host, causing signature mismatch errors. Fixed by syncingheaders["host"]after the URL rewrite.cohere_aws.Client.__init__unconditionally created SageMaker boto3 clients and asagemaker.Session, even for Bedrock users. Added amodeparameter (defaultMode.SAGEMAKERfor backwards compat) that conditionally initializes the correct service clients (bedrock-runtime/bedrockvssagemaker-runtime/sagemaker). SageMaker-only methods (connect_to_endpoint,create_endpoint,export_finetune,summarize,delete_endpoint) now raise a clear error if called in Bedrock mode.output_dimensionandembedding_typesto theembed()method signature, included injson_params(stripped whenNoneby existing cleanup loop).Closes #721
Test plan
test_bedrock_client.py(gated byTEST_AWSenv var) covering BedrockClientV2 signing,cohere_aws.Clientin Bedrock mode, and embed with v4 params.fernignore(safe from Fern regeneration)TEST_AWS=1+ AWS credential env vars)🤖 Generated with Claude Code
Note
Medium Risk
Touches request signing and AWS client initialization paths, where regressions could break Bedrock/SageMaker calls at runtime. Test coverage was added, but changes affect core connectivity/auth behavior.
Overview
Fixes AWS SigV4 signing for
AwsClientV2by ensuring the host header used during signing is updated after rewriting requests to Bedrock/SageMaker endpoints.Updates
cohere_aws.Clientto support a newmode(defaultMode.SAGEMAKER) that conditionally initializes Bedrock vs SageMaker boto3 clients and gates SageMaker-only operations with a clear error when used in Bedrock mode.Extends
cohere_aws.Client.embed()to accept and forwardoutput_dimensionandembedding_types, and adds unit + gated integration tests covering the signing fix, mode initialization, and new embed params.Written by Cursor Bugbot for commit bae43fa. This will update automatically on new commits. Configure here.