@ai-sdk/google 2.0.60 → 2.0.62

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,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.62
4
+
5
+ ### Patch Changes
6
+
7
+ - a608d48: feat(provider/google): add `gemini-embedding-2-preview` and fix multimodal embedding support with `embedMany`
8
+
9
+ ## 2.0.61
10
+
11
+ ### Patch Changes
12
+
13
+ - 3399b61: feat(provider/google): support multimodal content parts in embedding provider options
14
+
3
15
  ## 2.0.60
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -180,10 +180,18 @@ declare const googleImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchem
180
180
  }>;
181
181
  type GoogleGenerativeAIImageProviderOptions = InferValidator<typeof googleImageProviderOptionsSchema>;
182
182
 
183
- type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'text-embedding-004' | (string & {});
183
+ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
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
+ })[] | null)[] | undefined;
187
195
  }>;
188
196
  type GoogleGenerativeAIEmbeddingProviderOptions = InferValidator<typeof googleGenerativeAIEmbeddingProviderOptions>;
189
197
 
package/dist/index.d.ts CHANGED
@@ -180,10 +180,18 @@ declare const googleImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchem
180
180
  }>;
181
181
  type GoogleGenerativeAIImageProviderOptions = InferValidator<typeof googleImageProviderOptionsSchema>;
182
182
 
183
- type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'text-embedding-004' | (string & {});
183
+ type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
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
+ })[] | null)[] | 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.62" : "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,17 @@ 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. Per-value multimodal content parts for embedding non-text
103
+ * content (images, video, PDF, audio). Each entry corresponds to the
104
+ * embedding value at the same index and its parts are merged with the
105
+ * text value in the request. Use `null` for entries that are text-only.
106
+ *
107
+ * The array length must match the number of values being embedded. In
108
+ * the case of a single embedding, the array length must be 1.
109
+ */
110
+ content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
92
111
  })
93
112
  )
94
113
  );
@@ -128,7 +147,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
128
147
  await (0, import_provider_utils3.resolve)(this.config.headers),
129
148
  headers
130
149
  );
150
+ const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
151
+ if (multimodalContent != null && multimodalContent.length !== values.length) {
152
+ throw new Error(
153
+ `The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
154
+ );
155
+ }
131
156
  if (values.length === 1) {
157
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
158
+ const textPart = values[0] ? [{ text: values[0] }] : [];
159
+ const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
132
160
  const {
133
161
  responseHeaders: responseHeaders2,
134
162
  value: response2,
@@ -139,7 +167,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
139
167
  body: {
140
168
  model: `models/${this.modelId}`,
141
169
  content: {
142
- parts: [{ text: values[0] }]
170
+ parts
143
171
  },
144
172
  outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
145
173
  taskType: googleOptions == null ? void 0 : googleOptions.taskType
@@ -165,12 +193,19 @@ var GoogleGenerativeAIEmbeddingModel = class {
165
193
  url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
166
194
  headers: mergedHeaders,
167
195
  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
- }))
196
+ requests: values.map((value, index) => {
197
+ const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
198
+ const textPart = value ? [{ text: value }] : [];
199
+ return {
200
+ model: `models/${this.modelId}`,
201
+ content: {
202
+ role: "user",
203
+ parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
204
+ },
205
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
206
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
207
+ };
208
+ })
174
209
  },
175
210
  failedResponseHandler: googleFailedResponseHandler,
176
211
  successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(