@@ -234,28 +234,32 @@ class MultiModalEmbeddingModel(_model_garden_models._ModelGardenModel):
234
234
)
235
235
236
236
def get_embeddings (
237
- self , image : Image , contextual_text : Optional [str ] = None
237
+ self , image : Optional [ Image ] = None , contextual_text : Optional [str ] = None
238
238
) -> "MultiModalEmbeddingResponse" :
239
239
"""Gets embedding vectors from the provided image.
240
240
241
241
Args:
242
242
image (Image):
243
- The image to generate embeddings for.
243
+ Optional. The image to generate embeddings for. One of `image` or `contextual_text` is required .
244
244
contextual_text (str):
245
245
Optional. Contextual text for your input image. If provided, the model will also
246
246
generate an embedding vector for the provided contextual text. The returned image
247
247
and text embedding vectors are in the same semantic space with the same dimensionality,
248
248
and the vectors can be used interchangeably for use cases like searching image by text
249
- or searching text by image.
249
+ or searching text by image. One of `image` or `contextual_text` is required.
250
250
251
251
Returns:
252
252
ImageEmbeddingResponse:
253
253
The image and text embedding vectors.
254
254
"""
255
255
256
- instance = {
257
- "image" : {"bytesBase64Encoded" : image ._as_base64_string ()},
258
- }
256
+ if not image and not contextual_text :
257
+ raise ValueError ("One of `image` or `contextual_text` is required." )
258
+
259
+ instance = {}
260
+
261
+ if image :
262
+ instance ["image" ] = {"bytesBase64Encoded" : image ._as_base64_string ()}
259
263
260
264
if contextual_text :
261
265
instance ["text" ] = contextual_text
@@ -280,11 +284,11 @@ class MultiModalEmbeddingResponse:
280
284
281
285
Attributes:
282
286
image_embedding (List[float]):
283
- The emebedding vector generated from your image.
287
+ Optional. The embedding vector generated from your image.
284
288
text_embedding (List[float]):
285
289
Optional. The embedding vector generated from the contextual text provided for your image.
286
290
"""
287
291
288
- image_embedding : List [float ]
289
292
_prediction_response : Any
293
+ image_embedding : Optional [List [float ]] = None
290
294
text_embedding : Optional [List [float ]] = None
0 commit comments