@abhishek944/pi-embeddings 0.4.0 → 0.6.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/schemas.js CHANGED
@@ -21,12 +21,102 @@ export const EMBEDDING_ROUTE_IDS = [
21
21
  'cloudflare',
22
22
  'gemini',
23
23
  'vertex',
24
+ 'opencode',
25
+ 'opencode-go',
26
+ 'voyage',
27
+ 'cohere',
28
+ 'jina',
29
+ 'dashscope',
30
+ 'hetzner',
24
31
  ];
32
+ /** OpenAI text embeddings documented with 8192 max input tokens, 2048 inputs and 300000 tokens. */
33
+ export const OPENAI_EMBEDDING_MODELS = [
34
+ 'text-embedding-3-small',
35
+ 'text-embedding-3-large',
36
+ ];
37
+ /** Documented default output dimensions for the declared OpenAI text models. */
38
+ export const OPENAI_EMBEDDING_DIMENSIONS = Object.freeze({
39
+ 'text-embedding-3-small': 1536,
40
+ 'text-embedding-3-large': 3072,
41
+ });
25
42
  export const GATEWAY_EMBEDDING_MODELS = [
26
43
  'text-embedding-3-small',
27
44
  'openai/text-embedding-3-small',
28
45
  ];
29
- export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'];
46
+ /**
47
+ * Voyage declares the four general-purpose 4-series models as one shared embedding space. The
48
+ * descriptor still records the model that generated each vector; `voyage-code-4` is not covered by
49
+ * that compatibility statement and is therefore not treated as shared with the 4 series.
50
+ */
51
+ export const VOYAGE_EMBEDDING_MODELS = [
52
+ 'voyage-4-large',
53
+ 'voyage-4',
54
+ 'voyage-4-lite',
55
+ 'voyage-code-4',
56
+ ];
57
+ export const VOYAGE_EMBEDDING_DIMENSIONS = [256, 512, 1024, 2048];
58
+ export const DEFAULT_VOYAGE_DIMENSIONS = 1024;
59
+ export const VOYAGE_INPUT_TYPES = ['document', 'query'];
60
+ /** Cohere Embed 5 documents Pro and Fast as sharing one embedding space. */
61
+ export const COHERE_EMBEDDING_MODELS = ['embed-v5.0-pro', 'embed-v5.0-fast'];
62
+ export const COHERE_EMBEDDING_DIMENSIONS = [256, 512, 768, 1024, 1536, 2048];
63
+ export const DEFAULT_COHERE_DIMENSIONS = 2048;
64
+ export const COHERE_INPUT_TYPES = [
65
+ 'search_document',
66
+ 'search_query',
67
+ 'classification',
68
+ 'clustering',
69
+ ];
70
+ /** Jina v5 text models; the multimodal v5 Omni family is deliberately not declared here. */
71
+ export const JINA_EMBEDDING_MODELS = [
72
+ 'jina-embeddings-v5-text-small',
73
+ 'jina-embeddings-v5-text-nano',
74
+ ];
75
+ /** Documented Matryoshka sizes per model; the 1024 ceiling is the API-wide maximum. */
76
+ export const JINA_EMBEDDING_DIMENSIONS = Object.freeze({
77
+ 'jina-embeddings-v5-text-small': [32, 64, 128, 256, 512, 1024],
78
+ 'jina-embeddings-v5-text-nano': [32, 64, 128, 256, 512, 768],
79
+ });
80
+ export const JINA_EMBEDDING_TASKS = [
81
+ 'retrieval.passage',
82
+ 'retrieval.query',
83
+ 'text-matching',
84
+ 'clustering',
85
+ 'classification',
86
+ ];
87
+ /** Alibaba Model Studio qwen3.7 text embedding through the OpenAI-compatible endpoint. */
88
+ export const DASHSCOPE_EMBEDDING_MODELS = ['qwen3.7-text-embedding'];
89
+ /** The model overview and parameter reference disagree on 1536/2048, so they are not declared. */
90
+ export const DASHSCOPE_EMBEDDING_DIMENSIONS = [64, 128, 256, 512, 768, 1024, 2560];
91
+ export const DEFAULT_DASHSCOPE_DIMENSIONS = 1024;
92
+ /** Hetzner Inference serves one documented embedding model with fixed 1024 dimensions. */
93
+ export const HETZNER_EMBEDDING_MODELS = ['BAAI/bge-m3'];
94
+ export const HETZNER_EMBEDDING_DIMENSIONS = 1024;
95
+ /** Console (pay-as-you-go) embedding model IDs documented by OpenCode. */
96
+ export const OPENCODE_EMBEDDING_MODELS = [
97
+ 'text-embedding-3-small',
98
+ 'text-embedding-3-large',
99
+ 'gemini-embedding-2',
100
+ 'gemini-embedding-001',
101
+ 'codestral-embed',
102
+ 'mistral-embed',
103
+ 'cohere-embed-v5-pro',
104
+ 'cohere-embed-v5-fast',
105
+ 'voyage-4',
106
+ 'voyage-code-4',
107
+ 'qwen3-embedding-8b',
108
+ 'bge-m3',
109
+ ];
110
+ /** Go subscription embedding model IDs documented by OpenCode. */
111
+ export const OPENCODE_GO_EMBEDDING_MODELS = [
112
+ 'text-embedding-3-small',
113
+ 'qwen3-embedding-8b',
114
+ 'gemini-embedding-2',
115
+ ];
116
+ export const OPENROUTER_EMBEDDING_MODELS = [
117
+ 'openai/text-embedding-3-small',
118
+ 'openai/text-embedding-3-large',
119
+ ];
30
120
  export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'];
31
121
  export const GEMINI_EMBEDDING_MODELS = ['gemini-embedding-2'];
32
122
  export const GEMINI_EMBEDDING_MIN_DIMENSIONS = 128;
@@ -58,9 +148,82 @@ const gatewayModelSchema = Type.Union([
58
148
  Type.Literal('text-embedding-3-small'),
59
149
  Type.Literal('openai/text-embedding-3-small'),
60
150
  ]);
61
- const openRouterModelSchema = Type.Literal('openai/text-embedding-3-small');
151
+ const openRouterModelSchema = Type.Union([
152
+ Type.Literal('openai/text-embedding-3-small'),
153
+ Type.Literal('openai/text-embedding-3-large'),
154
+ ]);
155
+ const openAiModelSchema = Type.Union([
156
+ Type.Literal('text-embedding-3-small'),
157
+ Type.Literal('text-embedding-3-large'),
158
+ ]);
159
+ const voyageModelSchema = Type.Union([
160
+ Type.Literal('voyage-4-large'),
161
+ Type.Literal('voyage-4'),
162
+ Type.Literal('voyage-4-lite'),
163
+ Type.Literal('voyage-code-4'),
164
+ ]);
165
+ const voyageDimensionsSchema = Type.Union([
166
+ Type.Literal(256),
167
+ Type.Literal(512),
168
+ Type.Literal(1024),
169
+ Type.Literal(2048),
170
+ ]);
171
+ const cohereModelSchema = Type.Union([
172
+ Type.Literal('embed-v5.0-pro'),
173
+ Type.Literal('embed-v5.0-fast'),
174
+ ]);
175
+ const cohereDimensionsSchema = Type.Union([
176
+ Type.Literal(256),
177
+ Type.Literal(512),
178
+ Type.Literal(768),
179
+ Type.Literal(1024),
180
+ Type.Literal(1536),
181
+ Type.Literal(2048),
182
+ ]);
183
+ const jinaModelSchema = Type.Union([
184
+ Type.Literal('jina-embeddings-v5-text-small'),
185
+ Type.Literal('jina-embeddings-v5-text-nano'),
186
+ ]);
187
+ const jinaTaskSchema = Type.Union([
188
+ Type.Literal('retrieval.passage'),
189
+ Type.Literal('retrieval.query'),
190
+ Type.Literal('text-matching'),
191
+ Type.Literal('clustering'),
192
+ Type.Literal('classification'),
193
+ ]);
194
+ const jinaDimensionsSchema = Type.Integer({ minimum: 32, maximum: 1024 });
195
+ const dashScopeModelSchema = Type.Literal('qwen3.7-text-embedding');
196
+ const dashScopeDimensionsSchema = Type.Union([
197
+ Type.Literal(64),
198
+ Type.Literal(128),
199
+ Type.Literal(256),
200
+ Type.Literal(512),
201
+ Type.Literal(768),
202
+ Type.Literal(1024),
203
+ Type.Literal(2560),
204
+ ]);
205
+ const hetznerModelSchema = Type.Literal('BAAI/bge-m3');
62
206
  const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
63
207
  const geminiModelSchema = Type.Literal(GEMINI_EMBEDDING_MODELS[0]);
208
+ const openCodeModelSchema = Type.Union([
209
+ Type.Literal('text-embedding-3-small'),
210
+ Type.Literal('text-embedding-3-large'),
211
+ Type.Literal('gemini-embedding-2'),
212
+ Type.Literal('gemini-embedding-001'),
213
+ Type.Literal('codestral-embed'),
214
+ Type.Literal('mistral-embed'),
215
+ Type.Literal('cohere-embed-v5-pro'),
216
+ Type.Literal('cohere-embed-v5-fast'),
217
+ Type.Literal('voyage-4'),
218
+ Type.Literal('voyage-code-4'),
219
+ Type.Literal('qwen3-embedding-8b'),
220
+ Type.Literal('bge-m3'),
221
+ ]);
222
+ const openCodeGoModelSchema = Type.Union([
223
+ Type.Literal('text-embedding-3-small'),
224
+ Type.Literal('qwen3-embedding-8b'),
225
+ Type.Literal('gemini-embedding-2'),
226
+ ]);
64
227
  export const VERTEX_EMBEDDING_LOCATIONS = ['us', 'eu', 'global'];
65
228
  const vertexLocationSchema = Type.Union([
66
229
  Type.Literal('us'),
@@ -144,6 +307,13 @@ const embeddingProviderSchema = Type.Union([
144
307
  Type.Literal('cloudflare'),
145
308
  Type.Literal('gemini'),
146
309
  Type.Literal('vertex'),
310
+ Type.Literal('opencode'),
311
+ Type.Literal('opencode-go'),
312
+ Type.Literal('voyage'),
313
+ Type.Literal('cohere'),
314
+ Type.Literal('jina'),
315
+ Type.Literal('dashscope'),
316
+ Type.Literal('hetzner'),
147
317
  ]);
148
318
  export const embeddingRouteSchema = Type.Object({
149
319
  provider: embeddingProviderSchema,
@@ -154,6 +324,13 @@ const spaceCommon = {
154
324
  prefix: Type.Literal(EMBEDDING_DOCUMENT_PREFIX),
155
325
  normalization: Type.Literal(EMBEDDING_NORMALIZATION_VERSION),
156
326
  };
327
+ const openCodeSpaceCommon = {
328
+ ...spaceCommon,
329
+ revision: Type.Null(),
330
+ quantization: Type.Null(),
331
+ // Observed only after a successful response; preflight descriptors never invent a dimension.
332
+ dimensions: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
333
+ };
157
334
  const geminiSpaceCommon = {
158
335
  format: Type.Literal(EMBEDDING_FORMAT_VERSION),
159
336
  prefix: Type.Union([
@@ -196,6 +373,63 @@ export const embeddingSpaceSchema = Type.Union([
196
373
  runtime: Type.Null(),
197
374
  dimensions: Type.Literal(1536),
198
375
  }, { additionalProperties: false }),
376
+ Type.Object({
377
+ ...spaceCommon,
378
+ provider: Type.Literal('openai'),
379
+ model: Type.Literal('text-embedding-3-large'),
380
+ revision: Type.Null(),
381
+ quantization: Type.Null(),
382
+ runtime: Type.Null(),
383
+ dimensions: Type.Literal(3072),
384
+ }, { additionalProperties: false }),
385
+ Type.Object({
386
+ ...spaceCommon,
387
+ provider: Type.Literal('voyage'),
388
+ model: voyageModelSchema,
389
+ revision: Type.Null(),
390
+ quantization: Type.Null(),
391
+ runtime: Type.Literal('voyage-api-v1'),
392
+ dimensions: voyageDimensionsSchema,
393
+ inputType: Type.Literal('document'),
394
+ }, { additionalProperties: false }),
395
+ Type.Object({
396
+ ...spaceCommon,
397
+ provider: Type.Literal('cohere'),
398
+ model: cohereModelSchema,
399
+ revision: Type.Null(),
400
+ quantization: Type.Null(),
401
+ runtime: Type.Literal('cohere-api-v2'),
402
+ dimensions: cohereDimensionsSchema,
403
+ inputType: Type.Literal('search_document'),
404
+ }, { additionalProperties: false }),
405
+ Type.Object({
406
+ ...spaceCommon,
407
+ provider: Type.Literal('jina'),
408
+ model: jinaModelSchema,
409
+ revision: Type.Null(),
410
+ quantization: Type.Null(),
411
+ runtime: Type.Literal('jina-api-v1'),
412
+ dimensions: jinaDimensionsSchema,
413
+ task: Type.Literal('retrieval.passage'),
414
+ }, { additionalProperties: false }),
415
+ Type.Object({
416
+ ...spaceCommon,
417
+ provider: Type.Literal('dashscope'),
418
+ model: dashScopeModelSchema,
419
+ revision: Type.Null(),
420
+ quantization: Type.Null(),
421
+ runtime: Type.Literal('dashscope-compatible-mode-v1'),
422
+ dimensions: dashScopeDimensionsSchema,
423
+ }, { additionalProperties: false }),
424
+ Type.Object({
425
+ ...spaceCommon,
426
+ provider: Type.Literal('hetzner'),
427
+ model: hetznerModelSchema,
428
+ revision: Type.Null(),
429
+ quantization: Type.Null(),
430
+ runtime: Type.Literal('hetzner-inference-v1'),
431
+ dimensions: Type.Literal(1024),
432
+ }, { additionalProperties: false }),
199
433
  Type.Object({
200
434
  ...spaceCommon,
201
435
  provider: Type.Literal('sarvam'),
@@ -225,6 +459,18 @@ export const embeddingSpaceSchema = Type.Union([
225
459
  dimensions: Type.Literal(768),
226
460
  pooling: Type.Union([Type.Literal('mean'), Type.Literal('cls')]),
227
461
  }, { additionalProperties: false }),
462
+ Type.Object({
463
+ ...openCodeSpaceCommon,
464
+ provider: Type.Literal('opencode'),
465
+ model: openCodeModelSchema,
466
+ runtime: Type.Literal('opencode-console-embeddings-v1'),
467
+ }, { additionalProperties: false }),
468
+ Type.Object({
469
+ ...openCodeSpaceCommon,
470
+ provider: Type.Literal('opencode-go'),
471
+ model: openCodeGoModelSchema,
472
+ runtime: Type.Literal('opencode-go-embeddings-v1'),
473
+ }, { additionalProperties: false }),
228
474
  ]);
229
475
  export const embeddingSettingsSchema = Type.Object({
230
476
  version: Type.Optional(Type.Literal(1)),
@@ -264,6 +510,26 @@ export const embeddingSettingsSchema = Type.Object({
264
510
  dimensions: Type.Optional(geminiDimensionsSchema),
265
511
  taskFormat: Type.Optional(geminiTaskFormatSchema),
266
512
  }, { additionalProperties: false })),
513
+ opencode: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
514
+ 'opencode-go': Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
515
+ voyage: Type.Optional(Type.Object({
516
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
517
+ dimensions: Type.Optional(voyageDimensionsSchema),
518
+ }, { additionalProperties: false })),
519
+ cohere: Type.Optional(Type.Object({
520
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
521
+ dimensions: Type.Optional(cohereDimensionsSchema),
522
+ }, { additionalProperties: false })),
523
+ jina: Type.Optional(Type.Object({
524
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
525
+ dimensions: Type.Optional(jinaDimensionsSchema),
526
+ }, { additionalProperties: false })),
527
+ dashscope: Type.Optional(Type.Object({
528
+ baseUrl: Type.String({ minLength: 1 }),
529
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
530
+ dimensions: Type.Optional(dashScopeDimensionsSchema),
531
+ }, { additionalProperties: false })),
532
+ hetzner: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
267
533
  }, { additionalProperties: false })),
268
534
  }, { additionalProperties: false });
269
535
  export const embeddingRequestSchema = Type.Object({
package/dist/settings.js CHANGED
@@ -4,16 +4,23 @@ import { join, resolve } from 'node:path';
4
4
  import { loadPiSettings, resolveConfigDir } from '@amaster.ai/pi-shared/settings';
5
5
  import { Value } from 'typebox/value';
6
6
  import { EmbeddingsError } from './errors.js';
7
- import { CLOUDFLARE_EMBEDDING_MODELS, EMBEDDINGS_SETTINGS_KEY, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, OPENROUTER_EMBEDDING_MODELS, embeddingSettingsSchema, } from './schemas.js';
7
+ import { CLOUDFLARE_EMBEDDING_MODELS, COHERE_EMBEDDING_MODELS, DASHSCOPE_EMBEDDING_MODELS, EMBEDDINGS_SETTINGS_KEY, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, HETZNER_EMBEDDING_MODELS, JINA_EMBEDDING_DIMENSIONS, JINA_EMBEDDING_MODELS, OPENAI_EMBEDDING_MODELS, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_EMBEDDING_MODELS, OPENROUTER_EMBEDDING_MODELS, VOYAGE_EMBEDDING_MODELS, embeddingSettingsSchema, } from './schemas.js';
8
8
  const MODELS_BY_PROVIDER = {
9
9
  local: ['embeddinggemma-2'],
10
- openai: ['text-embedding-3-small'],
10
+ openai: OPENAI_EMBEDDING_MODELS,
11
11
  sarvam: ['embeddinggemma-2'],
12
12
  gateway: GATEWAY_EMBEDDING_MODELS,
13
13
  openrouter: OPENROUTER_EMBEDDING_MODELS,
14
14
  cloudflare: CLOUDFLARE_EMBEDDING_MODELS,
15
15
  gemini: GEMINI_EMBEDDING_MODELS,
16
16
  vertex: GEMINI_EMBEDDING_MODELS,
17
+ opencode: OPENCODE_EMBEDDING_MODELS,
18
+ 'opencode-go': OPENCODE_GO_EMBEDDING_MODELS,
19
+ voyage: VOYAGE_EMBEDDING_MODELS,
20
+ cohere: COHERE_EMBEDDING_MODELS,
21
+ jina: JINA_EMBEDDING_MODELS,
22
+ dashscope: DASHSCOPE_EMBEDDING_MODELS,
23
+ hetzner: HETZNER_EMBEDDING_MODELS,
17
24
  };
18
25
  export const isEmbeddingSettings = (value) => Value.Check(embeddingSettingsSchema, value);
19
26
  function configuration(message) {
@@ -46,6 +53,19 @@ export function validateEmbeddingSettings(value) {
46
53
  const routes = [value.default, ...(value.fallback ?? []), ...(value.compare ?? [])];
47
54
  if (routes.some((route) => route.provider === 'vertex') && value.providers?.vertex === undefined)
48
55
  return configuration('configuration-invalid');
56
+ // Jina documents a per-model Matryoshka set, so an undeclared size fails before any inference.
57
+ const jinaDimensions = value.providers?.jina?.dimensions;
58
+ if (jinaDimensions !== undefined) {
59
+ for (const route of routes) {
60
+ if (route.provider !== 'jina')
61
+ continue;
62
+ if (!MODELS_BY_PROVIDER.jina.includes(route.model))
63
+ return configuration('configuration-invalid');
64
+ const documented = JINA_EMBEDDING_DIMENSIONS[route.model];
65
+ if (documented === undefined || !documented.includes(jinaDimensions))
66
+ return configuration('configuration-invalid');
67
+ }
68
+ }
49
69
  if (value.version !== undefined && value.version !== 1)
50
70
  return configuration('configuration-invalid');
51
71
  return value;