@ai-sdk/google 2.0.60 → 2.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.61
4
+
5
+ ### Patch Changes
6
+
7
+ - 3399b61: feat(provider/google): support multimodal content parts in embedding provider options
8
+
3
9
  ## 2.0.60
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -184,6 +184,14 @@ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'text-embeddi
184
184
  declare const googleGenerativeAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
185
185
  outputDimensionality?: number | undefined;
186
186
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
187
+ content?: ({
188
+ text: string;
189
+ } | {
190
+ inlineData: {
191
+ mimeType: string;
192
+ data: string;
193
+ };
194
+ })[] | undefined;
187
195
  }>;
188
196
  type GoogleGenerativeAIEmbeddingProviderOptions = InferValidator<typeof googleGenerativeAIEmbeddingProviderOptions>;
189
197
 
package/dist/index.d.ts CHANGED
@@ -184,6 +184,14 @@ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'text-embeddi
184
184
  declare const googleGenerativeAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
185
185
  outputDimensionality?: number | undefined;
186
186
  taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
187
+ content?: ({
188
+ text: string;
189
+ } | {
190
+ inlineData: {
191
+ mimeType: string;
192
+ data: string;
193
+ };
194
+ })[] | undefined;
187
195
  }>;
188
196
  type GoogleGenerativeAIEmbeddingProviderOptions = InferValidator<typeof googleGenerativeAIEmbeddingProviderOptions>;
189
197
 
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
30
30
  var import_provider_utils15 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.60" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.61" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -59,6 +59,15 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
59
59
  // src/google-generative-ai-embedding-options.ts
60
60
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
61
61
  var import_v42 = require("zod/v4");
62
+ var googleEmbeddingContentPartSchema = import_v42.z.union([
63
+ import_v42.z.object({ text: import_v42.z.string() }),
64
+ import_v42.z.object({
65
+ inlineData: import_v42.z.object({
66
+ mimeType: import_v42.z.string(),
67
+ data: import_v42.z.string()
68
+ })
69
+ })
70
+ ]);
62
71
  var googleGenerativeAIEmbeddingProviderOptions = (0, import_provider_utils2.lazySchema)(
63
72
  () => (0, import_provider_utils2.zodSchema)(
64
73
  import_v42.z.object({
@@ -88,7 +97,13 @@ var googleGenerativeAIEmbeddingProviderOptions = (0, import_provider_utils2.lazy
88
97
  "QUESTION_ANSWERING",
89
98
  "FACT_VERIFICATION",
90
99
  "CODE_RETRIEVAL_QUERY"
91
- ]).optional()
100
+ ]).optional(),
101
+ /**
102
+ * Optional. Multimodal content parts for embedding non-text content
103
+ * (images, video, PDF, audio). When provided, these parts are merged
104
+ * with the text values in the embedding request.
105
+ */
106
+ content: import_v42.z.array(googleEmbeddingContentPartSchema).min(1).optional()
92
107
  })
93
108
  )
94
109
  );
@@ -111,6 +126,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
111
126
  abortSignal,
112
127
  providerOptions
113
128
  }) {
129
+ var _a;
114
130
  const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
115
131
  provider: "google",
116
132
  providerOptions,
@@ -128,7 +144,10 @@ var GoogleGenerativeAIEmbeddingModel = class {
128
144
  await (0, import_provider_utils3.resolve)(this.config.headers),
129
145
  headers
130
146
  );
147
+ const multimodalContent = (_a = googleOptions == null ? void 0 : googleOptions.content) != null ? _a : [];
131
148
  if (values.length === 1) {
149
+ const textPart = values[0] ? [{ text: values[0] }] : [];
150
+ const parts = multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: values[0] }];
132
151
  const {
133
152
  responseHeaders: responseHeaders2,
134
153
  value: response2,
@@ -139,7 +158,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
139
158
  body: {
140
159
  model: `models/${this.modelId}`,
141
160
  content: {
142
- parts: [{ text: values[0] }]
161
+ parts
143
162
  },
144
163
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
145
164
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -165,12 +184,18 @@ var GoogleGenerativeAIEmbeddingModel = class {
165
184
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
166
185
  headers: mergedHeaders,
167
186
  body: {
168
- requests: values.map((value) => ({
169
- model: `models/${this.modelId}`,
170
- content: { role: "user", parts: [{ text: value }] },
171
- outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
172
- taskType: googleOptions == null ? void 0 : googleOptions.taskType
173
- }))
187
+ requests: values.map((value) => {
188
+ const textPart = value ? [{ text: value }] : [];
189
+ return {
190
+ model: `models/${this.modelId}`,
191
+ content: {
192
+ role: "user",
193
+ parts: multimodalContent.length > 0 ? [...textPart, ...multimodalContent] : [{ text: value }]
194
+ },
195
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
196
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
197
+ };
198
+ })
174
199
  },
175
200
  failedResponseHandler: googleFailedResponseHandler,
176
201
  successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(