@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/dist/index.mjs CHANGED
@@ -1502,7 +1502,39 @@ var bedrockEmbeddingProviderOptions = z4.object({
1502
1502
  Flag indicating whether or not to normalize the output embeddings. Defaults to true
1503
1503
  Only supported in amazon.titan-embed-text-v2:0.
1504
1504
  */
1505
- normalize: z4.boolean().optional()
1505
+ normalize: z4.boolean().optional(),
1506
+ /**
1507
+ The number of dimensions for Nova embedding models (defaults to 1024).
1508
+ Supported values: 256, 384, 1024, 3072.
1509
+ Only supported in amazon.nova-* embedding models.
1510
+ */
1511
+ embeddingDimension: z4.union([z4.literal(256), z4.literal(384), z4.literal(1024), z4.literal(3072)]).optional(),
1512
+ /**
1513
+ The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
1514
+ Only supported in amazon.nova-* embedding models.
1515
+ */
1516
+ embeddingPurpose: z4.enum([
1517
+ "GENERIC_INDEX",
1518
+ "TEXT_RETRIEVAL",
1519
+ "IMAGE_RETRIEVAL",
1520
+ "VIDEO_RETRIEVAL",
1521
+ "DOCUMENT_RETRIEVAL",
1522
+ "AUDIO_RETRIEVAL",
1523
+ "GENERIC_RETRIEVAL",
1524
+ "CLASSIFICATION",
1525
+ "CLUSTERING"
1526
+ ]).optional(),
1527
+ /**
1528
+ Input type for Cohere embedding models on Bedrock.
1529
+ Common values: `search_document`, `search_query`, `classification`, `clustering`.
1530
+ If not set, the provider defaults to `search_query`.
1531
+ */
1532
+ inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
1533
+ /**
1534
+ Truncation behavior when input exceeds the model's context length.
1535
+ Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
1536
+ */
1537
+ truncate: z4.enum(["NONE", "START", "END"]).optional()
1506
1538
  });
1507
1539
 
1508
1540
  // src/bedrock-embedding-model.ts
@@ -1526,7 +1558,7 @@ var BedrockEmbeddingModel = class {
1526
1558
  abortSignal,
1527
1559
  providerOptions
1528
1560
  }) {
1529
- var _a;
1561
+ var _a, _b, _c, _d, _e, _f;
1530
1562
  if (values.length > this.maxEmbeddingsPerCall) {
1531
1563
  throw new TooManyEmbeddingValuesForCallError({
1532
1564
  provider: this.provider,
@@ -1540,7 +1572,25 @@ var BedrockEmbeddingModel = class {
1540
1572
  providerOptions,
1541
1573
  schema: bedrockEmbeddingProviderOptions
1542
1574
  })) != null ? _a : {};
1543
- const args = {
1575
+ const isNovaModel = this.modelId.startsWith("amazon.nova-") && this.modelId.includes("embed");
1576
+ const isCohereModel = this.modelId.startsWith("cohere.embed-");
1577
+ const args = isNovaModel ? {
1578
+ taskType: "SINGLE_EMBEDDING",
1579
+ singleEmbeddingParams: {
1580
+ embeddingPurpose: (_b = bedrockOptions.embeddingPurpose) != null ? _b : "GENERIC_INDEX",
1581
+ embeddingDimension: (_c = bedrockOptions.embeddingDimension) != null ? _c : 1024,
1582
+ text: {
1583
+ truncationMode: (_d = bedrockOptions.truncate) != null ? _d : "END",
1584
+ value: values[0]
1585
+ }
1586
+ }
1587
+ } : isCohereModel ? {
1588
+ // Cohere embedding models on Bedrock require `input_type`.
1589
+ // Without it, the service attempts other schema branches and rejects the request.
1590
+ input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
1591
+ texts: [values[0]],
1592
+ truncate: bedrockOptions.truncate
1593
+ } : {
1544
1594
  inputText: values[0],
1545
1595
  dimensions: bedrockOptions.dimensions,
1546
1596
  normalize: bedrockOptions.normalize
@@ -1562,17 +1612,54 @@ var BedrockEmbeddingModel = class {
1562
1612
  fetch: this.config.fetch,
1563
1613
  abortSignal
1564
1614
  });
1615
+ let embedding;
1616
+ if ("embedding" in response) {
1617
+ embedding = response.embedding;
1618
+ } else if (Array.isArray(response.embeddings)) {
1619
+ const firstEmbedding = response.embeddings[0];
1620
+ if (typeof firstEmbedding === "object" && firstEmbedding !== null && "embeddingType" in firstEmbedding) {
1621
+ embedding = firstEmbedding.embedding;
1622
+ } else {
1623
+ embedding = firstEmbedding;
1624
+ }
1625
+ } else {
1626
+ embedding = response.embeddings.float[0];
1627
+ }
1628
+ const tokens = "inputTextTokenCount" in response ? response.inputTextTokenCount : "inputTokenCount" in response ? (_f = response.inputTokenCount) != null ? _f : 0 : NaN;
1565
1629
  return {
1566
- warnings: [],
1567
- embeddings: [response.embedding],
1568
- usage: { tokens: response.inputTextTokenCount }
1630
+ embeddings: [embedding],
1631
+ usage: { tokens },
1632
+ warnings: []
1569
1633
  };
1570
1634
  }
1571
1635
  };
1572
- var BedrockEmbeddingResponseSchema = z5.object({
1573
- embedding: z5.array(z5.number()),
1574
- inputTextTokenCount: z5.number()
1575
- });
1636
+ var BedrockEmbeddingResponseSchema = z5.union([
1637
+ // Titan-style response
1638
+ z5.object({
1639
+ embedding: z5.array(z5.number()),
1640
+ inputTextTokenCount: z5.number()
1641
+ }),
1642
+ // Nova-style response
1643
+ z5.object({
1644
+ embeddings: z5.array(
1645
+ z5.object({
1646
+ embeddingType: z5.string(),
1647
+ embedding: z5.array(z5.number())
1648
+ })
1649
+ ),
1650
+ inputTokenCount: z5.number().optional()
1651
+ }),
1652
+ // Cohere v3-style response
1653
+ z5.object({
1654
+ embeddings: z5.array(z5.array(z5.number()))
1655
+ }),
1656
+ // Cohere v4-style response
1657
+ z5.object({
1658
+ embeddings: z5.object({
1659
+ float: z5.array(z5.array(z5.number()))
1660
+ })
1661
+ })
1662
+ ]);
1576
1663
 
1577
1664
  // src/bedrock-image-model.ts
1578
1665
  import {
@@ -1798,7 +1885,7 @@ import {
1798
1885
  import { AwsV4Signer } from "aws4fetch";
1799
1886
 
1800
1887
  // src/version.ts
1801
- var VERSION = true ? "4.0.29" : "0.0.0-test";
1888
+ var VERSION = true ? "4.0.31" : "0.0.0-test";
1802
1889
 
1803
1890
  // src/bedrock-sigv4-fetch.ts
1804
1891
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {