Skip to content

Commit

Permalink
Merge branch 'main' into mongodb-keyword-search
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje authored Dec 5, 2024
2 parents a658301 + 2c80a0b commit 140bb4b
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 48 deletions.
78 changes: 70 additions & 8 deletions integrations/amazon_bedrock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
# Changelog

## [integrations/amazon_bedrock-v1.1.1] - 2024-12-03

### 🐛 Bug Fixes

- AmazonBedrockChatGenerator with Claude raises moot warning for stream… (#1205)
- Allow passing boto3 config to all AWS Bedrock classes (#1166)

### 🧹 Chores

- Fix linting/isort (#1215)

### 🌀 Miscellaneous

- Chore: use class methods to create `ChatMessage` (#1222)

## [integrations/amazon_bedrock-v1.1.0] - 2024-10-23

### 🚜 Refactor

- Avoid downloading tokenizer if `truncate` is `False` (#1152)

### ⚙️ Miscellaneous Tasks
### ⚙️ CI

- Adopt uv as installer (#1142)


## [integrations/amazon_bedrock-v1.0.5] - 2024-10-17

### 🚀 Features

- Add prefixes to supported model patterns to allow cross region model ids (#1127)


## [integrations/amazon_bedrock-v1.0.4] - 2024-10-16

### 🐛 Bug Fixes

- Avoid bedrock read timeout (add boto3_config param) (#1135)


## [integrations/amazon_bedrock-v1.0.3] - 2024-10-04

### 🐛 Bug Fixes
Expand All @@ -33,10 +51,14 @@

- Remove usage of deprecated `ChatMessage.to_openai_format` (#1007)

### ⚙️ Miscellaneous Tasks
### 🧹 Chores

- Update ruff linting scripts and settings (#1105)

### 🌀 Miscellaneous

- Modify regex to allow cross-region inference in bedrock (#1120)

## [integrations/amazon_bedrock-v1.0.1] - 2024-08-19

### 🚀 Features
Expand All @@ -47,6 +69,7 @@

- Normalising ChatGenerators output (#973)


## [integrations/amazon_bedrock-v1.0.0] - 2024-08-12

### 🚜 Refactor
Expand All @@ -57,13 +80,14 @@

- Do not retry tests in `hatch run test` command (#954)


## [integrations/amazon_bedrock-v0.10.0] - 2024-08-12

### 🐛 Bug Fixes

- Support streaming_callback param in amazon bedrock generators (#927)

### Docs
### 🌀 Miscellaneous

- Update AmazonBedrockChatGenerator docstrings (#949)
- Update AmazonBedrockGenerator docstrings (#956)
Expand All @@ -75,11 +99,19 @@
- Use non-gated tokenizer as fallback for mistral in AmazonBedrockChatGenerator (#843)
- Made truncation optional for BedrockGenerator (#833)

### ⚙️ Miscellaneous Tasks
### ⚙️ CI

- Retry tests to reduce flakyness (#836)

### 🧹 Chores

- Update ruff invocation to include check parameter (#853)

### 🌀 Miscellaneous

- Ci: install `pytest-rerunfailures` where needed; add retry config to `test-cov` script (#845)
- Add meta deprecration warning (#910)

## [integrations/amazon_bedrock-v0.9.0] - 2024-06-14

### 🚀 Features
Expand All @@ -96,8 +128,18 @@

- Max_tokens typo in Mistral Chat (#740)

### 🌀 Miscellaneous

- Chore: change the pydoc renderer class (#718)
- Adding support of "amazon.titan-embed-text-v2:0" (#735)

## [integrations/amazon_bedrock-v0.7.1] - 2024-04-24

### 🌀 Miscellaneous

- Chore: add license classifiers (#680)
- Fix: Fix streaming_callback serialization in AmazonBedrockChatGenerator (#685)

## [integrations/amazon_bedrock-v0.7.0] - 2024-04-16

### 🚀 Features
Expand All @@ -108,6 +150,11 @@

- Disable-class-def (#556)

### 🌀 Miscellaneous

- Remove references to Python 3.7 (#601)
- [Bedrock] Added Amazon Bedrock examples (#635)

## [integrations/amazon_bedrock-v0.6.0] - 2024-03-11

### 🚀 Features
Expand All @@ -119,6 +166,10 @@
- Small consistency improvements (#536)
- Review integrations bedrock (#550)

### 🌀 Miscellaneous

- Docs updates + two additional unit tests (#513)

## [integrations/amazon_bedrock-v0.5.1] - 2024-02-22

### 🚀 Features
Expand All @@ -129,25 +180,36 @@

- Fix order of API docs (#447)

This PR will also push the docs to Readme

### 📚 Documentation

- Update category slug (#442)

### ⚙️ Miscellaneous Tasks
### 🧹 Chores

- Update Amazon Bedrock integration to use new generic callable (de)serializers for their callback handlers (#452)
- Use `serialize_callable` instead of `serialize_callback_handler` in Bedrock (#459)

### 🌀 Miscellaneous

- Amazon bedrock: generate api docs (#326)
- Adopt Secret to Amazon Bedrock (#416)
- Bedrock - remove `supports` method (#456)
- Bedrock refactoring (#455)
- Bedrock Text Embedder (#466)
- Bedrock Document Embedder (#468)

## [integrations/amazon_bedrock-v0.3.0] - 2024-01-30

### ⚙️ Miscellaneous Tasks
### 🧹 Chores

- [**breaking**] Rename `model_name` to `model` in `AmazonBedrockGenerator` (#220)
- Amazon Bedrock subproject refactoring (#293)
- Adjust amazon bedrock helper classes names (#297)

## [integrations/amazon_bedrock-v0.1.0] - 2024-01-03

### 🌀 Miscellaneous

- [Amazon Bedrock] Add AmazonBedrockGenerator (#153)

<!-- generated by git-cliff -->
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Any, Dict, List, Literal, Optional

from botocore.config import Config
from botocore.exceptions import ClientError
from haystack import component, default_from_dict, default_to_dict
from haystack.dataclasses import Document
Expand Down Expand Up @@ -73,6 +74,7 @@ def __init__(
progress_bar: bool = True,
meta_fields_to_embed: Optional[List[str]] = None,
embedding_separator: str = "\n",
boto3_config: Optional[Dict[str, Any]] = None,
**kwargs,
):
"""
Expand All @@ -98,6 +100,7 @@ def __init__(
to keep the logs clean.
:param meta_fields_to_embed: List of meta fields that should be embedded along with the Document text.
:param embedding_separator: Separator used to concatenate the meta fields to the Document text.
:param boto3_config: The configuration for the boto3 client.
:param kwargs: Additional parameters to pass for model inference. For example, `input_type` and `truncate` for
Cohere models.
:raises ValueError: If the model is not supported.
Expand All @@ -110,6 +113,19 @@ def __init__(
)
raise ValueError(msg)

self.model = model
self.aws_access_key_id = aws_access_key_id
self.aws_secret_access_key = aws_secret_access_key
self.aws_session_token = aws_session_token
self.aws_region_name = aws_region_name
self.aws_profile_name = aws_profile_name
self.batch_size = batch_size
self.progress_bar = progress_bar
self.meta_fields_to_embed = meta_fields_to_embed or []
self.embedding_separator = embedding_separator
self.boto3_config = boto3_config
self.kwargs = kwargs

def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
return secret.resolve_value() if secret else None

Expand All @@ -121,26 +137,17 @@ def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
aws_region_name=resolve_secret(aws_region_name),
aws_profile_name=resolve_secret(aws_profile_name),
)
self._client = session.client("bedrock-runtime")
config: Optional[Config] = None
if self.boto3_config:
config = Config(**self.boto3_config)
self._client = session.client("bedrock-runtime", config=config)
except Exception as exception:
msg = (
"Could not connect to Amazon Bedrock. Make sure the AWS environment is configured correctly. "
"See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration"
)
raise AmazonBedrockConfigurationError(msg) from exception

self.model = model
self.aws_access_key_id = aws_access_key_id
self.aws_secret_access_key = aws_secret_access_key
self.aws_session_token = aws_session_token
self.aws_region_name = aws_region_name
self.aws_profile_name = aws_profile_name
self.batch_size = batch_size
self.progress_bar = progress_bar
self.meta_fields_to_embed = meta_fields_to_embed or []
self.embedding_separator = embedding_separator
self.kwargs = kwargs

def _prepare_texts_to_embed(self, documents: List[Document]) -> List[str]:
"""
Prepare the texts to embed by concatenating the Document text with the metadata fields to embed.
Expand Down Expand Up @@ -269,6 +276,7 @@ def to_dict(self) -> Dict[str, Any]:
progress_bar=self.progress_bar,
meta_fields_to_embed=self.meta_fields_to_embed,
embedding_separator=self.embedding_separator,
boto3_config=self.boto3_config,
**self.kwargs,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Any, Dict, List, Literal, Optional

from botocore.config import Config
from botocore.exceptions import ClientError
from haystack import component, default_from_dict, default_to_dict
from haystack.utils.auth import Secret, deserialize_secrets_inplace
Expand Down Expand Up @@ -62,6 +63,7 @@ def __init__(
aws_session_token: Optional[Secret] = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
aws_region_name: Optional[Secret] = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
aws_profile_name: Optional[Secret] = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
boto3_config: Optional[Dict[str, Any]] = None,
**kwargs,
):
"""
Expand All @@ -81,6 +83,7 @@ def __init__(
:param aws_session_token: AWS session token.
:param aws_region_name: AWS region name.
:param aws_profile_name: AWS profile name.
:param boto3_config: The configuration for the boto3 client.
:param kwargs: Additional parameters to pass for model inference. For example, `input_type` and `truncate` for
Cohere models.
:raises ValueError: If the model is not supported.
Expand All @@ -92,6 +95,15 @@ def __init__(
)
raise ValueError(msg)

self.model = model
self.aws_access_key_id = aws_access_key_id
self.aws_secret_access_key = aws_secret_access_key
self.aws_session_token = aws_session_token
self.aws_region_name = aws_region_name
self.aws_profile_name = aws_profile_name
self.boto3_config = boto3_config
self.kwargs = kwargs

def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
return secret.resolve_value() if secret else None

Expand All @@ -103,22 +115,17 @@ def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
aws_region_name=resolve_secret(aws_region_name),
aws_profile_name=resolve_secret(aws_profile_name),
)
self._client = session.client("bedrock-runtime")
config: Optional[Config] = None
if self.boto3_config:
config = Config(**self.boto3_config)
self._client = session.client("bedrock-runtime", config=config)
except Exception as exception:
msg = (
"Could not connect to Amazon Bedrock. Make sure the AWS environment is configured correctly. "
"See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration"
)
raise AmazonBedrockConfigurationError(msg) from exception

self.model = model
self.aws_access_key_id = aws_access_key_id
self.aws_secret_access_key = aws_secret_access_key
self.aws_session_token = aws_session_token
self.aws_region_name = aws_region_name
self.aws_profile_name = aws_profile_name
self.kwargs = kwargs

@component.output_types(embedding=List[float])
def run(self, text: str):
"""Embeds the input text using the Amazon Bedrock model.
Expand Down Expand Up @@ -185,6 +192,7 @@ def to_dict(self) -> Dict[str, Any]:
aws_region_name=self.aws_region_name.to_dict() if self.aws_region_name else None,
aws_profile_name=self.aws_profile_name.to_dict() if self.aws_profile_name else None,
model=self.model,
boto3_config=self.boto3_config,
**self.kwargs,
)

Expand Down
Loading

0 comments on commit 140bb4b

Please sign in to comment.