@@ -2003,12 +2003,14 @@ def _prepare_text_embedding_request(
2003
2003
texts : List [Union [str , TextEmbeddingInput ]],
2004
2004
* ,
2005
2005
auto_truncate : bool = True ,
2006
+ output_dimensionality : Optional [int ] = None ,
2006
2007
) -> _MultiInstancePredictionRequest :
2007
2008
"""Asynchronously calculates embeddings for the given texts.
2008
2009
2009
2010
Args:
2010
2011
texts(str): A list of texts or `TextEmbeddingInput` objects to embed.
2011
2012
auto_truncate(bool): Whether to automatically truncate long texts. Default: True.
2013
+ output_dimensionality: Optional dimensions of embeddings. Range: [1, 768]. Default: None.
2012
2014
2013
2015
Returns:
2014
2016
A `_MultiInstancePredictionRequest` object.
@@ -2029,6 +2031,8 @@ def _prepare_text_embedding_request(
2029
2031
raise TypeError (f"Unsupported text embedding input type: { text } ." )
2030
2032
instances .append (instance )
2031
2033
parameters = {"autoTruncate" : auto_truncate }
2034
+ if output_dimensionality is not None :
2035
+ parameters ["outputDimensionality" ] = output_dimensionality
2032
2036
return _MultiInstancePredictionRequest (
2033
2037
instances = instances ,
2034
2038
parameters = parameters ,
@@ -2057,19 +2061,22 @@ def get_embeddings(
2057
2061
texts : List [Union [str , TextEmbeddingInput ]],
2058
2062
* ,
2059
2063
auto_truncate : bool = True ,
2064
+ output_dimensionality : Optional [int ] = None
2060
2065
) -> List ["TextEmbedding" ]:
2061
2066
"""Calculates embeddings for the given texts.
2062
2067
2063
2068
Args:
2064
- texts(str): A list of texts or `TextEmbeddingInput` objects to embed.
2065
- auto_truncate(bool): Whether to automatically truncate long texts. Default: True.
2069
+ texts: A list of texts or `TextEmbeddingInput` objects to embed.
2070
+ auto_truncate: Whether to automatically truncate long texts. Default: True.
2071
+ output_dimensionality: Optional dimensions of embeddings. Range: [1, 768]. Default: None.
2066
2072
2067
2073
Returns:
2068
2074
A list of `TextEmbedding` objects.
2069
2075
"""
2070
2076
prediction_request = self ._prepare_text_embedding_request (
2071
2077
texts = texts ,
2072
2078
auto_truncate = auto_truncate ,
2079
+ output_dimensionality = output_dimensionality ,
2073
2080
)
2074
2081
2075
2082
prediction_response = self ._endpoint .predict (
@@ -2092,19 +2099,22 @@ async def get_embeddings_async(
2092
2099
texts : List [Union [str , TextEmbeddingInput ]],
2093
2100
* ,
2094
2101
auto_truncate : bool = True ,
2102
+ output_dimensionality : Optional [int ] = None ,
2095
2103
) -> List ["TextEmbedding" ]:
2096
2104
"""Asynchronously calculates embeddings for the given texts.
2097
2105
2098
2106
Args:
2099
- texts(str): A list of texts or `TextEmbeddingInput` objects to embed.
2100
- auto_truncate(bool): Whether to automatically truncate long texts. Default: True.
2107
+ texts: A list of texts or `TextEmbeddingInput` objects to embed.
2108
+ auto_truncate: Whether to automatically truncate long texts. Default: True.
2109
+ output_dimensionality: Optional dimensions of embeddings. Range: [1, 768]. Default: None.
2101
2110
2102
2111
Returns:
2103
2112
A list of `TextEmbedding` objects.
2104
2113
"""
2105
2114
prediction_request = self ._prepare_text_embedding_request (
2106
2115
texts = texts ,
2107
2116
auto_truncate = auto_truncate ,
2117
+ output_dimensionality = output_dimensionality
2108
2118
)
2109
2119
2110
2120
prediction_response = await self ._endpoint .predict_async (
0 commit comments