@ai-sdk/amazon-bedrock 4.0.127 → 4.0.128
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 +19 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -11
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/package.json +4 -4
- package/src/bedrock-embedding-model.ts +24 -14
package/dist/index.mjs
CHANGED
|
@@ -1692,9 +1692,11 @@ var BedrockEmbeddingModel = class {
|
|
|
1692
1692
|
this.config = config;
|
|
1693
1693
|
this.specificationVersion = "v3";
|
|
1694
1694
|
this.provider = "amazon-bedrock";
|
|
1695
|
-
this.maxEmbeddingsPerCall = 1;
|
|
1696
1695
|
this.supportsParallelCalls = true;
|
|
1697
1696
|
}
|
|
1697
|
+
get maxEmbeddingsPerCall() {
|
|
1698
|
+
return isCohereEmbeddingModel(this.modelId) ? 96 : 1;
|
|
1699
|
+
}
|
|
1698
1700
|
getUrl(modelId) {
|
|
1699
1701
|
const encodedModelId = encodeURIComponent(modelId);
|
|
1700
1702
|
return `${this.config.baseUrl()}/model/${encodedModelId}/invoke`;
|
|
@@ -1719,8 +1721,8 @@ var BedrockEmbeddingModel = class {
|
|
|
1719
1721
|
providerOptions,
|
|
1720
1722
|
schema: amazonBedrockEmbeddingModelOptionsSchema
|
|
1721
1723
|
})) != null ? _a : {};
|
|
1722
|
-
const isNovaModel =
|
|
1723
|
-
const isCohereModel = this.modelId
|
|
1724
|
+
const isNovaModel = isNovaEmbeddingModel(this.modelId);
|
|
1725
|
+
const isCohereModel = isCohereEmbeddingModel(this.modelId);
|
|
1724
1726
|
const args = isNovaModel ? {
|
|
1725
1727
|
taskType: "SINGLE_EMBEDDING",
|
|
1726
1728
|
singleEmbeddingParams: {
|
|
@@ -1735,7 +1737,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1735
1737
|
// Cohere embedding models on Bedrock require `input_type`.
|
|
1736
1738
|
// Without it, the service attempts other schema branches and rejects the request.
|
|
1737
1739
|
input_type: (_e = bedrockOptions.inputType) != null ? _e : "search_query",
|
|
1738
|
-
texts:
|
|
1740
|
+
texts: values,
|
|
1739
1741
|
truncate: bedrockOptions.truncate,
|
|
1740
1742
|
output_dimension: bedrockOptions.outputDimension
|
|
1741
1743
|
} : {
|
|
@@ -1760,30 +1762,36 @@ var BedrockEmbeddingModel = class {
|
|
|
1760
1762
|
fetch: this.config.fetch,
|
|
1761
1763
|
abortSignal
|
|
1762
1764
|
});
|
|
1763
|
-
let
|
|
1765
|
+
let embeddings;
|
|
1764
1766
|
if ("embedding" in response) {
|
|
1765
|
-
|
|
1767
|
+
embeddings = [response.embedding];
|
|
1766
1768
|
} else if (Array.isArray(response.embeddings)) {
|
|
1767
1769
|
const firstEmbedding = response.embeddings[0];
|
|
1768
1770
|
if (typeof firstEmbedding === "object" && firstEmbedding !== null && "embeddingType" in firstEmbedding) {
|
|
1769
|
-
|
|
1771
|
+
embeddings = [firstEmbedding.embedding];
|
|
1770
1772
|
} else {
|
|
1771
|
-
|
|
1773
|
+
embeddings = response.embeddings;
|
|
1772
1774
|
}
|
|
1773
1775
|
} else {
|
|
1774
|
-
|
|
1776
|
+
embeddings = response.embeddings.float;
|
|
1775
1777
|
}
|
|
1776
1778
|
const headerTokenCount = Number(
|
|
1777
1779
|
responseHeaders == null ? void 0 : responseHeaders["x-amzn-bedrock-input-token-count"]
|
|
1778
1780
|
);
|
|
1779
1781
|
const tokens = "inputTextTokenCount" in response ? response.inputTextTokenCount : "inputTokenCount" in response ? (_f = response.inputTokenCount) != null ? _f : 0 : headerTokenCount;
|
|
1780
1782
|
return {
|
|
1781
|
-
embeddings
|
|
1783
|
+
embeddings,
|
|
1782
1784
|
usage: { tokens },
|
|
1783
1785
|
warnings: []
|
|
1784
1786
|
};
|
|
1785
1787
|
}
|
|
1786
1788
|
};
|
|
1789
|
+
function isCohereEmbeddingModel(modelId) {
|
|
1790
|
+
return modelId.includes("cohere.embed-");
|
|
1791
|
+
}
|
|
1792
|
+
function isNovaEmbeddingModel(modelId) {
|
|
1793
|
+
return modelId.startsWith("amazon.nova-") && modelId.includes("embed");
|
|
1794
|
+
}
|
|
1787
1795
|
var BedrockEmbeddingResponseSchema = z6.union([
|
|
1788
1796
|
// Titan-style response
|
|
1789
1797
|
z6.object({
|
|
@@ -2036,7 +2044,7 @@ import {
|
|
|
2036
2044
|
import { AwsV4Signer } from "aws4fetch";
|
|
2037
2045
|
|
|
2038
2046
|
// src/version.ts
|
|
2039
|
-
var VERSION = true ? "4.0.
|
|
2047
|
+
var VERSION = true ? "4.0.128" : "0.0.0-test";
|
|
2040
2048
|
|
|
2041
2049
|
// src/bedrock-sigv4-fetch.ts
|
|
2042
2050
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|