59
59
EmbeddingTaskType .CLUSTERING : EmbeddingTaskType .CLUSTERING ,
60
60
5 : EmbeddingTaskType .CLUSTERING ,
61
61
"clustering" : EmbeddingTaskType .CLUSTERING ,
62
+ 6 : EmbeddingTaskType .QUESTION_ANSWERING ,
63
+ "question_answering" : EmbeddingTaskType .QUESTION_ANSWERING ,
64
+ "qa" : EmbeddingTaskType .QUESTION_ANSWERING ,
65
+ EmbeddingTaskType .QUESTION_ANSWERING : EmbeddingTaskType .QUESTION_ANSWERING ,
66
+ 7 : EmbeddingTaskType .FACT_VERIFICATION ,
67
+ "fact_verification" : EmbeddingTaskType .FACT_VERIFICATION ,
68
+ "verification" : EmbeddingTaskType .FACT_VERIFICATION ,
69
+ EmbeddingTaskType .FACT_VERIFICATION : EmbeddingTaskType .FACT_VERIFICATION ,
62
70
}
63
71
64
72
@@ -94,6 +102,7 @@ def embed_content(
94
102
content : content_types .ContentType ,
95
103
task_type : EmbeddingTaskTypeOptions | None = None ,
96
104
title : str | None = None ,
105
+ output_dimensionality : int | None = None ,
97
106
client : glm .GenerativeServiceClient | None = None ,
98
107
request_options : dict [str , Any ] | None = None ,
99
108
) -> text_types .EmbeddingDict : ...
@@ -105,6 +114,7 @@ def embed_content(
105
114
content : Iterable [content_types .ContentType ],
106
115
task_type : EmbeddingTaskTypeOptions | None = None ,
107
116
title : str | None = None ,
117
+ output_dimensionality : int | None = None ,
108
118
client : glm .GenerativeServiceClient | None = None ,
109
119
request_options : dict [str , Any ] | None = None ,
110
120
) -> text_types .BatchEmbeddingDict : ...
@@ -115,6 +125,7 @@ def embed_content(
115
125
content : content_types .ContentType | Iterable [content_types .ContentType ],
116
126
task_type : EmbeddingTaskTypeOptions | None = None ,
117
127
title : str | None = None ,
128
+ output_dimensionality : int | None = None ,
118
129
client : glm .GenerativeServiceClient = None ,
119
130
request_options : dict [str , Any ] | None = None ,
120
131
) -> text_types .EmbeddingDict | text_types .BatchEmbeddingDict :
@@ -135,6 +146,12 @@ def embed_content(
135
146
title:
136
147
An optional title for the text. Only applicable when task_type is
137
148
`RETRIEVAL_DOCUMENT`.
149
+
150
+ output_dimensionality:
151
+ Optional reduced dimensionality for the output embeddings. If set,
152
+ excessive values from the output embeddings will be truncated from
153
+ the end.
154
+
138
155
request_options:
139
156
Options for the request.
140
157
@@ -155,14 +172,21 @@ def embed_content(
155
172
"If a title is specified, the task must be a retrieval document type task."
156
173
)
157
174
175
+ if output_dimensionality and output_dimensionality < 0 :
176
+ raise ValueError ("`output_dimensionality` must be a non-negative integer." )
177
+
158
178
if task_type :
159
179
task_type = to_task_type (task_type )
160
180
161
181
if isinstance (content , Iterable ) and not isinstance (content , (str , Mapping )):
162
182
result = {"embedding" : []}
163
183
requests = (
164
184
glm .EmbedContentRequest (
165
- model = model , content = content_types .to_content (c ), task_type = task_type , title = title
185
+ model = model ,
186
+ content = content_types .to_content (c ),
187
+ task_type = task_type ,
188
+ title = title ,
189
+ output_dimensionality = output_dimensionality ,
166
190
)
167
191
for c in content
168
192
)
@@ -177,7 +201,11 @@ def embed_content(
177
201
return result
178
202
else :
179
203
embedding_request = glm .EmbedContentRequest (
180
- model = model , content = content_types .to_content (content ), task_type = task_type , title = title
204
+ model = model ,
205
+ content = content_types .to_content (content ),
206
+ task_type = task_type ,
207
+ title = title ,
208
+ output_dimensionality = output_dimensionality ,
181
209
)
182
210
embedding_response = client .embed_content (
183
211
embedding_request ,
@@ -194,6 +222,7 @@ async def embed_content_async(
194
222
content : content_types .ContentType ,
195
223
task_type : EmbeddingTaskTypeOptions | None = None ,
196
224
title : str | None = None ,
225
+ output_dimensionality : int | None = None ,
197
226
client : glm .GenerativeServiceAsyncClient | None = None ,
198
227
request_options : dict [str , Any ] | None = None ,
199
228
) -> text_types .EmbeddingDict : ...
@@ -205,6 +234,7 @@ async def embed_content_async(
205
234
content : Iterable [content_types .ContentType ],
206
235
task_type : EmbeddingTaskTypeOptions | None = None ,
207
236
title : str | None = None ,
237
+ output_dimensionality : int | None = None ,
208
238
client : glm .GenerativeServiceAsyncClient | None = None ,
209
239
request_options : dict [str , Any ] | None = None ,
210
240
) -> text_types .BatchEmbeddingDict : ...
@@ -215,6 +245,7 @@ async def embed_content_async(
215
245
content : content_types .ContentType | Iterable [content_types .ContentType ],
216
246
task_type : EmbeddingTaskTypeOptions | None = None ,
217
247
title : str | None = None ,
248
+ output_dimensionality : int | None = None ,
218
249
client : glm .GenerativeServiceAsyncClient = None ,
219
250
request_options : dict [str , Any ] | None = None ,
220
251
) -> text_types .EmbeddingDict | text_types .BatchEmbeddingDict :
@@ -232,14 +263,21 @@ async def embed_content_async(
232
263
"If a title is specified, the task must be a retrieval document type task."
233
264
)
234
265
266
+ if output_dimensionality and output_dimensionality < 0 :
267
+ raise ValueError ("`output_dimensionality` must be a non-negative integer." )
268
+
235
269
if task_type :
236
270
task_type = to_task_type (task_type )
237
271
238
272
if isinstance (content , Iterable ) and not isinstance (content , (str , Mapping )):
239
273
result = {"embedding" : []}
240
274
requests = (
241
275
glm .EmbedContentRequest (
242
- model = model , content = content_types .to_content (c ), task_type = task_type , title = title
276
+ model = model ,
277
+ content = content_types .to_content (c ),
278
+ task_type = task_type ,
279
+ title = title ,
280
+ output_dimensionality = output_dimensionality ,
243
281
)
244
282
for c in content
245
283
)
@@ -254,7 +292,11 @@ async def embed_content_async(
254
292
return result
255
293
else :
256
294
embedding_request = glm .EmbedContentRequest (
257
- model = model , content = content_types .to_content (content ), task_type = task_type , title = title
295
+ model = model ,
296
+ content = content_types .to_content (content ),
297
+ task_type = task_type ,
298
+ title = title ,
299
+ output_dimensionality = output_dimensionality ,
258
300
)
259
301
embedding_response = await client .embed_content (
260
302
embedding_request ,
0 commit comments