Skip to content

Conversation

@bitnahian
Copy link
Contributor

@bitnahian bitnahian commented Jan 15, 2026

Pre-Review Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • Linting and type checking pass per make format and make typecheck.
  • PR title is fit for the release changelog.

Pre-Merge Checklist

  • New tests for any fix or new behavior, maintaining 100% coverage.
  • Updated documentation for new features and behaviors, including docstrings for API docs.

@dsfaccini dsfaccini added new models Support for new model(s) bedrock embeddings feature New feature request, or PR implementing a feature (enhancement) labels Jan 15, 2026
@dsfaccini dsfaccini changed the title feat: add BedrockEmbeddingModel for Nova, Cohere and Titan endpoints feat: add BedrockEmbeddingModel for Nova, Cohere and Titan endpoints Jan 15, 2026
export AWS_REGION='us-east-1'
```
- **AWS credentials file** (`~/.aws/credentials`)
- **IAM roles** (when running on AWS infrastructure)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we do in https://ai.pydantic.dev/embeddings/#vertex-ai, let's link to the existing Bedrock doc that is the canonical source on how to configure the provider, that also has more details like that we support the AWS_BEARER_TOKEN_BEDROCK env var. So I'd prefer for that to be the main place we explain all the options, and for this to have an example + link there for more details; if you want to specifically mention ~/.aws/credentials for example, let's add it there, not here.


#### Basic Usage

```python {title="bedrock_embeddings.py" test="skip"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't skip testing examples unless we have no other option.


#### Supported Models

Bedrock supports three families of embedding models:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll get outdated, let's link to Amazon's doc on this and have just 1 example here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I see now that we specifically implement support these 3 families. So then it does make sense listing them, but I'd rather use subheadings so they show up in the ToC sidebar, and instead of one "Bedrock-Specific Settings", I think each model family section should have list its own settings, as they're model family specific right?

embedder = Embedder('bedrock:eu.cohere.embed-english-v3')
```

The model automatically normalizes these prefixes when looking up `max_input_tokens()`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this needs to be specified


#### Using a Custom Provider

For advanced configuration, you can create a [`BedrockProvider`][pydantic_ai.providers.bedrock.BedrockProvider] directly:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can have just one example here of building the provider yourself, and link to the existing bedrock docs for more details.

str(response_body),
)

return EmbeddingResult(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets simplify this method by returning only the embeddings + tokens + in some cases the response ID, and then build the EmbeddingResult where we call parse_response. Right now when we combine single-document runs, we deconstruct the individual EmbeddingResults and turn them into one combined one anyway, so let's skip the intermediate EmbeddingResult. That also means we no longer have to pass inputs, model_name etc into this method anymore.

def mock_vcr_botocore_content_length(mocker: MockerFixture):
# VCR doesn't properly handle botocore's content-length verification when replaying responses.
# This causes IncompleteReadError when the recorded response body length doesn't match the Content-Length header.
# This happens because VCR decodes compressed responses but doesn't update the Content-Length header.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we instead fix this by updating the Content-Length in tests/json_body_serializer.py's serialize method?

embeddings=IsList(IsList(IsFloat(), length=1024), length=1),
inputs=['Hello, world!'],
input_type='query',
usage=RequestUsage(input_tokens=IsInt()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For usage, can we see the actual value rather than IsInt? I want to make sure it's not 0



@pytest.mark.skipif(not bedrock_imports_successful(), reason='Bedrock not installed')
class TestBedrockHandlers:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to unit test this, assuming all the paths are covered by the integration test above?

"""Test error handling when ClientError is raised with HTTP status code."""
from botocore.exceptions import ClientError

from pydantic_ai.exceptions import ModelHTTPError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All imports at the top please

@bitnahian
Copy link
Contributor Author

@DouweM Are we keeping the clients opinionated to work as text embedding models only? For instance, Nova has a tonne of multi-modal specific parameters and if we're restricting to text only, we shouldn't surface them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting author revision bedrock embeddings feature New feature request, or PR implementing a feature (enhancement) new models Support for new model(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants