5959 EmbeddingTaskType .CLUSTERING : EmbeddingTaskType .CLUSTERING ,
6060 5 : EmbeddingTaskType .CLUSTERING ,
6161 "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 ,
6270}
6371
6472
@@ -94,6 +102,7 @@ def embed_content(
94102 content : content_types .ContentType ,
95103 task_type : EmbeddingTaskTypeOptions | None = None ,
96104 title : str | None = None ,
105+ output_dimensionality : int | None = None ,
97106 client : glm .GenerativeServiceClient | None = None ,
98107 request_options : dict [str , Any ] | None = None ,
99108) -> text_types .EmbeddingDict : ...
@@ -105,6 +114,7 @@ def embed_content(
105114 content : Iterable [content_types .ContentType ],
106115 task_type : EmbeddingTaskTypeOptions | None = None ,
107116 title : str | None = None ,
117+ output_dimensionality : int | None = None ,
108118 client : glm .GenerativeServiceClient | None = None ,
109119 request_options : dict [str , Any ] | None = None ,
110120) -> text_types .BatchEmbeddingDict : ...
@@ -115,6 +125,7 @@ def embed_content(
115125 content : content_types .ContentType | Iterable [content_types .ContentType ],
116126 task_type : EmbeddingTaskTypeOptions | None = None ,
117127 title : str | None = None ,
128+ output_dimensionality : int | None = None ,
118129 client : glm .GenerativeServiceClient = None ,
119130 request_options : dict [str , Any ] | None = None ,
120131) -> text_types .EmbeddingDict | text_types .BatchEmbeddingDict :
@@ -135,6 +146,12 @@ def embed_content(
135146 title:
136147 An optional title for the text. Only applicable when task_type is
137148 `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+
138155 request_options:
139156 Options for the request.
140157
@@ -155,14 +172,21 @@ def embed_content(
155172 "If a title is specified, the task must be a retrieval document type task."
156173 )
157174
175+ if output_dimensionality and output_dimensionality < 0 :
176+ raise ValueError ("`output_dimensionality` must be a non-negative integer." )
177+
158178 if task_type :
159179 task_type = to_task_type (task_type )
160180
161181 if isinstance (content , Iterable ) and not isinstance (content , (str , Mapping )):
162182 result = {"embedding" : []}
163183 requests = (
164184 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 ,
166190 )
167191 for c in content
168192 )
@@ -177,7 +201,11 @@ def embed_content(
177201 return result
178202 else :
179203 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 ,
181209 )
182210 embedding_response = client .embed_content (
183211 embedding_request ,
@@ -194,6 +222,7 @@ async def embed_content_async(
194222 content : content_types .ContentType ,
195223 task_type : EmbeddingTaskTypeOptions | None = None ,
196224 title : str | None = None ,
225+ output_dimensionality : int | None = None ,
197226 client : glm .GenerativeServiceAsyncClient | None = None ,
198227 request_options : dict [str , Any ] | None = None ,
199228) -> text_types .EmbeddingDict : ...
@@ -205,6 +234,7 @@ async def embed_content_async(
205234 content : Iterable [content_types .ContentType ],
206235 task_type : EmbeddingTaskTypeOptions | None = None ,
207236 title : str | None = None ,
237+ output_dimensionality : int | None = None ,
208238 client : glm .GenerativeServiceAsyncClient | None = None ,
209239 request_options : dict [str , Any ] | None = None ,
210240) -> text_types .BatchEmbeddingDict : ...
@@ -215,6 +245,7 @@ async def embed_content_async(
215245 content : content_types .ContentType | Iterable [content_types .ContentType ],
216246 task_type : EmbeddingTaskTypeOptions | None = None ,
217247 title : str | None = None ,
248+ output_dimensionality : int | None = None ,
218249 client : glm .GenerativeServiceAsyncClient = None ,
219250 request_options : dict [str , Any ] | None = None ,
220251) -> text_types .EmbeddingDict | text_types .BatchEmbeddingDict :
@@ -232,14 +263,21 @@ async def embed_content_async(
232263 "If a title is specified, the task must be a retrieval document type task."
233264 )
234265
266+ if output_dimensionality and output_dimensionality < 0 :
267+ raise ValueError ("`output_dimensionality` must be a non-negative integer." )
268+
235269 if task_type :
236270 task_type = to_task_type (task_type )
237271
238272 if isinstance (content , Iterable ) and not isinstance (content , (str , Mapping )):
239273 result = {"embedding" : []}
240274 requests = (
241275 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 ,
243281 )
244282 for c in content
245283 )
@@ -254,7 +292,11 @@ async def embed_content_async(
254292 return result
255293 else :
256294 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 ,
258300 )
259301 embedding_response = await client .embed_content (
260302 embedding_request ,
0 commit comments