Skip to content

Commit 70d8f53

Browse files
speedstorm1copybara-github
authored andcommitted
chore: support new config mappings and fields for gemini-embedding-2 on GenAI SDK
PiperOrigin-RevId: 897443062
1 parent 3615ca2 commit 70d8f53

6 files changed

Lines changed: 90 additions & 4 deletions

File tree

api-report/genai-node.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,9 @@ export interface EmbedContentBatch {
10441044
// @public
10451045
export interface EmbedContentConfig {
10461046
abortSignal?: AbortSignal;
1047+
audioTrackExtraction?: boolean;
10471048
autoTruncate?: boolean;
1049+
documentOcr?: boolean;
10481050
httpOptions?: HttpOptions;
10491051
mimeType?: string;
10501052
outputDimensionality?: number;

api-report/genai-web.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,9 @@ export interface EmbedContentBatch {
10441044
// @public
10451045
export interface EmbedContentConfig {
10461046
abortSignal?: AbortSignal;
1047+
audioTrackExtraction?: boolean;
10471048
autoTruncate?: boolean;
1049+
documentOcr?: boolean;
10481050
httpOptions?: HttpOptions;
10491051
mimeType?: string;
10501052
outputDimensionality?: number;

api-report/genai.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,9 @@ export interface EmbedContentBatch {
10441044
// @public
10451045
export interface EmbedContentConfig {
10461046
abortSignal?: AbortSignal;
1047+
audioTrackExtraction?: boolean;
10471048
autoTruncate?: boolean;
1049+
documentOcr?: boolean;
10481050
httpOptions?: HttpOptions;
10491051
mimeType?: string;
10501052
outputDimensionality?: number;

src/converters/_batches_converters.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,18 @@ export function embedContentConfigToMldev(
928928
throw new Error('autoTruncate parameter is not supported in Gemini API.');
929929
}
930930

931+
if (common.getValueByPath(fromObject, ['documentOcr']) !== undefined) {
932+
throw new Error('documentOcr parameter is not supported in Gemini API.');
933+
}
934+
935+
if (
936+
common.getValueByPath(fromObject, ['audioTrackExtraction']) !== undefined
937+
) {
938+
throw new Error(
939+
'audioTrackExtraction parameter is not supported in Gemini API.',
940+
);
941+
}
942+
931943
return toObject;
932944
}
933945

src/converters/_models_converters.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,18 @@ export function embedContentConfigToMldev(
912912
throw new Error('autoTruncate parameter is not supported in Gemini API.');
913913
}
914914

915+
if (common.getValueByPath(fromObject, ['documentOcr']) !== undefined) {
916+
throw new Error('documentOcr parameter is not supported in Gemini API.');
917+
}
918+
919+
if (
920+
common.getValueByPath(fromObject, ['audioTrackExtraction']) !== undefined
921+
) {
922+
throw new Error(
923+
'audioTrackExtraction parameter is not supported in Gemini API.',
924+
);
925+
}
926+
915927
return toObject;
916928
}
917929

@@ -940,7 +952,11 @@ export function embedContentConfigToVertex(
940952
} else if (discriminatorTaskType === 'EMBED_CONTENT') {
941953
const fromTaskType = common.getValueByPath(fromObject, ['taskType']);
942954
if (parentObject !== undefined && fromTaskType != null) {
943-
common.setValueByPath(parentObject, ['taskType'], fromTaskType);
955+
common.setValueByPath(
956+
parentObject,
957+
['embedContentConfig', 'taskType'],
958+
fromTaskType,
959+
);
944960
}
945961
}
946962

@@ -958,7 +974,11 @@ export function embedContentConfigToVertex(
958974
} else if (discriminatorTitle === 'EMBED_CONTENT') {
959975
const fromTitle = common.getValueByPath(fromObject, ['title']);
960976
if (parentObject !== undefined && fromTitle != null) {
961-
common.setValueByPath(parentObject, ['title'], fromTitle);
977+
common.setValueByPath(
978+
parentObject,
979+
['embedContentConfig', 'title'],
980+
fromTitle,
981+
);
962982
}
963983
}
964984

@@ -986,7 +1006,7 @@ export function embedContentConfigToVertex(
9861006
if (parentObject !== undefined && fromOutputDimensionality != null) {
9871007
common.setValueByPath(
9881008
parentObject,
989-
['outputDimensionality'],
1009+
['embedContentConfig', 'outputDimensionality'],
9901010
fromOutputDimensionality,
9911011
);
9921012
}
@@ -1031,7 +1051,47 @@ export function embedContentConfigToVertex(
10311051
'autoTruncate',
10321052
]);
10331053
if (parentObject !== undefined && fromAutoTruncate != null) {
1034-
common.setValueByPath(parentObject, ['autoTruncate'], fromAutoTruncate);
1054+
common.setValueByPath(
1055+
parentObject,
1056+
['embedContentConfig', 'autoTruncate'],
1057+
fromAutoTruncate,
1058+
);
1059+
}
1060+
}
1061+
1062+
let discriminatorDocumentOcr = common.getValueByPath(rootObject, [
1063+
'embeddingApiType',
1064+
]);
1065+
if (discriminatorDocumentOcr === undefined) {
1066+
discriminatorDocumentOcr = 'PREDICT';
1067+
}
1068+
if (discriminatorDocumentOcr === 'EMBED_CONTENT') {
1069+
const fromDocumentOcr = common.getValueByPath(fromObject, ['documentOcr']);
1070+
if (parentObject !== undefined && fromDocumentOcr != null) {
1071+
common.setValueByPath(
1072+
parentObject,
1073+
['embedContentConfig', 'documentOcr'],
1074+
fromDocumentOcr,
1075+
);
1076+
}
1077+
}
1078+
1079+
let discriminatorAudioTrackExtraction = common.getValueByPath(rootObject, [
1080+
'embeddingApiType',
1081+
]);
1082+
if (discriminatorAudioTrackExtraction === undefined) {
1083+
discriminatorAudioTrackExtraction = 'PREDICT';
1084+
}
1085+
if (discriminatorAudioTrackExtraction === 'EMBED_CONTENT') {
1086+
const fromAudioTrackExtraction = common.getValueByPath(fromObject, [
1087+
'audioTrackExtraction',
1088+
]);
1089+
if (parentObject !== undefined && fromAudioTrackExtraction != null) {
1090+
common.setValueByPath(
1091+
parentObject,
1092+
['embedContentConfig', 'audioTrackExtraction'],
1093+
fromAudioTrackExtraction,
1094+
);
10351095
}
10361096
}
10371097

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,6 +3659,14 @@ export declare interface EmbedContentConfig {
36593659
will lead to an INVALID_ARGUMENT error, similar to other text APIs.
36603660
*/
36613661
autoTruncate?: boolean;
3662+
/** Vertex API only. Whether to enable OCR for document content.
3663+
Only applicable to Gemini Embedding 2 models.
3664+
*/
3665+
documentOcr?: boolean;
3666+
/** Vertex API only. Whether to extract audio from video content.
3667+
Only applicable to Gemini Embedding 2 models.
3668+
*/
3669+
audioTrackExtraction?: boolean;
36623670
}
36633671

36643672
/** Parameters for the _embed_content method. */

0 commit comments

Comments
 (0)