@ai-sdk/amazon-bedrock 5.0.66 → 5.0.68
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 +24 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/index.d.ts +14 -5
- package/dist/index.js +36 -26
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/docs/08-amazon-bedrock.mdx +24 -0
- package/package.json +5 -5
- package/src/amazon-bedrock-chat-language-model.ts +9 -1
- package/src/amazon-bedrock-embedding-model-options.ts +10 -0
- package/src/amazon-bedrock-embedding-model.ts +47 -30
- package/src/amazon-bedrock-provider.ts +25 -6
- package/src/convert-to-amazon-bedrock-chat-messages.ts +1 -1
- package/src/index.ts +4 -1
package/dist/mantle/index.cjs
CHANGED
|
@@ -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.
|
|
38
|
+
var VERSION = true ? "5.0.68" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "5.0.
|
|
26
|
+
var VERSION = true ? "5.0.68" : "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.
|
|
3
|
+
"version": "5.0.68",
|
|
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.
|
|
45
|
-
"@ai-sdk/openai": "4.0.
|
|
46
|
-
"@ai-sdk/provider": "4.0.
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
44
|
+
"@ai-sdk/anthropic": "4.0.46",
|
|
45
|
+
"@ai-sdk/openai": "4.0.52",
|
|
46
|
+
"@ai-sdk/provider": "4.0.9",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.34",
|
|
48
48
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
49
49
|
"@smithy/util-utf8": "^4.3.3",
|
|
50
50
|
"aws4fetch": "^1.0.20"
|
|
@@ -216,7 +216,12 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
// Application inference profile ARNs do not expose their underlying model.
|
|
220
|
+
// The Anthropic-only reasoning budget provides the model-family signal.
|
|
221
|
+
const isAnthropicModel =
|
|
222
|
+
this.modelId.includes('anthropic') ||
|
|
223
|
+
(this.modelId.includes(':application-inference-profile/') &&
|
|
224
|
+
amazonBedrockOptions.reasoningConfig?.budgetTokens != null);
|
|
220
225
|
const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
|
|
221
226
|
const isOpenAIModel = openAIModelId != null;
|
|
222
227
|
const isOpenAIGptOssModel =
|
|
@@ -1384,6 +1389,9 @@ const AmazonBedrockStreamSchema = z.object({
|
|
|
1384
1389
|
delta: z
|
|
1385
1390
|
.union([
|
|
1386
1391
|
z.object({ text: z.string() }),
|
|
1392
|
+
z.object({
|
|
1393
|
+
citation: z.record(z.string(), z.unknown()),
|
|
1394
|
+
}),
|
|
1387
1395
|
z.object({ toolUse: z.object({ input: z.string() }) }),
|
|
1388
1396
|
z.object({
|
|
1389
1397
|
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
|
|
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
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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.
|
|
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 {
|
|
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(
|
|
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(
|
|
133
|
+
embeddingModel(
|
|
134
|
+
modelId: AmazonBedrockEmbeddingModelId,
|
|
135
|
+
settings?: AmazonBedrockEmbeddingModelSettings,
|
|
136
|
+
): EmbeddingModelV4;
|
|
128
137
|
|
|
129
138
|
/**
|
|
130
139
|
* @deprecated Use `embedding` instead.
|
|
131
140
|
*/
|
|
132
|
-
textEmbedding(
|
|
141
|
+
textEmbedding(
|
|
142
|
+
modelId: AmazonBedrockEmbeddingModelId,
|
|
143
|
+
settings?: AmazonBedrockEmbeddingModelSettings,
|
|
144
|
+
): EmbeddingModelV4;
|
|
133
145
|
|
|
134
146
|
/**
|
|
135
147
|
* @deprecated Use `embeddingModel` instead.
|
|
136
148
|
*/
|
|
137
|
-
textEmbeddingModel(
|
|
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 = (
|
|
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.
|
|
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 {
|
|
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,
|