You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Use embedding for vector search, clustering, etc.
74
74
```
75
75
76
+
Amazon Titan Multimodal Embeddings support both text and image at the same time. The resulting embeddings vector averages the text embeddings and image embeddings vectors.
77
+
78
+
```python
79
+
from idp_common.bedrock.client import BedrockClient
80
+
81
+
withopen("/path/to/document.png", "rb") as image_file:
82
+
image_data = image_file.read()
83
+
84
+
client = BedrockClient()
85
+
embedding = client.generate_embedding(
86
+
text="This document contains information about loan applications.",
87
+
image_source=image_data,
88
+
model_id="amazon.titan-embed-image-v1"
89
+
)
90
+
```
91
+
92
+
The image source can also be an S3 URI:
93
+
94
+
```python
95
+
from idp_common.bedrock.client import BedrockClient
96
+
97
+
client = BedrockClient()
98
+
embedding = client.generate_embedding(
99
+
image_data="s3://bucket/key",
100
+
model_id="amazon.titan-embed-image-v1"
101
+
)
102
+
```
103
+
104
+
Amazon Nova Multimodal Embeddings with 3072 dimension size:
105
+
106
+
```python
107
+
from idp_common.bedrock.client import BedrockClient
Prompt caching is a powerful feature in Amazon Bedrock that significantly reduces response latency for workloads with repetitive contexts. The Bedrock client provides built-in support for this via the `<<CACHEPOINT>>` tag.
Generate an embedding vector for the given text using Amazon Bedrock.
712
+
Generate an embedding vector for the given text or image_source using Amazon Bedrock.
713
+
At least one of text or the image is required to generate the embedding.
714
+
For Titan Multimodal embedding models, you can include both to create an embeddings query vector that averages the resulting text embeddings and image embeddings vectors.
715
+
For Nova Multimodal embedding models, exactly one of text or the image must be present, but not both.
707
716
708
717
Args:
709
718
text: The text to generate embeddings for
719
+
image_source: The image to generate embeddings for (can be either an S3 URI (s3://bucket/key) or raw image bytes)
710
720
model_id: The embedding model ID to use (default: amazon.titan-embed-text-v1)
711
721
max_retries: Optional override for the instance's max_retries setting
722
+
dimensions: Length of the output embeddings vector
712
723
713
724
Returns:
714
725
List of floats representing the embedding vector
715
726
"""
716
-
ifnottextornotisinstance(text, str):
727
+
if(nottextornotisinstance(text, str)) and (notimage_source):
0 commit comments