@eidentic/model 0.1.1 → 0.2.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/dist/index.cjs +9 -6
- package/dist/index.d.cts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +9 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -241,19 +241,22 @@ var AIModel = class {
|
|
|
241
241
|
// src/embedder.ts
|
|
242
242
|
var import_ai3 = require("ai");
|
|
243
243
|
var AIEmbedder = class _AIEmbedder {
|
|
244
|
-
constructor(model, dim) {
|
|
244
|
+
constructor(model, dim, maxRetries) {
|
|
245
245
|
this.model = model;
|
|
246
|
+
this.maxRetries = maxRetries;
|
|
246
247
|
this.dim = dim;
|
|
247
248
|
}
|
|
248
249
|
model;
|
|
250
|
+
maxRetries;
|
|
249
251
|
dim;
|
|
250
252
|
/** Construct an embedder, probing the model once to discover its output dimension. */
|
|
251
|
-
static async create(model) {
|
|
252
|
-
const
|
|
253
|
-
|
|
253
|
+
static async create(model, opts) {
|
|
254
|
+
const maxRetries = opts?.maxRetries ?? 2;
|
|
255
|
+
const { embedding } = await (0, import_ai3.embed)({ model, value: "x", maxRetries });
|
|
256
|
+
return new _AIEmbedder(model, embedding.length, maxRetries);
|
|
254
257
|
}
|
|
255
258
|
async embed(text) {
|
|
256
|
-
const { embedding } = await (0, import_ai3.embed)({ model: this.model, value: text });
|
|
259
|
+
const { embedding } = await (0, import_ai3.embed)({ model: this.model, value: text, maxRetries: this.maxRetries });
|
|
257
260
|
return embedding;
|
|
258
261
|
}
|
|
259
262
|
/**
|
|
@@ -263,7 +266,7 @@ var AIEmbedder = class _AIEmbedder {
|
|
|
263
266
|
*/
|
|
264
267
|
async embedBatch(texts) {
|
|
265
268
|
if (texts.length === 0) return [];
|
|
266
|
-
const { embeddings } = await (0, import_ai3.embedMany)({ model: this.model, values: texts });
|
|
269
|
+
const { embeddings } = await (0, import_ai3.embedMany)({ model: this.model, values: texts, maxRetries: this.maxRetries });
|
|
267
270
|
for (let i = 0; i < embeddings.length; i++) {
|
|
268
271
|
if (embeddings[i].length !== this.dim) {
|
|
269
272
|
throw new Error(`embedBatch: embedding[${i}] has length ${embeddings[i].length}, expected ${this.dim}`);
|
package/dist/index.d.cts
CHANGED
|
@@ -37,6 +37,22 @@ declare class AIModel implements ModelPort {
|
|
|
37
37
|
|
|
38
38
|
/** The embedding-model type accepted by AI SDK v6 `embed`, minus the bare-string branch. */
|
|
39
39
|
type AIEmbeddingModel = Exclude<Parameters<typeof embed>[0]["model"], string>;
|
|
40
|
+
/**
|
|
41
|
+
* Provider-agnostic hosted embedder over AI SDK v6. Bring your own provider + key + model:
|
|
42
|
+
* const embedder = await AIEmbedder.create(openai.embedding("text-embedding-3-small"));
|
|
43
|
+
* Works with any `@ai-sdk/*` embedding model (OpenAI, Cohere, Google, Mistral, ...).
|
|
44
|
+
* A first-class peer to the local `@eidentic/transformers` embedder; pick whichever fits.
|
|
45
|
+
*/
|
|
46
|
+
/** Options for {@link AIEmbedder.create}. */
|
|
47
|
+
interface AIEmbedderOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Max retry attempts per embedding call. The AI SDK retries transient
|
|
50
|
+
* failures (including provider rate limits / 429s) with exponential backoff
|
|
51
|
+
* and honours `retry-after`. Raise this for high-volume ingest against a
|
|
52
|
+
* rate-limited provider. Default: 2 (the AI SDK default).
|
|
53
|
+
*/
|
|
54
|
+
maxRetries?: number;
|
|
55
|
+
}
|
|
40
56
|
/**
|
|
41
57
|
* Provider-agnostic hosted embedder over AI SDK v6. Bring your own provider + key + model:
|
|
42
58
|
* const embedder = await AIEmbedder.create(openai.embedding("text-embedding-3-small"));
|
|
@@ -45,10 +61,11 @@ type AIEmbeddingModel = Exclude<Parameters<typeof embed>[0]["model"], string>;
|
|
|
45
61
|
*/
|
|
46
62
|
declare class AIEmbedder implements EmbeddingPort {
|
|
47
63
|
private readonly model;
|
|
64
|
+
private readonly maxRetries;
|
|
48
65
|
readonly dim: number;
|
|
49
66
|
private constructor();
|
|
50
67
|
/** Construct an embedder, probing the model once to discover its output dimension. */
|
|
51
|
-
static create(model: AIEmbeddingModel): Promise<AIEmbedder>;
|
|
68
|
+
static create(model: AIEmbeddingModel, opts?: AIEmbedderOptions): Promise<AIEmbedder>;
|
|
52
69
|
embed(text: string): Promise<number[]>;
|
|
53
70
|
/**
|
|
54
71
|
* Batch embedding via AI SDK v6 `embedMany({ model, values })` → `{ embeddings: number[][] }`.
|
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,22 @@ declare class AIModel implements ModelPort {
|
|
|
37
37
|
|
|
38
38
|
/** The embedding-model type accepted by AI SDK v6 `embed`, minus the bare-string branch. */
|
|
39
39
|
type AIEmbeddingModel = Exclude<Parameters<typeof embed>[0]["model"], string>;
|
|
40
|
+
/**
|
|
41
|
+
* Provider-agnostic hosted embedder over AI SDK v6. Bring your own provider + key + model:
|
|
42
|
+
* const embedder = await AIEmbedder.create(openai.embedding("text-embedding-3-small"));
|
|
43
|
+
* Works with any `@ai-sdk/*` embedding model (OpenAI, Cohere, Google, Mistral, ...).
|
|
44
|
+
* A first-class peer to the local `@eidentic/transformers` embedder; pick whichever fits.
|
|
45
|
+
*/
|
|
46
|
+
/** Options for {@link AIEmbedder.create}. */
|
|
47
|
+
interface AIEmbedderOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Max retry attempts per embedding call. The AI SDK retries transient
|
|
50
|
+
* failures (including provider rate limits / 429s) with exponential backoff
|
|
51
|
+
* and honours `retry-after`. Raise this for high-volume ingest against a
|
|
52
|
+
* rate-limited provider. Default: 2 (the AI SDK default).
|
|
53
|
+
*/
|
|
54
|
+
maxRetries?: number;
|
|
55
|
+
}
|
|
40
56
|
/**
|
|
41
57
|
* Provider-agnostic hosted embedder over AI SDK v6. Bring your own provider + key + model:
|
|
42
58
|
* const embedder = await AIEmbedder.create(openai.embedding("text-embedding-3-small"));
|
|
@@ -45,10 +61,11 @@ type AIEmbeddingModel = Exclude<Parameters<typeof embed>[0]["model"], string>;
|
|
|
45
61
|
*/
|
|
46
62
|
declare class AIEmbedder implements EmbeddingPort {
|
|
47
63
|
private readonly model;
|
|
64
|
+
private readonly maxRetries;
|
|
48
65
|
readonly dim: number;
|
|
49
66
|
private constructor();
|
|
50
67
|
/** Construct an embedder, probing the model once to discover its output dimension. */
|
|
51
|
-
static create(model: AIEmbeddingModel): Promise<AIEmbedder>;
|
|
68
|
+
static create(model: AIEmbeddingModel, opts?: AIEmbedderOptions): Promise<AIEmbedder>;
|
|
52
69
|
embed(text: string): Promise<number[]>;
|
|
53
70
|
/**
|
|
54
71
|
* Batch embedding via AI SDK v6 `embedMany({ model, values })` → `{ embeddings: number[][] }`.
|
package/dist/index.js
CHANGED
|
@@ -211,19 +211,22 @@ var AIModel = class {
|
|
|
211
211
|
// src/embedder.ts
|
|
212
212
|
import { embed, embedMany } from "ai";
|
|
213
213
|
var AIEmbedder = class _AIEmbedder {
|
|
214
|
-
constructor(model, dim) {
|
|
214
|
+
constructor(model, dim, maxRetries) {
|
|
215
215
|
this.model = model;
|
|
216
|
+
this.maxRetries = maxRetries;
|
|
216
217
|
this.dim = dim;
|
|
217
218
|
}
|
|
218
219
|
model;
|
|
220
|
+
maxRetries;
|
|
219
221
|
dim;
|
|
220
222
|
/** Construct an embedder, probing the model once to discover its output dimension. */
|
|
221
|
-
static async create(model) {
|
|
222
|
-
const
|
|
223
|
-
|
|
223
|
+
static async create(model, opts) {
|
|
224
|
+
const maxRetries = opts?.maxRetries ?? 2;
|
|
225
|
+
const { embedding } = await embed({ model, value: "x", maxRetries });
|
|
226
|
+
return new _AIEmbedder(model, embedding.length, maxRetries);
|
|
224
227
|
}
|
|
225
228
|
async embed(text) {
|
|
226
|
-
const { embedding } = await embed({ model: this.model, value: text });
|
|
229
|
+
const { embedding } = await embed({ model: this.model, value: text, maxRetries: this.maxRetries });
|
|
227
230
|
return embedding;
|
|
228
231
|
}
|
|
229
232
|
/**
|
|
@@ -233,7 +236,7 @@ var AIEmbedder = class _AIEmbedder {
|
|
|
233
236
|
*/
|
|
234
237
|
async embedBatch(texts) {
|
|
235
238
|
if (texts.length === 0) return [];
|
|
236
|
-
const { embeddings } = await embedMany({ model: this.model, values: texts });
|
|
239
|
+
const { embeddings } = await embedMany({ model: this.model, values: texts, maxRetries: this.maxRetries });
|
|
237
240
|
for (let i = 0; i < embeddings.length; i++) {
|
|
238
241
|
if (embeddings[i].length !== this.dim) {
|
|
239
242
|
throw new Error(`embedBatch: embedding[${i}] has length ${embeddings[i].length}, expected ${this.dim}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eidentic/model",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"ai": "^6.0.0",
|
|
32
|
-
"@eidentic/types": "0.
|
|
32
|
+
"@eidentic/types": "0.2.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"ollama-ai-provider": ">=1.0.0"
|