@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 4.0.30
4
+
5
+ ### Patch Changes
6
+
7
+ - 6ece44c: Fix Cohere embedding model request format on Bedrock by sending the required `input_type` and parsing Cohere-style responses.
8
+
3
9
  ## 4.0.29
4
10
 
5
11
  ### Patch Changes
@@ -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.29" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.30" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -24,7 +24,7 @@ import {
24
24
  import { AwsV4Signer } from "aws4fetch";
25
25
 
26
26
  // src/version.ts
27
- var VERSION = true ? "4.0.29" : "0.0.0-test";
27
+ var VERSION = true ? "4.0.30" : "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,17 @@ 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
+ Input type for Cohere embedding models on Bedrock.
1503
+ Common values: `search_document`, `search_query`, `classification`, `clustering`.
1504
+ If not set, the provider defaults to `search_query`.
1505
+ */
1506
+ inputType: import_v44.z.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
1507
+ /**
1508
+ Truncation behavior for Cohere embedding models on Bedrock.
1509
+ */
1510
+ truncate: import_v44.z.enum(["NONE", "START", "END"]).optional()
1501
1511
  });
1502
1512
 
1503
1513
  // src/bedrock-embedding-model.ts
@@ -1521,7 +1531,7 @@ var BedrockEmbeddingModel = class {
1521
1531
  abortSignal,
1522
1532
  providerOptions
1523
1533
  }) {
1524
- var _a;
1534
+ var _a, _b;
1525
1535
  if (values.length > this.maxEmbeddingsPerCall) {
1526
1536
  throw new import_provider4.TooManyEmbeddingValuesForCallError({
1527
1537
  provider: this.provider,
@@ -1535,7 +1545,13 @@ var BedrockEmbeddingModel = class {
1535
1545
  providerOptions,
1536
1546
  schema: bedrockEmbeddingProviderOptions
1537
1547
  })) != null ? _a : {};
1538
- const args = {
1548
+ const args = this.modelId.startsWith("cohere.embed-") ? {
1549
+ // Cohere embedding models on Bedrock require `input_type`.
1550
+ // Without it, the service attempts other schema branches and rejects the request.
1551
+ input_type: (_b = bedrockOptions.inputType) != null ? _b : "search_query",
1552
+ texts: [values[0]],
1553
+ truncate: bedrockOptions.truncate
1554
+ } : {
1539
1555
  inputText: values[0],
1540
1556
  dimensions: bedrockOptions.dimensions,
1541
1557
  normalize: bedrockOptions.normalize
@@ -1557,17 +1573,33 @@ var BedrockEmbeddingModel = class {
1557
1573
  fetch: this.config.fetch,
1558
1574
  abortSignal
1559
1575
  });
1576
+ const embedding = "embedding" in response ? response.embedding : Array.isArray(response.embeddings) ? response.embeddings[0] : response.embeddings.float[0];
1560
1577
  return {
1561
1578
  warnings: [],
1562
- embeddings: [response.embedding],
1563
- usage: { tokens: response.inputTextTokenCount }
1579
+ embeddings: [embedding],
1580
+ usage: {
1581
+ tokens: "inputTextTokenCount" in response ? response.inputTextTokenCount : NaN
1582
+ }
1564
1583
  };
1565
1584
  }
1566
1585
  };
1567
- var BedrockEmbeddingResponseSchema = import_v45.z.object({
1568
- embedding: import_v45.z.array(import_v45.z.number()),
1569
- inputTextTokenCount: import_v45.z.number()
1570
- });
1586
+ var BedrockEmbeddingResponseSchema = import_v45.z.union([
1587
+ // Titan-style response
1588
+ import_v45.z.object({
1589
+ embedding: import_v45.z.array(import_v45.z.number()),
1590
+ inputTextTokenCount: import_v45.z.number()
1591
+ }),
1592
+ // Cohere v3-style response
1593
+ import_v45.z.object({
1594
+ embeddings: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
1595
+ }),
1596
+ // Cohere v4-style response
1597
+ import_v45.z.object({
1598
+ embeddings: import_v45.z.object({
1599
+ float: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
1600
+ })
1601
+ })
1602
+ ]);
1571
1603
 
1572
1604
  // src/bedrock-image-model.ts
1573
1605
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
@@ -1781,7 +1813,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1781
1813
  var import_aws4fetch = require("aws4fetch");
1782
1814
 
1783
1815
  // src/version.ts
1784
- var VERSION = true ? "4.0.29" : "0.0.0-test";
1816
+ var VERSION = true ? "4.0.30" : "0.0.0-test";
1785
1817
 
1786
1818
  // src/bedrock-sigv4-fetch.ts
1787
1819
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {