@ai-sdk/amazon-bedrock 4.0.30 → 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 +6 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +65 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/bedrock-embedding-model.ts +72 -25
- package/src/bedrock-embedding-options.ts +29 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 4.0.30
|
|
4
10
|
|
|
5
11
|
### 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
|
@@ -1499,13 +1499,35 @@ var bedrockEmbeddingProviderOptions = import_v44.z.object({
|
|
|
1499
1499
|
*/
|
|
1500
1500
|
normalize: import_v44.z.boolean().optional(),
|
|
1501
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
|
+
/**
|
|
1502
1523
|
Input type for Cohere embedding models on Bedrock.
|
|
1503
1524
|
Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
1504
1525
|
If not set, the provider defaults to `search_query`.
|
|
1505
1526
|
*/
|
|
1506
1527
|
inputType: import_v44.z.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
1507
1528
|
/**
|
|
1508
|
-
Truncation behavior
|
|
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.
|
|
1509
1531
|
*/
|
|
1510
1532
|
truncate: import_v44.z.enum(["NONE", "START", "END"]).optional()
|
|
1511
1533
|
});
|
|
@@ -1531,7 +1553,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1531
1553
|
abortSignal,
|
|
1532
1554
|
providerOptions
|
|
1533
1555
|
}) {
|
|
1534
|
-
var _a, _b;
|
|
1556
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1535
1557
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1536
1558
|
throw new import_provider4.TooManyEmbeddingValuesForCallError({
|
|
1537
1559
|
provider: this.provider,
|
|
@@ -1545,10 +1567,22 @@ var BedrockEmbeddingModel = class {
|
|
|
1545
1567
|
providerOptions,
|
|
1546
1568
|
schema: bedrockEmbeddingProviderOptions
|
|
1547
1569
|
})) != null ? _a : {};
|
|
1548
|
-
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 ? {
|
|
1549
1583
|
// Cohere embedding models on Bedrock require `input_type`.
|
|
1550
1584
|
// Without it, the service attempts other schema branches and rejects the request.
|
|
1551
|
-
input_type: (
|
|
1585
|
+
input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
|
|
1552
1586
|
texts: [values[0]],
|
|
1553
1587
|
truncate: bedrockOptions.truncate
|
|
1554
1588
|
} : {
|
|
@@ -1573,13 +1607,24 @@ var BedrockEmbeddingModel = class {
|
|
|
1573
1607
|
fetch: this.config.fetch,
|
|
1574
1608
|
abortSignal
|
|
1575
1609
|
});
|
|
1576
|
-
|
|
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;
|
|
1577
1624
|
return {
|
|
1578
|
-
warnings: [],
|
|
1579
1625
|
embeddings: [embedding],
|
|
1580
|
-
usage: {
|
|
1581
|
-
|
|
1582
|
-
}
|
|
1626
|
+
usage: { tokens },
|
|
1627
|
+
warnings: []
|
|
1583
1628
|
};
|
|
1584
1629
|
}
|
|
1585
1630
|
};
|
|
@@ -1589,6 +1634,16 @@ var BedrockEmbeddingResponseSchema = import_v45.z.union([
|
|
|
1589
1634
|
embedding: import_v45.z.array(import_v45.z.number()),
|
|
1590
1635
|
inputTextTokenCount: import_v45.z.number()
|
|
1591
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
|
+
}),
|
|
1592
1647
|
// Cohere v3-style response
|
|
1593
1648
|
import_v45.z.object({
|
|
1594
1649
|
embeddings: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
|
|
@@ -1813,7 +1868,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
1813
1868
|
var import_aws4fetch = require("aws4fetch");
|
|
1814
1869
|
|
|
1815
1870
|
// src/version.ts
|
|
1816
|
-
var VERSION = true ? "4.0.
|
|
1871
|
+
var VERSION = true ? "4.0.31" : "0.0.0-test";
|
|
1817
1872
|
|
|
1818
1873
|
// src/bedrock-sigv4-fetch.ts
|
|
1819
1874
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|