@ai-sdk/amazon-bedrock 4.0.30 → 4.0.32

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
@@ -1504,13 +1504,35 @@ var bedrockEmbeddingProviderOptions = z4.object({
1504
1504
  */
1505
1505
  normalize: z4.boolean().optional(),
1506
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
+ /**
1507
1528
  Input type for Cohere embedding models on Bedrock.
1508
1529
  Common values: `search_document`, `search_query`, `classification`, `clustering`.
1509
1530
  If not set, the provider defaults to `search_query`.
1510
1531
  */
1511
1532
  inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
1512
1533
  /**
1513
- Truncation behavior for Cohere embedding models on Bedrock.
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.
1514
1536
  */
1515
1537
  truncate: z4.enum(["NONE", "START", "END"]).optional()
1516
1538
  });
@@ -1536,7 +1558,7 @@ var BedrockEmbeddingModel = class {
1536
1558
  abortSignal,
1537
1559
  providerOptions
1538
1560
  }) {
1539
- var _a, _b;
1561
+ var _a, _b, _c, _d, _e, _f;
1540
1562
  if (values.length > this.maxEmbeddingsPerCall) {
1541
1563
  throw new TooManyEmbeddingValuesForCallError({
1542
1564
  provider: this.provider,
@@ -1550,10 +1572,22 @@ var BedrockEmbeddingModel = class {
1550
1572
  providerOptions,
1551
1573
  schema: bedrockEmbeddingProviderOptions
1552
1574
  })) != null ? _a : {};
1553
- const args = this.modelId.startsWith("cohere.embed-") ? {
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 ? {
1554
1588
  // Cohere embedding models on Bedrock require `input_type`.
1555
1589
  // Without it, the service attempts other schema branches and rejects the request.
1556
- input_type: (_b = bedrockOptions.inputType) != null ? _b : "search_query",
1590
+ input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
1557
1591
  texts: [values[0]],
1558
1592
  truncate: bedrockOptions.truncate
1559
1593
  } : {
@@ -1578,13 +1612,24 @@ var BedrockEmbeddingModel = class {
1578
1612
  fetch: this.config.fetch,
1579
1613
  abortSignal
1580
1614
  });
1581
- const embedding = "embedding" in response ? response.embedding : Array.isArray(response.embeddings) ? response.embeddings[0] : response.embeddings.float[0];
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;
1582
1629
  return {
1583
- warnings: [],
1584
1630
  embeddings: [embedding],
1585
- usage: {
1586
- tokens: "inputTextTokenCount" in response ? response.inputTextTokenCount : NaN
1587
- }
1631
+ usage: { tokens },
1632
+ warnings: []
1588
1633
  };
1589
1634
  }
1590
1635
  };
@@ -1594,6 +1639,16 @@ var BedrockEmbeddingResponseSchema = z5.union([
1594
1639
  embedding: z5.array(z5.number()),
1595
1640
  inputTextTokenCount: z5.number()
1596
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
+ }),
1597
1652
  // Cohere v3-style response
1598
1653
  z5.object({
1599
1654
  embeddings: z5.array(z5.array(z5.number()))
@@ -1830,7 +1885,7 @@ import {
1830
1885
  import { AwsV4Signer } from "aws4fetch";
1831
1886
 
1832
1887
  // src/version.ts
1833
- var VERSION = true ? "4.0.30" : "0.0.0-test";
1888
+ var VERSION = true ? "4.0.32" : "0.0.0-test";
1834
1889
 
1835
1890
  // src/bedrock-sigv4-fetch.ts
1836
1891
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {