@abhishek944/pi-embeddings 0.5.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
@@ -23,11 +23,75 @@ export const EMBEDDING_ROUTE_IDS = [
23
23
  'vertex',
24
24
  'opencode',
25
25
  'opencode-go',
26
+ 'voyage',
27
+ 'cohere',
28
+ 'jina',
29
+ 'dashscope',
30
+ 'hetzner',
26
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
+ });
27
42
  export const GATEWAY_EMBEDDING_MODELS = [
28
43
  'text-embedding-3-small',
29
44
  'openai/text-embedding-3-small',
30
45
  ];
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;
31
95
  /** Console (pay-as-you-go) embedding model IDs documented by OpenCode. */
32
96
  export const OPENCODE_EMBEDDING_MODELS = [
33
97
  'text-embedding-3-small',
@@ -49,7 +113,10 @@ export const OPENCODE_GO_EMBEDDING_MODELS = [
49
113
  'qwen3-embedding-8b',
50
114
  'gemini-embedding-2',
51
115
  ];
52
- export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'];
116
+ export const OPENROUTER_EMBEDDING_MODELS = [
117
+ 'openai/text-embedding-3-small',
118
+ 'openai/text-embedding-3-large',
119
+ ];
53
120
  export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'];
54
121
  export const GEMINI_EMBEDDING_MODELS = ['gemini-embedding-2'];
55
122
  export const GEMINI_EMBEDDING_MIN_DIMENSIONS = 128;
@@ -81,7 +148,61 @@ const gatewayModelSchema = Type.Union([
81
148
  Type.Literal('text-embedding-3-small'),
82
149
  Type.Literal('openai/text-embedding-3-small'),
83
150
  ]);
84
- 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');
85
206
  const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
86
207
  const geminiModelSchema = Type.Literal(GEMINI_EMBEDDING_MODELS[0]);
87
208
  const openCodeModelSchema = Type.Union([
@@ -188,6 +309,11 @@ const embeddingProviderSchema = Type.Union([
188
309
  Type.Literal('vertex'),
189
310
  Type.Literal('opencode'),
190
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'),
191
317
  ]);
192
318
  export const embeddingRouteSchema = Type.Object({
193
319
  provider: embeddingProviderSchema,
@@ -247,6 +373,63 @@ export const embeddingSpaceSchema = Type.Union([
247
373
  runtime: Type.Null(),
248
374
  dimensions: Type.Literal(1536),
249
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 }),
250
433
  Type.Object({
251
434
  ...spaceCommon,
252
435
  provider: Type.Literal('sarvam'),
@@ -329,6 +512,24 @@ export const embeddingSettingsSchema = Type.Object({
329
512
  }, { additionalProperties: false })),
330
513
  opencode: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
331
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 })),
332
533
  }, { additionalProperties: false })),
333
534
  }, { additionalProperties: false });
334
535
  export const embeddingRequestSchema = Type.Object({
package/dist/settings.js CHANGED
@@ -4,10 +4,10 @@ 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, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_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,
@@ -16,6 +16,11 @@ const MODELS_BY_PROVIDER = {
16
16
  vertex: GEMINI_EMBEDDING_MODELS,
17
17
  opencode: OPENCODE_EMBEDDING_MODELS,
18
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,
19
24
  };
20
25
  export const isEmbeddingSettings = (value) => Value.Check(embeddingSettingsSchema, value);
21
26
  function configuration(message) {
@@ -48,6 +53,19 @@ export function validateEmbeddingSettings(value) {
48
53
  const routes = [value.default, ...(value.fallback ?? []), ...(value.compare ?? [])];
49
54
  if (routes.some((route) => route.provider === 'vertex') && value.providers?.vertex === undefined)
50
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
+ }
51
69
  if (value.version !== undefined && value.version !== 1)
52
70
  return configuration('configuration-invalid');
53
71
  return value;