@ai-sdk/amazon-bedrock 4.0.29 → 4.0.30
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 +6 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +42 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -10
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +7 -0
- package/package.json +3 -3
- package/src/bedrock-embedding-model.ts +48 -11
- package/src/bedrock-embedding-options.ts +14 -0
|
@@ -758,6 +758,13 @@ The following optional provider options are available for Bedrock Titan embeddin
|
|
|
758
758
|
| `cohere.embed-english-v3` | 1024 | <Cross size={18} /> |
|
|
759
759
|
| `cohere.embed-multilingual-v3` | 1024 | <Cross size={18} /> |
|
|
760
760
|
|
|
761
|
+
<Note>
|
|
762
|
+
Cohere embedding models on Bedrock require an <code>input_type</code>. Set it
|
|
763
|
+
via
|
|
764
|
+
<code>providerOptions.bedrock.inputType</code> (defaults to{' '}
|
|
765
|
+
<code>search_query</code>).
|
|
766
|
+
</Note>
|
|
767
|
+
|
|
761
768
|
## Reranking Models
|
|
762
769
|
|
|
763
770
|
You can create models that call the [Bedrock Rerank API](https://docs.aws.amazon.com/bedrock/latest/userguide/rerank-api.html)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.30",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"tsup": "^8.3.0",
|
|
48
48
|
"typescript": "5.8.3",
|
|
49
49
|
"zod": "3.25.76",
|
|
50
|
-
"@ai-
|
|
51
|
-
"@
|
|
50
|
+
"@vercel/ai-tsconfig": "0.0.0",
|
|
51
|
+
"@ai-sdk/test-server": "1.0.3"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"zod": "^3.25.76 || ^4.1.8"
|
|
@@ -67,11 +67,23 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
|
|
|
67
67
|
})) ?? {};
|
|
68
68
|
|
|
69
69
|
// https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
//
|
|
71
|
+
// Note: Different embedding model families expect different request/response
|
|
72
|
+
// payloads (e.g. Titan vs Cohere). We keep the public interface stable and
|
|
73
|
+
// adapt here based on the modelId.
|
|
74
|
+
const args = this.modelId.startsWith('cohere.embed-')
|
|
75
|
+
? {
|
|
76
|
+
// Cohere embedding models on Bedrock require `input_type`.
|
|
77
|
+
// Without it, the service attempts other schema branches and rejects the request.
|
|
78
|
+
input_type: bedrockOptions.inputType ?? 'search_query',
|
|
79
|
+
texts: [values[0]],
|
|
80
|
+
truncate: bedrockOptions.truncate,
|
|
81
|
+
}
|
|
82
|
+
: {
|
|
83
|
+
inputText: values[0],
|
|
84
|
+
dimensions: bedrockOptions.dimensions,
|
|
85
|
+
normalize: bedrockOptions.normalize,
|
|
86
|
+
};
|
|
75
87
|
const url = this.getUrl(this.modelId);
|
|
76
88
|
const { value: response } = await postJsonToApi({
|
|
77
89
|
url,
|
|
@@ -90,15 +102,40 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
|
|
|
90
102
|
abortSignal,
|
|
91
103
|
});
|
|
92
104
|
|
|
105
|
+
const embedding =
|
|
106
|
+
'embedding' in response
|
|
107
|
+
? response.embedding
|
|
108
|
+
: Array.isArray(response.embeddings)
|
|
109
|
+
? response.embeddings[0]
|
|
110
|
+
: response.embeddings.float[0];
|
|
111
|
+
|
|
93
112
|
return {
|
|
94
113
|
warnings: [],
|
|
95
|
-
embeddings: [
|
|
96
|
-
usage: {
|
|
114
|
+
embeddings: [embedding],
|
|
115
|
+
usage: {
|
|
116
|
+
tokens:
|
|
117
|
+
'inputTextTokenCount' in response
|
|
118
|
+
? response.inputTextTokenCount
|
|
119
|
+
: NaN,
|
|
120
|
+
},
|
|
97
121
|
};
|
|
98
122
|
}
|
|
99
123
|
}
|
|
100
124
|
|
|
101
|
-
const BedrockEmbeddingResponseSchema = z.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
125
|
+
const BedrockEmbeddingResponseSchema = z.union([
|
|
126
|
+
// Titan-style response
|
|
127
|
+
z.object({
|
|
128
|
+
embedding: z.array(z.number()),
|
|
129
|
+
inputTextTokenCount: z.number(),
|
|
130
|
+
}),
|
|
131
|
+
// Cohere v3-style response
|
|
132
|
+
z.object({
|
|
133
|
+
embeddings: z.array(z.array(z.number())),
|
|
134
|
+
}),
|
|
135
|
+
// Cohere v4-style response
|
|
136
|
+
z.object({
|
|
137
|
+
embeddings: z.object({
|
|
138
|
+
float: z.array(z.array(z.number())),
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
]);
|
|
@@ -21,4 +21,18 @@ Flag indicating whether or not to normalize the output embeddings. Defaults to t
|
|
|
21
21
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
22
22
|
*/
|
|
23
23
|
normalize: z.boolean().optional(),
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
Input type for Cohere embedding models on Bedrock.
|
|
27
|
+
Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
28
|
+
If not set, the provider defaults to `search_query`.
|
|
29
|
+
*/
|
|
30
|
+
inputType: z
|
|
31
|
+
.enum(['search_document', 'search_query', 'classification', 'clustering'])
|
|
32
|
+
.optional(),
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
Truncation behavior for Cohere embedding models on Bedrock.
|
|
36
|
+
*/
|
|
37
|
+
truncate: z.enum(['NONE', 'START', 'END']).optional(),
|
|
24
38
|
});
|