@ai-sdk/amazon-bedrock 4.0.29 → 4.0.31
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 +12 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +98 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -11
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +7 -0
- package/package.json +1 -1
- package/src/bedrock-embedding-model.ts +95 -11
- package/src/bedrock-embedding-options.ts +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 4.0.31
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 151c4aa: Add support for Amazon Nova embedding models by sending the required `taskType` and `singleEmbeddingParams` payload and parsing Nova-style responses.
|
|
8
|
+
|
|
9
|
+
## 4.0.30
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 6ece44c: Fix Cohere embedding model request format on Bedrock by sending the required `input_type` and parsing Cohere-style responses.
|
|
14
|
+
|
|
3
15
|
## 4.0.29
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/anthropic/index.js
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 ? "4.0.
|
|
38
|
+
var VERSION = true ? "4.0.31" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
package/dist/anthropic/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { AwsV4Signer } from "aws4fetch";
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = true ? "4.0.
|
|
27
|
+
var VERSION = true ? "4.0.31" : "0.0.0-test";
|
|
28
28
|
|
|
29
29
|
// src/bedrock-sigv4-fetch.ts
|
|
30
30
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
package/dist/index.js
CHANGED
|
@@ -1497,7 +1497,39 @@ var bedrockEmbeddingProviderOptions = import_v44.z.object({
|
|
|
1497
1497
|
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
1498
1498
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
1499
1499
|
*/
|
|
1500
|
-
normalize: import_v44.z.boolean().optional()
|
|
1500
|
+
normalize: import_v44.z.boolean().optional(),
|
|
1501
|
+
/**
|
|
1502
|
+
The number of dimensions for Nova embedding models (defaults to 1024).
|
|
1503
|
+
Supported values: 256, 384, 1024, 3072.
|
|
1504
|
+
Only supported in amazon.nova-* embedding models.
|
|
1505
|
+
*/
|
|
1506
|
+
embeddingDimension: import_v44.z.union([import_v44.z.literal(256), import_v44.z.literal(384), import_v44.z.literal(1024), import_v44.z.literal(3072)]).optional(),
|
|
1507
|
+
/**
|
|
1508
|
+
The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
|
|
1509
|
+
Only supported in amazon.nova-* embedding models.
|
|
1510
|
+
*/
|
|
1511
|
+
embeddingPurpose: import_v44.z.enum([
|
|
1512
|
+
"GENERIC_INDEX",
|
|
1513
|
+
"TEXT_RETRIEVAL",
|
|
1514
|
+
"IMAGE_RETRIEVAL",
|
|
1515
|
+
"VIDEO_RETRIEVAL",
|
|
1516
|
+
"DOCUMENT_RETRIEVAL",
|
|
1517
|
+
"AUDIO_RETRIEVAL",
|
|
1518
|
+
"GENERIC_RETRIEVAL",
|
|
1519
|
+
"CLASSIFICATION",
|
|
1520
|
+
"CLUSTERING"
|
|
1521
|
+
]).optional(),
|
|
1522
|
+
/**
|
|
1523
|
+
Input type for Cohere embedding models on Bedrock.
|
|
1524
|
+
Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
1525
|
+
If not set, the provider defaults to `search_query`.
|
|
1526
|
+
*/
|
|
1527
|
+
inputType: import_v44.z.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
1528
|
+
/**
|
|
1529
|
+
Truncation behavior when input exceeds the model's context length.
|
|
1530
|
+
Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
|
|
1531
|
+
*/
|
|
1532
|
+
truncate: import_v44.z.enum(["NONE", "START", "END"]).optional()
|
|
1501
1533
|
});
|
|
1502
1534
|
|
|
1503
1535
|
// src/bedrock-embedding-model.ts
|
|
@@ -1521,7 +1553,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1521
1553
|
abortSignal,
|
|
1522
1554
|
providerOptions
|
|
1523
1555
|
}) {
|
|
1524
|
-
var _a;
|
|
1556
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1525
1557
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1526
1558
|
throw new import_provider4.TooManyEmbeddingValuesForCallError({
|
|
1527
1559
|
provider: this.provider,
|
|
@@ -1535,7 +1567,25 @@ var BedrockEmbeddingModel = class {
|
|
|
1535
1567
|
providerOptions,
|
|
1536
1568
|
schema: bedrockEmbeddingProviderOptions
|
|
1537
1569
|
})) != null ? _a : {};
|
|
1538
|
-
const
|
|
1570
|
+
const isNovaModel = this.modelId.startsWith("amazon.nova-") && this.modelId.includes("embed");
|
|
1571
|
+
const isCohereModel = this.modelId.startsWith("cohere.embed-");
|
|
1572
|
+
const args = isNovaModel ? {
|
|
1573
|
+
taskType: "SINGLE_EMBEDDING",
|
|
1574
|
+
singleEmbeddingParams: {
|
|
1575
|
+
embeddingPurpose: (_b = bedrockOptions.embeddingPurpose) != null ? _b : "GENERIC_INDEX",
|
|
1576
|
+
embeddingDimension: (_c = bedrockOptions.embeddingDimension) != null ? _c : 1024,
|
|
1577
|
+
text: {
|
|
1578
|
+
truncationMode: (_d = bedrockOptions.truncate) != null ? _d : "END",
|
|
1579
|
+
value: values[0]
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
} : isCohereModel ? {
|
|
1583
|
+
// Cohere embedding models on Bedrock require `input_type`.
|
|
1584
|
+
// Without it, the service attempts other schema branches and rejects the request.
|
|
1585
|
+
input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
|
|
1586
|
+
texts: [values[0]],
|
|
1587
|
+
truncate: bedrockOptions.truncate
|
|
1588
|
+
} : {
|
|
1539
1589
|
inputText: values[0],
|
|
1540
1590
|
dimensions: bedrockOptions.dimensions,
|
|
1541
1591
|
normalize: bedrockOptions.normalize
|
|
@@ -1557,17 +1607,54 @@ var BedrockEmbeddingModel = class {
|
|
|
1557
1607
|
fetch: this.config.fetch,
|
|
1558
1608
|
abortSignal
|
|
1559
1609
|
});
|
|
1610
|
+
let embedding;
|
|
1611
|
+
if ("embedding" in response) {
|
|
1612
|
+
embedding = response.embedding;
|
|
1613
|
+
} else if (Array.isArray(response.embeddings)) {
|
|
1614
|
+
const firstEmbedding = response.embeddings[0];
|
|
1615
|
+
if (typeof firstEmbedding === "object" && firstEmbedding !== null && "embeddingType" in firstEmbedding) {
|
|
1616
|
+
embedding = firstEmbedding.embedding;
|
|
1617
|
+
} else {
|
|
1618
|
+
embedding = firstEmbedding;
|
|
1619
|
+
}
|
|
1620
|
+
} else {
|
|
1621
|
+
embedding = response.embeddings.float[0];
|
|
1622
|
+
}
|
|
1623
|
+
const tokens = "inputTextTokenCount" in response ? response.inputTextTokenCount : "inputTokenCount" in response ? (_f = response.inputTokenCount) != null ? _f : 0 : NaN;
|
|
1560
1624
|
return {
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1625
|
+
embeddings: [embedding],
|
|
1626
|
+
usage: { tokens },
|
|
1627
|
+
warnings: []
|
|
1564
1628
|
};
|
|
1565
1629
|
}
|
|
1566
1630
|
};
|
|
1567
|
-
var BedrockEmbeddingResponseSchema = import_v45.z.
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1631
|
+
var BedrockEmbeddingResponseSchema = import_v45.z.union([
|
|
1632
|
+
// Titan-style response
|
|
1633
|
+
import_v45.z.object({
|
|
1634
|
+
embedding: import_v45.z.array(import_v45.z.number()),
|
|
1635
|
+
inputTextTokenCount: import_v45.z.number()
|
|
1636
|
+
}),
|
|
1637
|
+
// Nova-style response
|
|
1638
|
+
import_v45.z.object({
|
|
1639
|
+
embeddings: import_v45.z.array(
|
|
1640
|
+
import_v45.z.object({
|
|
1641
|
+
embeddingType: import_v45.z.string(),
|
|
1642
|
+
embedding: import_v45.z.array(import_v45.z.number())
|
|
1643
|
+
})
|
|
1644
|
+
),
|
|
1645
|
+
inputTokenCount: import_v45.z.number().optional()
|
|
1646
|
+
}),
|
|
1647
|
+
// Cohere v3-style response
|
|
1648
|
+
import_v45.z.object({
|
|
1649
|
+
embeddings: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
|
|
1650
|
+
}),
|
|
1651
|
+
// Cohere v4-style response
|
|
1652
|
+
import_v45.z.object({
|
|
1653
|
+
embeddings: import_v45.z.object({
|
|
1654
|
+
float: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
|
|
1655
|
+
})
|
|
1656
|
+
})
|
|
1657
|
+
]);
|
|
1571
1658
|
|
|
1572
1659
|
// src/bedrock-image-model.ts
|
|
1573
1660
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
@@ -1781,7 +1868,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
1781
1868
|
var import_aws4fetch = require("aws4fetch");
|
|
1782
1869
|
|
|
1783
1870
|
// src/version.ts
|
|
1784
|
-
var VERSION = true ? "4.0.
|
|
1871
|
+
var VERSION = true ? "4.0.31" : "0.0.0-test";
|
|
1785
1872
|
|
|
1786
1873
|
// src/bedrock-sigv4-fetch.ts
|
|
1787
1874
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|