@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/dist/index.mjs CHANGED
@@ -1502,7 +1502,17 @@ 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
+ Input type for Cohere embedding models on Bedrock.
1508
+ Common values: `search_document`, `search_query`, `classification`, `clustering`.
1509
+ If not set, the provider defaults to `search_query`.
1510
+ */
1511
+ inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
1512
+ /**
1513
+ Truncation behavior for Cohere embedding models on Bedrock.
1514
+ */
1515
+ truncate: z4.enum(["NONE", "START", "END"]).optional()
1506
1516
  });
1507
1517
 
1508
1518
  // src/bedrock-embedding-model.ts
@@ -1526,7 +1536,7 @@ var BedrockEmbeddingModel = class {
1526
1536
  abortSignal,
1527
1537
  providerOptions
1528
1538
  }) {
1529
- var _a;
1539
+ var _a, _b;
1530
1540
  if (values.length > this.maxEmbeddingsPerCall) {
1531
1541
  throw new TooManyEmbeddingValuesForCallError({
1532
1542
  provider: this.provider,
@@ -1540,7 +1550,13 @@ var BedrockEmbeddingModel = class {
1540
1550
  providerOptions,
1541
1551
  schema: bedrockEmbeddingProviderOptions
1542
1552
  })) != null ? _a : {};
1543
- const args = {
1553
+ const args = this.modelId.startsWith("cohere.embed-") ? {
1554
+ // Cohere embedding models on Bedrock require `input_type`.
1555
+ // Without it, the service attempts other schema branches and rejects the request.
1556
+ input_type: (_b = bedrockOptions.inputType) != null ? _b : "search_query",
1557
+ texts: [values[0]],
1558
+ truncate: bedrockOptions.truncate
1559
+ } : {
1544
1560
  inputText: values[0],
1545
1561
  dimensions: bedrockOptions.dimensions,
1546
1562
  normalize: bedrockOptions.normalize
@@ -1562,17 +1578,33 @@ var BedrockEmbeddingModel = class {
1562
1578
  fetch: this.config.fetch,
1563
1579
  abortSignal
1564
1580
  });
1581
+ const embedding = "embedding" in response ? response.embedding : Array.isArray(response.embeddings) ? response.embeddings[0] : response.embeddings.float[0];
1565
1582
  return {
1566
1583
  warnings: [],
1567
- embeddings: [response.embedding],
1568
- usage: { tokens: response.inputTextTokenCount }
1584
+ embeddings: [embedding],
1585
+ usage: {
1586
+ tokens: "inputTextTokenCount" in response ? response.inputTextTokenCount : NaN
1587
+ }
1569
1588
  };
1570
1589
  }
1571
1590
  };
1572
- var BedrockEmbeddingResponseSchema = z5.object({
1573
- embedding: z5.array(z5.number()),
1574
- inputTextTokenCount: z5.number()
1575
- });
1591
+ var BedrockEmbeddingResponseSchema = z5.union([
1592
+ // Titan-style response
1593
+ z5.object({
1594
+ embedding: z5.array(z5.number()),
1595
+ inputTextTokenCount: z5.number()
1596
+ }),
1597
+ // Cohere v3-style response
1598
+ z5.object({
1599
+ embeddings: z5.array(z5.array(z5.number()))
1600
+ }),
1601
+ // Cohere v4-style response
1602
+ z5.object({
1603
+ embeddings: z5.object({
1604
+ float: z5.array(z5.array(z5.number()))
1605
+ })
1606
+ })
1607
+ ]);
1576
1608
 
1577
1609
  // src/bedrock-image-model.ts
1578
1610
  import {
@@ -1798,7 +1830,7 @@ import {
1798
1830
  import { AwsV4Signer } from "aws4fetch";
1799
1831
 
1800
1832
  // src/version.ts
1801
- var VERSION = true ? "4.0.29" : "0.0.0-test";
1833
+ var VERSION = true ? "4.0.30" : "0.0.0-test";
1802
1834
 
1803
1835
  // src/bedrock-sigv4-fetch.ts
1804
1836
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {