@ai-sdk/amazon-bedrock 5.0.66 → 5.0.67

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.
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "5.0.66" : "0.0.0-test";
38
+ var VERSION = true ? "5.0.67" : "0.0.0-test";
39
39
 
40
40
  // src/amazon-bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "5.0.66" : "0.0.0-test";
26
+ var VERSION = true ? "5.0.67" : "0.0.0-test";
27
27
 
28
28
  // src/amazon-bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -991,6 +991,30 @@ The following provider options are available for Cohere embedding models:
991
991
 
992
992
  Truncation behavior when input exceeds the model's context length. Accepts: `NONE`, `START`, `END`.
993
993
 
994
+ ### Application Inference Profiles
995
+
996
+ Application inference profile ARNs do not identify their underlying model. Pass
997
+ the model family when creating an embedding model so the provider can select
998
+ the correct request format and batch size:
999
+
1000
+ ```ts
1001
+ import {
1002
+ amazonBedrock,
1003
+ type AmazonBedrockEmbeddingModelSettings,
1004
+ } from '@ai-sdk/amazon-bedrock';
1005
+ import { embedMany } from 'ai';
1006
+
1007
+ const profileArn =
1008
+ 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/qibm5eutlkcy';
1009
+
1010
+ const { embeddings } = await embedMany({
1011
+ model: amazonBedrock.embedding(profileArn, {
1012
+ modelFamily: 'cohere',
1013
+ } satisfies AmazonBedrockEmbeddingModelSettings),
1014
+ values: ['hello', 'world'],
1015
+ });
1016
+ ```
1017
+
994
1018
  ### Model Capabilities
995
1019
 
996
1020
  | Model | Default Dimensions | Custom Dimensions |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "5.0.66",
3
+ "version": "5.0.67",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -41,10 +41,10 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@ai-sdk/anthropic": "4.0.44",
45
- "@ai-sdk/openai": "4.0.50",
44
+ "@ai-sdk/anthropic": "4.0.45",
45
+ "@ai-sdk/openai": "4.0.51",
46
46
  "@ai-sdk/provider": "4.0.8",
47
- "@ai-sdk/provider-utils": "5.0.32",
47
+ "@ai-sdk/provider-utils": "5.0.33",
48
48
  "@smithy/eventstream-codec": "^4.3.3",
49
49
  "@smithy/util-utf8": "^4.3.3",
50
50
  "aws4fetch": "^1.0.20"
@@ -1384,6 +1384,9 @@ const AmazonBedrockStreamSchema = z.object({
1384
1384
  delta: z
1385
1385
  .union([
1386
1386
  z.object({ text: z.string() }),
1387
+ z.object({
1388
+ citation: z.record(z.string(), z.unknown()),
1389
+ }),
1387
1390
  z.object({ toolUse: z.object({ input: z.string() }) }),
1388
1391
  z.object({
1389
1392
  reasoningContent: z.object({ text: z.string() }),
@@ -7,6 +7,16 @@ export type AmazonBedrockEmbeddingModelId =
7
7
  | 'cohere.embed-multilingual-v3'
8
8
  | (string & {});
9
9
 
10
+ export type AmazonBedrockEmbeddingModelSettings = {
11
+ /**
12
+ * The embedding model family.
13
+ *
14
+ * Specify this when the model ID does not identify the underlying model,
15
+ * such as an application inference profile ARN.
16
+ */
17
+ modelFamily?: 'titan' | 'cohere' | 'nova';
18
+ };
19
+
10
20
  export const amazonBedrockEmbeddingModelOptionsSchema = z.object({
11
21
  /**
12
22
  * The number of dimensions the resulting output embeddings should have (defaults to 1024).
@@ -18,6 +18,7 @@ import {
18
18
  import {
19
19
  amazonBedrockEmbeddingModelOptionsSchema,
20
20
  type AmazonBedrockEmbeddingModelId,
21
+ type AmazonBedrockEmbeddingModelSettings,
21
22
  } from './amazon-bedrock-embedding-model-options';
22
23
  import { AmazonBedrockErrorSchema } from './amazon-bedrock-error';
23
24
  import { z } from 'zod/v4';
@@ -26,6 +27,7 @@ type AmazonBedrockEmbeddingConfig = {
26
27
  baseUrl: () => string;
27
28
  headers?: Resolvable<Record<string, string | undefined>>;
28
29
  fetch?: FetchFunction;
30
+ modelFamily?: AmazonBedrockEmbeddingModelSettings['modelFamily'];
29
31
  };
30
32
 
31
33
  type DoEmbedResponse = Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>;
@@ -36,7 +38,11 @@ export class AmazonBedrockEmbeddingModel implements EmbeddingModelV4 {
36
38
  readonly supportsParallelCalls = true;
37
39
 
38
40
  get maxEmbeddingsPerCall() {
39
- return isCohereEmbeddingModel(this.modelId) ? 96 : 1;
41
+ return this.modelFamily === 'cohere' ? 96 : 1;
42
+ }
43
+
44
+ private get modelFamily() {
45
+ return this.config.modelFamily ?? detectEmbeddingModelFamily(this.modelId);
40
46
  }
41
47
 
42
48
  static [WORKFLOW_SERIALIZE](model: AmazonBedrockEmbeddingModel) {
@@ -98,36 +104,37 @@ export class AmazonBedrockEmbeddingModel implements EmbeddingModelV4 {
98
104
  // Note: Different embedding model families expect different request/response
99
105
  // payloads (e.g. Titan vs Cohere vs Nova). We keep the public interface stable and
100
106
  // adapt here based on the modelId.
101
- const isNovaModel = isNovaEmbeddingModel(this.modelId);
102
- const isCohereModel = isCohereEmbeddingModel(this.modelId);
103
-
104
- const args = isNovaModel
105
- ? {
106
- taskType: 'SINGLE_EMBEDDING',
107
- singleEmbeddingParams: {
108
- embeddingPurpose:
109
- amazonBedrockOptions.embeddingPurpose ?? 'GENERIC_INDEX',
110
- embeddingDimension: amazonBedrockOptions.embeddingDimension ?? 1024,
111
- text: {
112
- truncationMode: amazonBedrockOptions.truncate ?? 'END',
113
- value: values[0],
114
- },
115
- },
116
- }
117
- : isCohereModel
107
+ const modelFamily = this.modelFamily;
108
+
109
+ const args =
110
+ modelFamily === 'nova'
118
111
  ? {
119
- // Cohere embedding models on Bedrock require `input_type`.
120
- // Without it, the service attempts other schema branches and rejects the request.
121
- input_type: amazonBedrockOptions.inputType ?? 'search_query',
122
- texts: values,
123
- truncate: amazonBedrockOptions.truncate,
124
- output_dimension: amazonBedrockOptions.outputDimension,
112
+ taskType: 'SINGLE_EMBEDDING',
113
+ singleEmbeddingParams: {
114
+ embeddingPurpose:
115
+ amazonBedrockOptions.embeddingPurpose ?? 'GENERIC_INDEX',
116
+ embeddingDimension:
117
+ amazonBedrockOptions.embeddingDimension ?? 1024,
118
+ text: {
119
+ truncationMode: amazonBedrockOptions.truncate ?? 'END',
120
+ value: values[0],
121
+ },
122
+ },
125
123
  }
126
- : {
127
- inputText: values[0],
128
- dimensions: amazonBedrockOptions.dimensions,
129
- normalize: amazonBedrockOptions.normalize,
130
- };
124
+ : modelFamily === 'cohere'
125
+ ? {
126
+ // Cohere embedding models on Bedrock require `input_type`.
127
+ // Without it, the service attempts other schema branches and rejects the request.
128
+ input_type: amazonBedrockOptions.inputType ?? 'search_query',
129
+ texts: values,
130
+ truncate: amazonBedrockOptions.truncate,
131
+ output_dimension: amazonBedrockOptions.outputDimension,
132
+ }
133
+ : {
134
+ inputText: values[0],
135
+ dimensions: amazonBedrockOptions.dimensions,
136
+ normalize: amazonBedrockOptions.normalize,
137
+ };
131
138
 
132
139
  const url = this.getUrl(this.modelId);
133
140
  const { value: response, responseHeaders } = await postJsonToApi({
@@ -199,7 +206,17 @@ function isCohereEmbeddingModel(modelId: string) {
199
206
  }
200
207
 
201
208
  function isNovaEmbeddingModel(modelId: string) {
202
- return modelId.startsWith('amazon.nova-') && modelId.includes('embed');
209
+ return modelId.includes('amazon.nova-') && modelId.includes('embed');
210
+ }
211
+
212
+ function detectEmbeddingModelFamily(
213
+ modelId: string,
214
+ ): NonNullable<AmazonBedrockEmbeddingModelSettings['modelFamily']> {
215
+ return isNovaEmbeddingModel(modelId)
216
+ ? 'nova'
217
+ : isCohereEmbeddingModel(modelId)
218
+ ? 'cohere'
219
+ : 'titan';
203
220
  }
204
221
 
205
222
  const AmazonBedrockEmbeddingResponseSchema = z.union([
@@ -17,7 +17,10 @@ import {
17
17
  import { AmazonBedrockChatLanguageModel } from './amazon-bedrock-chat-language-model';
18
18
  import type { AmazonBedrockChatModelId } from './amazon-bedrock-chat-language-model-options';
19
19
  import { AmazonBedrockEmbeddingModel } from './amazon-bedrock-embedding-model';
20
- import type { AmazonBedrockEmbeddingModelId } from './amazon-bedrock-embedding-model-options';
20
+ import type {
21
+ AmazonBedrockEmbeddingModelId,
22
+ AmazonBedrockEmbeddingModelSettings,
23
+ } from './amazon-bedrock-embedding-model-options';
21
24
  import { AmazonBedrockImageModel } from './amazon-bedrock-image-model';
22
25
  import type { AmazonBedrockImageModelId } from './amazon-bedrock-image-settings';
23
26
  import {
@@ -119,22 +122,34 @@ export interface AmazonBedrockProvider extends ProviderV4 {
119
122
  /**
120
123
  * Creates a model for text embeddings.
121
124
  */
122
- embedding(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
125
+ embedding(
126
+ modelId: AmazonBedrockEmbeddingModelId,
127
+ settings?: AmazonBedrockEmbeddingModelSettings,
128
+ ): EmbeddingModelV4;
123
129
 
124
130
  /**
125
131
  * Creates a model for text embeddings.
126
132
  */
127
- embeddingModel(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
133
+ embeddingModel(
134
+ modelId: AmazonBedrockEmbeddingModelId,
135
+ settings?: AmazonBedrockEmbeddingModelSettings,
136
+ ): EmbeddingModelV4;
128
137
 
129
138
  /**
130
139
  * @deprecated Use `embedding` instead.
131
140
  */
132
- textEmbedding(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
141
+ textEmbedding(
142
+ modelId: AmazonBedrockEmbeddingModelId,
143
+ settings?: AmazonBedrockEmbeddingModelSettings,
144
+ ): EmbeddingModelV4;
133
145
 
134
146
  /**
135
147
  * @deprecated Use `embeddingModel` instead.
136
148
  */
137
- textEmbeddingModel(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4;
149
+ textEmbeddingModel(
150
+ modelId: AmazonBedrockEmbeddingModelId,
151
+ settings?: AmazonBedrockEmbeddingModelSettings,
152
+ ): EmbeddingModelV4;
138
153
 
139
154
  /**
140
155
  * Creates a model for image generation.
@@ -310,11 +325,15 @@ export function createAmazonBedrock(
310
325
  return createChatModel(modelId);
311
326
  };
312
327
 
313
- const createEmbeddingModel = (modelId: AmazonBedrockEmbeddingModelId) =>
328
+ const createEmbeddingModel = (
329
+ modelId: AmazonBedrockEmbeddingModelId,
330
+ settings: AmazonBedrockEmbeddingModelSettings = {},
331
+ ) =>
314
332
  new AmazonBedrockEmbeddingModel(modelId, {
315
333
  baseUrl: getAmazonBedrockRuntimeBaseUrl,
316
334
  headers: getHeaders,
317
335
  fetch: fetchFunction,
336
+ modelFamily: settings.modelFamily,
318
337
  });
319
338
 
320
339
  const createImageModel = (modelId: AmazonBedrockImageModelId) =>
@@ -624,7 +624,7 @@ export async function convertToAmazonBedrockChatMessages(
624
624
  pushCachePoint(amazonBedrockContent, message.providerOptions);
625
625
  }
626
626
 
627
- if (amazonBedrockContent.length > 0) {
627
+ if (amazonBedrockContent.some(block => !('cachePoint' in block))) {
628
628
  messages.push({ role: 'assistant', content: amazonBedrockContent });
629
629
  }
630
630
 
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export type { AnthropicProviderOptions } from '@ai-sdk/anthropic';
2
2
 
3
- export type { AmazonBedrockEmbeddingModelOptions } from './amazon-bedrock-embedding-model-options';
3
+ export type {
4
+ AmazonBedrockEmbeddingModelOptions,
5
+ AmazonBedrockEmbeddingModelSettings,
6
+ } from './amazon-bedrock-embedding-model-options';
4
7
  export type { AmazonBedrockImageModelOptions } from './amazon-bedrock-image-model-options';
5
8
  export type {
6
9
  AmazonBedrockLanguageModelChatOptions,