@kb-labs/adapters-voyage-ai 2.96.0
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/README.md +5 -0
- package/dist/embeddings-manifest.d.ts +5 -0
- package/dist/embeddings-manifest.js +44 -0
- package/dist/embeddings-manifest.js.map +1 -0
- package/dist/embeddings.d.ts +41 -0
- package/dist/embeddings.js +117 -0
- package/dist/embeddings.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/embeddings-manifest.ts
|
|
2
|
+
var manifest = {
|
|
3
|
+
manifestVersion: "1.0.0",
|
|
4
|
+
id: "voyage-ai-embeddings",
|
|
5
|
+
name: "Voyage AI Embeddings",
|
|
6
|
+
version: "0.1.0",
|
|
7
|
+
description: "Voyage AI text embeddings adapter (voyage-3, voyage-3.5, voyage-code-3, etc.)",
|
|
8
|
+
author: "KB Labs",
|
|
9
|
+
license: "MIT",
|
|
10
|
+
type: "core",
|
|
11
|
+
implements: "IEmbeddings",
|
|
12
|
+
capabilities: {
|
|
13
|
+
batch: true
|
|
14
|
+
},
|
|
15
|
+
configSchema: {
|
|
16
|
+
apiKey: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Voyage AI API key (defaults to VOYAGE_API_KEY env var)"
|
|
19
|
+
},
|
|
20
|
+
model: {
|
|
21
|
+
type: "string",
|
|
22
|
+
default: "voyage-3",
|
|
23
|
+
description: "Embedding model to use",
|
|
24
|
+
enum: [
|
|
25
|
+
"voyage-3",
|
|
26
|
+
"voyage-3-lite",
|
|
27
|
+
"voyage-3.5",
|
|
28
|
+
"voyage-code-3",
|
|
29
|
+
"voyage-finance-2",
|
|
30
|
+
"voyage-law-2",
|
|
31
|
+
"voyage-multilingual-2"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
inputType: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Input type hint for retrieval tasks",
|
|
37
|
+
enum: ["query", "document"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { manifest };
|
|
43
|
+
//# sourceMappingURL=embeddings-manifest.js.map
|
|
44
|
+
//# sourceMappingURL=embeddings-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/embeddings-manifest.ts"],"names":[],"mappings":";AAEO,IAAM,QAAA,GAA4B;AAAA,EACvC,eAAA,EAAiB,OAAA;AAAA,EACjB,EAAA,EAAI,sBAAA;AAAA,EACJ,IAAA,EAAM,sBAAA;AAAA,EACN,OAAA,EAAS,OAAA;AAAA,EACT,WAAA,EACE,+EAAA;AAAA,EACF,MAAA,EAAQ,SAAA;AAAA,EACR,OAAA,EAAS,KAAA;AAAA,EACT,IAAA,EAAM,MAAA;AAAA,EACN,UAAA,EAAY,aAAA;AAAA,EACZ,YAAA,EAAc;AAAA,IACZ,KAAA,EAAO;AAAA,GACT;AAAA,EACA,YAAA,EAAc;AAAA,IACZ,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EAAa;AAAA,KACf;AAAA,IACA,KAAA,EAAO;AAAA,MACL,IAAA,EAAM,QAAA;AAAA,MACN,OAAA,EAAS,UAAA;AAAA,MACT,WAAA,EAAa,wBAAA;AAAA,MACb,IAAA,EAAM;AAAA,QACJ,UAAA;AAAA,QACA,eAAA;AAAA,QACA,YAAA;AAAA,QACA,eAAA;AAAA,QACA,kBAAA;AAAA,QACA,cAAA;AAAA,QACA;AAAA;AACF,KACF;AAAA,IACA,SAAA,EAAW;AAAA,MACT,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EAAa,qCAAA;AAAA,MACb,IAAA,EAAM,CAAC,OAAA,EAAS,UAAU;AAAA;AAC5B;AAEJ","file":"embeddings-manifest.js","sourcesContent":["import type { AdapterManifest } from \"@kb-labs/sdk/adapters\";\n\nexport const manifest: AdapterManifest = {\n manifestVersion: \"1.0.0\",\n id: \"voyage-ai-embeddings\",\n name: \"Voyage AI Embeddings\",\n version: \"0.1.0\",\n description:\n \"Voyage AI text embeddings adapter (voyage-3, voyage-3.5, voyage-code-3, etc.)\",\n author: \"KB Labs\",\n license: \"MIT\",\n type: \"core\",\n implements: \"IEmbeddings\",\n capabilities: {\n batch: true,\n },\n configSchema: {\n apiKey: {\n type: \"string\",\n description: \"Voyage AI API key (defaults to VOYAGE_API_KEY env var)\",\n },\n model: {\n type: \"string\",\n default: \"voyage-3\",\n description: \"Embedding model to use\",\n enum: [\n \"voyage-3\",\n \"voyage-3-lite\",\n \"voyage-3.5\",\n \"voyage-code-3\",\n \"voyage-finance-2\",\n \"voyage-law-2\",\n \"voyage-multilingual-2\",\n ],\n },\n inputType: {\n type: \"string\",\n description: \"Input type hint for retrieval tasks\",\n enum: [\"query\", \"document\"],\n },\n },\n};\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IEmbeddings } from '@kb-labs/sdk/adapters';
|
|
2
|
+
export { manifest } from './embeddings-manifest.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module @kb-labs/adapters-voyage-ai/embeddings
|
|
6
|
+
* Voyage AI implementation of IEmbeddings interface.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const EMBEDDING_MODELS: {
|
|
10
|
+
readonly "voyage-3": 1024;
|
|
11
|
+
readonly "voyage-3-lite": 512;
|
|
12
|
+
readonly "voyage-3.5": 2048;
|
|
13
|
+
readonly "voyage-code-3": 1024;
|
|
14
|
+
readonly "voyage-finance-2": 1024;
|
|
15
|
+
readonly "voyage-law-2": 1024;
|
|
16
|
+
readonly "voyage-multilingual-2": 1024;
|
|
17
|
+
};
|
|
18
|
+
type EmbeddingModel = keyof typeof EMBEDDING_MODELS;
|
|
19
|
+
type InputType = "query" | "document";
|
|
20
|
+
interface VoyageAIEmbeddingsConfig {
|
|
21
|
+
/** Voyage AI API key (defaults to VOYAGE_API_KEY env var) */
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
/** Embedding model to use */
|
|
24
|
+
model?: EmbeddingModel;
|
|
25
|
+
/** Input type hint for retrieval tasks */
|
|
26
|
+
inputType?: InputType;
|
|
27
|
+
}
|
|
28
|
+
declare class VoyageAIEmbeddings implements IEmbeddings {
|
|
29
|
+
private apiKey;
|
|
30
|
+
private model;
|
|
31
|
+
private inputType;
|
|
32
|
+
readonly dimensions: number;
|
|
33
|
+
constructor(config?: VoyageAIEmbeddingsConfig);
|
|
34
|
+
private request;
|
|
35
|
+
embed(text: string): Promise<number[]>;
|
|
36
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
37
|
+
getDimensions(): Promise<number>;
|
|
38
|
+
}
|
|
39
|
+
declare function createAdapter(config?: VoyageAIEmbeddingsConfig): VoyageAIEmbeddings;
|
|
40
|
+
|
|
41
|
+
export { EMBEDDING_MODELS, type EmbeddingModel, type InputType, VoyageAIEmbeddings, type VoyageAIEmbeddingsConfig, createAdapter, createAdapter as default };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/embeddings-manifest.ts
|
|
2
|
+
var manifest = {
|
|
3
|
+
manifestVersion: "1.0.0",
|
|
4
|
+
id: "voyage-ai-embeddings",
|
|
5
|
+
name: "Voyage AI Embeddings",
|
|
6
|
+
version: "0.1.0",
|
|
7
|
+
description: "Voyage AI text embeddings adapter (voyage-3, voyage-3.5, voyage-code-3, etc.)",
|
|
8
|
+
author: "KB Labs",
|
|
9
|
+
license: "MIT",
|
|
10
|
+
type: "core",
|
|
11
|
+
implements: "IEmbeddings",
|
|
12
|
+
capabilities: {
|
|
13
|
+
batch: true
|
|
14
|
+
},
|
|
15
|
+
configSchema: {
|
|
16
|
+
apiKey: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Voyage AI API key (defaults to VOYAGE_API_KEY env var)"
|
|
19
|
+
},
|
|
20
|
+
model: {
|
|
21
|
+
type: "string",
|
|
22
|
+
default: "voyage-3",
|
|
23
|
+
description: "Embedding model to use",
|
|
24
|
+
enum: [
|
|
25
|
+
"voyage-3",
|
|
26
|
+
"voyage-3-lite",
|
|
27
|
+
"voyage-3.5",
|
|
28
|
+
"voyage-code-3",
|
|
29
|
+
"voyage-finance-2",
|
|
30
|
+
"voyage-law-2",
|
|
31
|
+
"voyage-multilingual-2"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
inputType: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Input type hint for retrieval tasks",
|
|
37
|
+
enum: ["query", "document"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/embeddings.ts
|
|
43
|
+
var EMBEDDING_MODELS = {
|
|
44
|
+
"voyage-3": 1024,
|
|
45
|
+
"voyage-3-lite": 512,
|
|
46
|
+
"voyage-3.5": 2048,
|
|
47
|
+
"voyage-code-3": 1024,
|
|
48
|
+
"voyage-finance-2": 1024,
|
|
49
|
+
"voyage-law-2": 1024,
|
|
50
|
+
"voyage-multilingual-2": 1024
|
|
51
|
+
};
|
|
52
|
+
var API_URL = "https://api.voyageai.com/v1/embeddings";
|
|
53
|
+
var VoyageAIEmbeddings = class {
|
|
54
|
+
apiKey;
|
|
55
|
+
model;
|
|
56
|
+
inputType;
|
|
57
|
+
dimensions;
|
|
58
|
+
constructor(config = {}) {
|
|
59
|
+
const key = config.apiKey ?? process.env["VOYAGE_API_KEY"];
|
|
60
|
+
if (!key) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"Voyage AI API key is required. Set VOYAGE_API_KEY env var or pass apiKey in config."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
this.apiKey = key;
|
|
66
|
+
this.model = config.model ?? "voyage-3";
|
|
67
|
+
this.inputType = config.inputType;
|
|
68
|
+
this.dimensions = EMBEDDING_MODELS[this.model];
|
|
69
|
+
}
|
|
70
|
+
async request(input) {
|
|
71
|
+
const body = {
|
|
72
|
+
model: this.model,
|
|
73
|
+
input
|
|
74
|
+
};
|
|
75
|
+
if (this.inputType) {
|
|
76
|
+
body["input_type"] = this.inputType;
|
|
77
|
+
}
|
|
78
|
+
const res = await fetch(API_URL, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: {
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
83
|
+
},
|
|
84
|
+
body: JSON.stringify(body)
|
|
85
|
+
});
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
const text = await res.text().catch(() => res.statusText);
|
|
88
|
+
throw new Error(`Voyage AI API error ${res.status}: ${text}`);
|
|
89
|
+
}
|
|
90
|
+
const json = await res.json();
|
|
91
|
+
return json.data.sort((a, b) => a.index - b.index).map((d) => d.embedding);
|
|
92
|
+
}
|
|
93
|
+
async embed(text) {
|
|
94
|
+
const [embedding] = await this.request(text);
|
|
95
|
+
if (!embedding) {
|
|
96
|
+
throw new Error("Voyage AI embeddings API returned empty response");
|
|
97
|
+
}
|
|
98
|
+
return embedding;
|
|
99
|
+
}
|
|
100
|
+
async embedBatch(texts) {
|
|
101
|
+
if (texts.length === 0) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
return this.request(texts);
|
|
105
|
+
}
|
|
106
|
+
async getDimensions() {
|
|
107
|
+
return this.dimensions;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
function createAdapter(config) {
|
|
111
|
+
return new VoyageAIEmbeddings(config);
|
|
112
|
+
}
|
|
113
|
+
var embeddings_default = createAdapter;
|
|
114
|
+
|
|
115
|
+
export { EMBEDDING_MODELS, VoyageAIEmbeddings, createAdapter, embeddings_default as default, manifest };
|
|
116
|
+
//# sourceMappingURL=embeddings.js.map
|
|
117
|
+
//# sourceMappingURL=embeddings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/embeddings-manifest.ts","../src/embeddings.ts"],"names":[],"mappings":";AAEO,IAAM,QAAA,GAA4B;AAAA,EACvC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AAA,IAC9D;AAEA,IAAA,MAAM,IAAA,GAAQ,MAAM,GAAA,CAAI,IAAA,EAAK;AAC7B,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAK,CAAC,GAAG,CAAA,KAAM,CAAA,CAAE,KAAA,GAAQ,CAAA,CAAE,KAAK,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,KAAM,EAAE,SAAS,CAAA;AAAA,EAC3E;AAAA,EAEA,MAAM,MAAM,IAAA,EAAiC;AAC3C,IAAA,MAAM,CAAC,SAAS,CAAA,GAAI,MAAM,IAAA,CAAK,QAAQ,IAAI,CAAA;AAC3C,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,MAAM,IAAI,MAAM,kDAAkD,CAAA;AAAA,IACpE;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,KAAA,EAAsC;AACrD,IAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AAAC,MAAA,OAAO,EAAC;AAAA,IAAE;AACnC,IAAA,OAAO,IAAA,CAAK,QAAQ,KAAK,CAAA;AAAA,EAC3B;AAAA,EAEA,MAAM,aAAA,GAAiC;AACrC,IAAA,OAAO,IAAA,CAAK,UAAA;AAAA,EACd;AACF;AAEO,SAAS,cAAc,MAAA,EAAuD;AACnF,EAAA,OAAO,IAAI,mBAAmB,MAAM,CAAA;AACtC;AAIA,IAAO,kBAAA,GAAQ","file":"embeddings.js","sourcesContent":["import type { AdapterManifest } from \"@kb-labs/sdk/adapters\";\n\nexport const manifest: AdapterManifest = {\n manifestVersion: \"1.0.0\",\n id: \"voyage-ai-embeddings\",\n name: \"Voyage AI Embeddings\",\n version: \"0.1.0\",\n description:\n \"Voyage AI text embeddings adapter (voyage-3, voyage-3.5, voyage-code-3, etc.)\",\n author: \"KB Labs\",\n license: \"MIT\",\n type: \"core\",\n implements: \"IEmbeddings\",\n capabilities: {\n batch: true,\n },\n configSchema: {\n apiKey: {\n type: \"string\",\n description: \"Voyage AI API key (defaults to VOYAGE_API_KEY env var)\",\n },\n model: {\n type: \"string\",\n default: \"voyage-3\",\n description: \"Embedding model to use\",\n enum: [\n \"voyage-3\",\n \"voyage-3-lite\",\n \"voyage-3.5\",\n \"voyage-code-3\",\n \"voyage-finance-2\",\n \"voyage-law-2\",\n \"voyage-multilingual-2\",\n ],\n },\n inputType: {\n type: \"string\",\n description: \"Input type hint for retrieval tasks\",\n enum: [\"query\", \"document\"],\n },\n },\n};\n","/**\n * @module @kb-labs/adapters-voyage-ai/embeddings\n * Voyage AI implementation of IEmbeddings interface.\n */\n\nimport type { IEmbeddings } from \"@kb-labs/sdk/adapters\";\n\nexport const EMBEDDING_MODELS = {\n \"voyage-3\": 1024,\n \"voyage-3-lite\": 512,\n \"voyage-3.5\": 2048,\n \"voyage-code-3\": 1024,\n \"voyage-finance-2\": 1024,\n \"voyage-law-2\": 1024,\n \"voyage-multilingual-2\": 1024,\n} as const;\n\nexport type EmbeddingModel = keyof typeof EMBEDDING_MODELS;\n\nexport type InputType = \"query\" | \"document\";\n\nexport interface VoyageAIEmbeddingsConfig {\n /** Voyage AI API key (defaults to VOYAGE_API_KEY env var) */\n apiKey?: string;\n /** Embedding model to use */\n model?: EmbeddingModel;\n /** Input type hint for retrieval tasks */\n inputType?: InputType;\n}\n\nconst API_URL = \"https://api.voyageai.com/v1/embeddings\";\n\ninterface VoyageResponse {\n data: Array<{ embedding: number[]; index: number }>;\n}\n\nexport class VoyageAIEmbeddings implements IEmbeddings {\n private apiKey: string;\n private model: EmbeddingModel;\n private inputType: InputType | undefined;\n readonly dimensions: number;\n\n constructor(config: VoyageAIEmbeddingsConfig = {}) {\n const key = config.apiKey ?? process.env[\"VOYAGE_API_KEY\"];\n if (!key) {\n throw new Error(\n \"Voyage AI API key is required. Set VOYAGE_API_KEY env var or pass apiKey in config.\",\n );\n }\n this.apiKey = key;\n this.model = config.model ?? \"voyage-3\";\n this.inputType = config.inputType;\n this.dimensions = EMBEDDING_MODELS[this.model];\n }\n\n private async request(input: string | string[]): Promise<number[][]> {\n const body: Record<string, unknown> = {\n model: this.model,\n input,\n };\n if (this.inputType) {\n body[\"input_type\"] = this.inputType;\n }\n\n const res = await fetch(API_URL, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(body),\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => res.statusText);\n throw new Error(`Voyage AI API error ${res.status}: ${text}`);\n }\n\n const json = (await res.json()) as VoyageResponse;\n return json.data.sort((a, b) => a.index - b.index).map((d) => d.embedding);\n }\n\n async embed(text: string): Promise<number[]> {\n const [embedding] = await this.request(text);\n if (!embedding) {\n throw new Error(\"Voyage AI embeddings API returned empty response\");\n }\n return embedding;\n }\n\n async embedBatch(texts: string[]): Promise<number[][]> {\n if (texts.length === 0) {return [];}\n return this.request(texts);\n }\n\n async getDimensions(): Promise<number> {\n return this.dimensions;\n }\n}\n\nexport function createAdapter(config?: VoyageAIEmbeddingsConfig): VoyageAIEmbeddings {\n return new VoyageAIEmbeddings(config);\n}\n\nexport { manifest } from \"./embeddings-manifest.js\";\n\nexport default createAdapter;\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kb-labs/adapters-voyage-ai",
|
|
3
|
+
"description": "Voyage AI adapter implementing IEmbeddings interface",
|
|
4
|
+
"version": "2.96.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/embeddings.js",
|
|
7
|
+
"types": "./dist/embeddings.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/embeddings.d.ts",
|
|
11
|
+
"import": "./dist/embeddings.js"
|
|
12
|
+
},
|
|
13
|
+
"./embeddings": {
|
|
14
|
+
"types": "./dist/embeddings.d.ts",
|
|
15
|
+
"import": "./dist/embeddings.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^24.3.3",
|
|
24
|
+
"eslint": "^9",
|
|
25
|
+
"rimraf": "^6.0.1",
|
|
26
|
+
"tsup": "^8.5.0",
|
|
27
|
+
"typescript": "^5.6.3",
|
|
28
|
+
"vitest": "^3.2.6",
|
|
29
|
+
"@kb-labs/devkit": "2.96.0",
|
|
30
|
+
"@kb-labs/sdk": "2.21.2"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.0.0",
|
|
34
|
+
"pnpm": ">=9.0.0"
|
|
35
|
+
},
|
|
36
|
+
"kb": {
|
|
37
|
+
"manifest": "./dist/embeddings-manifest.js"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@kb-labs/sdk": "^2.21.2"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"clean": "rimraf dist",
|
|
46
|
+
"dev": "tsup --watch",
|
|
47
|
+
"lint": "eslint src --ext .ts",
|
|
48
|
+
"lint:fix": "eslint . --fix",
|
|
49
|
+
"test": "vitest run --passWithNoTests",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"type-check": "tsc --noEmit"
|
|
52
|
+
}
|
|
53
|
+
}
|