@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/src/schemas.ts CHANGED
@@ -23,15 +23,129 @@ export const EMBEDDING_ROUTE_IDS = [
23
23
  'cloudflare',
24
24
  'gemini',
25
25
  'vertex',
26
+ 'opencode',
27
+ 'opencode-go',
28
+ 'voyage',
29
+ 'cohere',
30
+ 'jina',
31
+ 'dashscope',
32
+ 'hetzner',
26
33
  ] as const;
27
34
  export type EmbeddingRouteId = (typeof EMBEDDING_ROUTE_IDS)[number];
35
+ export type OpenCodeRouteId = Extract<EmbeddingRouteId, 'opencode' | 'opencode-go'>;
36
+
37
+ /** OpenAI text embeddings documented with 8192 max input tokens, 2048 inputs and 300000 tokens. */
38
+ export const OPENAI_EMBEDDING_MODELS = [
39
+ 'text-embedding-3-small',
40
+ 'text-embedding-3-large',
41
+ ] as const;
42
+ export type OpenAiEmbeddingModel = (typeof OPENAI_EMBEDDING_MODELS)[number];
43
+ /** Documented default output dimensions for the declared OpenAI text models. */
44
+ export const OPENAI_EMBEDDING_DIMENSIONS = Object.freeze({
45
+ 'text-embedding-3-small': 1536,
46
+ 'text-embedding-3-large': 3072,
47
+ } as const satisfies Record<OpenAiEmbeddingModel, number>);
28
48
 
29
49
  export const GATEWAY_EMBEDDING_MODELS = [
30
50
  'text-embedding-3-small',
31
51
  'openai/text-embedding-3-small',
32
52
  ] as const;
33
53
 
34
- export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'] as const;
54
+ /**
55
+ * Voyage declares the four general-purpose 4-series models as one shared embedding space. The
56
+ * descriptor still records the model that generated each vector; `voyage-code-4` is not covered by
57
+ * that compatibility statement and is therefore not treated as shared with the 4 series.
58
+ */
59
+ export const VOYAGE_EMBEDDING_MODELS = [
60
+ 'voyage-4-large',
61
+ 'voyage-4',
62
+ 'voyage-4-lite',
63
+ 'voyage-code-4',
64
+ ] as const;
65
+ export type VoyageEmbeddingModel = (typeof VOYAGE_EMBEDDING_MODELS)[number];
66
+ export const VOYAGE_EMBEDDING_DIMENSIONS = [256, 512, 1024, 2048] as const;
67
+ export type VoyageEmbeddingDimension = (typeof VOYAGE_EMBEDDING_DIMENSIONS)[number];
68
+ export const DEFAULT_VOYAGE_DIMENSIONS: VoyageEmbeddingDimension = 1024;
69
+ export const VOYAGE_INPUT_TYPES = ['document', 'query'] as const;
70
+ export type VoyageInputType = (typeof VOYAGE_INPUT_TYPES)[number];
71
+
72
+ /** Cohere Embed 5 documents Pro and Fast as sharing one embedding space. */
73
+ export const COHERE_EMBEDDING_MODELS = ['embed-v5.0-pro', 'embed-v5.0-fast'] as const;
74
+ export type CohereEmbeddingModel = (typeof COHERE_EMBEDDING_MODELS)[number];
75
+ export const COHERE_EMBEDDING_DIMENSIONS = [256, 512, 768, 1024, 1536, 2048] as const;
76
+ export type CohereEmbeddingDimension = (typeof COHERE_EMBEDDING_DIMENSIONS)[number];
77
+ export const DEFAULT_COHERE_DIMENSIONS: CohereEmbeddingDimension = 2048;
78
+ export const COHERE_INPUT_TYPES = [
79
+ 'search_document',
80
+ 'search_query',
81
+ 'classification',
82
+ 'clustering',
83
+ ] as const;
84
+ export type CohereInputType = (typeof COHERE_INPUT_TYPES)[number];
85
+
86
+ /** Jina v5 text models; the multimodal v5 Omni family is deliberately not declared here. */
87
+ export const JINA_EMBEDDING_MODELS = [
88
+ 'jina-embeddings-v5-text-small',
89
+ 'jina-embeddings-v5-text-nano',
90
+ ] as const;
91
+ export type JinaEmbeddingModel = (typeof JINA_EMBEDDING_MODELS)[number];
92
+ /** Documented Matryoshka sizes per model; the 1024 ceiling is the API-wide maximum. */
93
+ export const JINA_EMBEDDING_DIMENSIONS: Readonly<Record<JinaEmbeddingModel, readonly number[]>> = Object.freeze({
94
+ 'jina-embeddings-v5-text-small': [32, 64, 128, 256, 512, 1024],
95
+ 'jina-embeddings-v5-text-nano': [32, 64, 128, 256, 512, 768],
96
+ });
97
+ export const JINA_EMBEDDING_TASKS = [
98
+ 'retrieval.passage',
99
+ 'retrieval.query',
100
+ 'text-matching',
101
+ 'clustering',
102
+ 'classification',
103
+ ] as const;
104
+ export type JinaEmbeddingTask = (typeof JINA_EMBEDDING_TASKS)[number];
105
+
106
+ /** Alibaba Model Studio qwen3.7 text embedding through the OpenAI-compatible endpoint. */
107
+ export const DASHSCOPE_EMBEDDING_MODELS = ['qwen3.7-text-embedding'] as const;
108
+ export type DashScopeEmbeddingModel = (typeof DASHSCOPE_EMBEDDING_MODELS)[number];
109
+ /** The model overview and parameter reference disagree on 1536/2048, so they are not declared. */
110
+ export const DASHSCOPE_EMBEDDING_DIMENSIONS = [64, 128, 256, 512, 768, 1024, 2560] as const;
111
+ export type DashScopeEmbeddingDimension = (typeof DASHSCOPE_EMBEDDING_DIMENSIONS)[number];
112
+ export const DEFAULT_DASHSCOPE_DIMENSIONS: DashScopeEmbeddingDimension = 1024;
113
+
114
+ /** Hetzner Inference serves one documented embedding model with fixed 1024 dimensions. */
115
+ export const HETZNER_EMBEDDING_MODELS = ['BAAI/bge-m3'] as const;
116
+ export type HetznerEmbeddingModel = (typeof HETZNER_EMBEDDING_MODELS)[number];
117
+ export const HETZNER_EMBEDDING_DIMENSIONS = 1024;
118
+
119
+ /** Console (pay-as-you-go) embedding model IDs documented by OpenCode. */
120
+ export const OPENCODE_EMBEDDING_MODELS = [
121
+ 'text-embedding-3-small',
122
+ 'text-embedding-3-large',
123
+ 'gemini-embedding-2',
124
+ 'gemini-embedding-001',
125
+ 'codestral-embed',
126
+ 'mistral-embed',
127
+ 'cohere-embed-v5-pro',
128
+ 'cohere-embed-v5-fast',
129
+ 'voyage-4',
130
+ 'voyage-code-4',
131
+ 'qwen3-embedding-8b',
132
+ 'bge-m3',
133
+ ] as const;
134
+ export type OpenCodeEmbeddingModel = (typeof OPENCODE_EMBEDDING_MODELS)[number];
135
+
136
+ /** Go subscription embedding model IDs documented by OpenCode. */
137
+ export const OPENCODE_GO_EMBEDDING_MODELS = [
138
+ 'text-embedding-3-small',
139
+ 'qwen3-embedding-8b',
140
+ 'gemini-embedding-2',
141
+ ] as const;
142
+ export type OpenCodeGoEmbeddingModel = (typeof OPENCODE_GO_EMBEDDING_MODELS)[number];
143
+
144
+ export const OPENROUTER_EMBEDDING_MODELS = [
145
+ 'openai/text-embedding-3-small',
146
+ 'openai/text-embedding-3-large',
147
+ ] as const;
148
+ export type OpenRouterEmbeddingModel = (typeof OPENROUTER_EMBEDDING_MODELS)[number];
35
149
  export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'] as const;
36
150
  export const GEMINI_EMBEDDING_MODELS = ['gemini-embedding-2'] as const;
37
151
  export const GEMINI_EMBEDDING_MIN_DIMENSIONS = 128;
@@ -69,9 +183,82 @@ const gatewayModelSchema = Type.Union([
69
183
  Type.Literal('openai/text-embedding-3-small'),
70
184
  ]);
71
185
 
72
- const openRouterModelSchema = Type.Literal('openai/text-embedding-3-small');
186
+ const openRouterModelSchema = Type.Union([
187
+ Type.Literal('openai/text-embedding-3-small'),
188
+ Type.Literal('openai/text-embedding-3-large'),
189
+ ]);
190
+ const openAiModelSchema = Type.Union([
191
+ Type.Literal('text-embedding-3-small'),
192
+ Type.Literal('text-embedding-3-large'),
193
+ ]);
194
+ const voyageModelSchema = Type.Union([
195
+ Type.Literal('voyage-4-large'),
196
+ Type.Literal('voyage-4'),
197
+ Type.Literal('voyage-4-lite'),
198
+ Type.Literal('voyage-code-4'),
199
+ ]);
200
+ const voyageDimensionsSchema = Type.Union([
201
+ Type.Literal(256),
202
+ Type.Literal(512),
203
+ Type.Literal(1024),
204
+ Type.Literal(2048),
205
+ ]);
206
+ const cohereModelSchema = Type.Union([
207
+ Type.Literal('embed-v5.0-pro'),
208
+ Type.Literal('embed-v5.0-fast'),
209
+ ]);
210
+ const cohereDimensionsSchema = Type.Union([
211
+ Type.Literal(256),
212
+ Type.Literal(512),
213
+ Type.Literal(768),
214
+ Type.Literal(1024),
215
+ Type.Literal(1536),
216
+ Type.Literal(2048),
217
+ ]);
218
+ const jinaModelSchema = Type.Union([
219
+ Type.Literal('jina-embeddings-v5-text-small'),
220
+ Type.Literal('jina-embeddings-v5-text-nano'),
221
+ ]);
222
+ const jinaTaskSchema = Type.Union([
223
+ Type.Literal('retrieval.passage'),
224
+ Type.Literal('retrieval.query'),
225
+ Type.Literal('text-matching'),
226
+ Type.Literal('clustering'),
227
+ Type.Literal('classification'),
228
+ ]);
229
+ const jinaDimensionsSchema = Type.Integer({ minimum: 32, maximum: 1024 });
230
+ const dashScopeModelSchema = Type.Literal('qwen3.7-text-embedding');
231
+ const dashScopeDimensionsSchema = Type.Union([
232
+ Type.Literal(64),
233
+ Type.Literal(128),
234
+ Type.Literal(256),
235
+ Type.Literal(512),
236
+ Type.Literal(768),
237
+ Type.Literal(1024),
238
+ Type.Literal(2560),
239
+ ]);
240
+ const hetznerModelSchema = Type.Literal('BAAI/bge-m3');
73
241
  const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
74
242
  const geminiModelSchema = Type.Literal(GEMINI_EMBEDDING_MODELS[0]);
243
+ const openCodeModelSchema = Type.Union([
244
+ Type.Literal('text-embedding-3-small'),
245
+ Type.Literal('text-embedding-3-large'),
246
+ Type.Literal('gemini-embedding-2'),
247
+ Type.Literal('gemini-embedding-001'),
248
+ Type.Literal('codestral-embed'),
249
+ Type.Literal('mistral-embed'),
250
+ Type.Literal('cohere-embed-v5-pro'),
251
+ Type.Literal('cohere-embed-v5-fast'),
252
+ Type.Literal('voyage-4'),
253
+ Type.Literal('voyage-code-4'),
254
+ Type.Literal('qwen3-embedding-8b'),
255
+ Type.Literal('bge-m3'),
256
+ ]);
257
+ const openCodeGoModelSchema = Type.Union([
258
+ Type.Literal('text-embedding-3-small'),
259
+ Type.Literal('qwen3-embedding-8b'),
260
+ Type.Literal('gemini-embedding-2'),
261
+ ]);
75
262
  export const VERTEX_EMBEDDING_LOCATIONS = ['us', 'eu', 'global'] as const;
76
263
  const vertexLocationSchema = Type.Union([
77
264
  Type.Literal('us'),
@@ -159,6 +346,13 @@ const embeddingProviderSchema = Type.Union([
159
346
  Type.Literal('cloudflare'),
160
347
  Type.Literal('gemini'),
161
348
  Type.Literal('vertex'),
349
+ Type.Literal('opencode'),
350
+ Type.Literal('opencode-go'),
351
+ Type.Literal('voyage'),
352
+ Type.Literal('cohere'),
353
+ Type.Literal('jina'),
354
+ Type.Literal('dashscope'),
355
+ Type.Literal('hetzner'),
162
356
  ]);
163
357
 
164
358
  export const embeddingRouteSchema = Type.Object(
@@ -175,6 +369,14 @@ const spaceCommon = {
175
369
  normalization: Type.Literal(EMBEDDING_NORMALIZATION_VERSION),
176
370
  };
177
371
 
372
+ const openCodeSpaceCommon = {
373
+ ...spaceCommon,
374
+ revision: Type.Null(),
375
+ quantization: Type.Null(),
376
+ // Observed only after a successful response; preflight descriptors never invent a dimension.
377
+ dimensions: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
378
+ };
379
+
178
380
  const geminiSpaceCommon = {
179
381
  format: Type.Literal(EMBEDDING_FORMAT_VERSION),
180
382
  prefix: Type.Union([
@@ -224,6 +426,81 @@ export const embeddingSpaceSchema = Type.Union([
224
426
  },
225
427
  { additionalProperties: false }
226
428
  ),
429
+ Type.Object(
430
+ {
431
+ ...spaceCommon,
432
+ provider: Type.Literal('openai'),
433
+ model: Type.Literal('text-embedding-3-large'),
434
+ revision: Type.Null(),
435
+ quantization: Type.Null(),
436
+ runtime: Type.Null(),
437
+ dimensions: Type.Literal(3072),
438
+ },
439
+ { additionalProperties: false }
440
+ ),
441
+ Type.Object(
442
+ {
443
+ ...spaceCommon,
444
+ provider: Type.Literal('voyage'),
445
+ model: voyageModelSchema,
446
+ revision: Type.Null(),
447
+ quantization: Type.Null(),
448
+ runtime: Type.Literal('voyage-api-v1'),
449
+ dimensions: voyageDimensionsSchema,
450
+ inputType: Type.Literal('document'),
451
+ },
452
+ { additionalProperties: false }
453
+ ),
454
+ Type.Object(
455
+ {
456
+ ...spaceCommon,
457
+ provider: Type.Literal('cohere'),
458
+ model: cohereModelSchema,
459
+ revision: Type.Null(),
460
+ quantization: Type.Null(),
461
+ runtime: Type.Literal('cohere-api-v2'),
462
+ dimensions: cohereDimensionsSchema,
463
+ inputType: Type.Literal('search_document'),
464
+ },
465
+ { additionalProperties: false }
466
+ ),
467
+ Type.Object(
468
+ {
469
+ ...spaceCommon,
470
+ provider: Type.Literal('jina'),
471
+ model: jinaModelSchema,
472
+ revision: Type.Null(),
473
+ quantization: Type.Null(),
474
+ runtime: Type.Literal('jina-api-v1'),
475
+ dimensions: jinaDimensionsSchema,
476
+ task: Type.Literal('retrieval.passage'),
477
+ },
478
+ { additionalProperties: false }
479
+ ),
480
+ Type.Object(
481
+ {
482
+ ...spaceCommon,
483
+ provider: Type.Literal('dashscope'),
484
+ model: dashScopeModelSchema,
485
+ revision: Type.Null(),
486
+ quantization: Type.Null(),
487
+ runtime: Type.Literal('dashscope-compatible-mode-v1'),
488
+ dimensions: dashScopeDimensionsSchema,
489
+ },
490
+ { additionalProperties: false }
491
+ ),
492
+ Type.Object(
493
+ {
494
+ ...spaceCommon,
495
+ provider: Type.Literal('hetzner'),
496
+ model: hetznerModelSchema,
497
+ revision: Type.Null(),
498
+ quantization: Type.Null(),
499
+ runtime: Type.Literal('hetzner-inference-v1'),
500
+ dimensions: Type.Literal(1024),
501
+ },
502
+ { additionalProperties: false }
503
+ ),
227
504
  Type.Object(
228
505
  {
229
506
  ...spaceCommon,
@@ -265,6 +542,24 @@ export const embeddingSpaceSchema = Type.Union([
265
542
  },
266
543
  { additionalProperties: false }
267
544
  ),
545
+ Type.Object(
546
+ {
547
+ ...openCodeSpaceCommon,
548
+ provider: Type.Literal('opencode'),
549
+ model: openCodeModelSchema,
550
+ runtime: Type.Literal('opencode-console-embeddings-v1'),
551
+ },
552
+ { additionalProperties: false }
553
+ ),
554
+ Type.Object(
555
+ {
556
+ ...openCodeSpaceCommon,
557
+ provider: Type.Literal('opencode-go'),
558
+ model: openCodeGoModelSchema,
559
+ runtime: Type.Literal('opencode-go-embeddings-v1'),
560
+ },
561
+ { additionalProperties: false }
562
+ ),
268
563
  ]);
269
564
 
270
565
  export const embeddingSettingsSchema = Type.Object(
@@ -350,6 +645,61 @@ export const embeddingSettingsSchema = Type.Object(
350
645
  { additionalProperties: false }
351
646
  )
352
647
  ),
648
+ opencode: Type.Optional(
649
+ Type.Object(
650
+ { apiKey: Type.Optional(Type.String({ minLength: 1 })) },
651
+ { additionalProperties: false }
652
+ )
653
+ ),
654
+ 'opencode-go': Type.Optional(
655
+ Type.Object(
656
+ { apiKey: Type.Optional(Type.String({ minLength: 1 })) },
657
+ { additionalProperties: false }
658
+ )
659
+ ),
660
+ voyage: Type.Optional(
661
+ Type.Object(
662
+ {
663
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
664
+ dimensions: Type.Optional(voyageDimensionsSchema),
665
+ },
666
+ { additionalProperties: false }
667
+ )
668
+ ),
669
+ cohere: Type.Optional(
670
+ Type.Object(
671
+ {
672
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
673
+ dimensions: Type.Optional(cohereDimensionsSchema),
674
+ },
675
+ { additionalProperties: false }
676
+ )
677
+ ),
678
+ jina: Type.Optional(
679
+ Type.Object(
680
+ {
681
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
682
+ dimensions: Type.Optional(jinaDimensionsSchema),
683
+ },
684
+ { additionalProperties: false }
685
+ )
686
+ ),
687
+ dashscope: Type.Optional(
688
+ Type.Object(
689
+ {
690
+ baseUrl: Type.String({ minLength: 1 }),
691
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
692
+ dimensions: Type.Optional(dashScopeDimensionsSchema),
693
+ },
694
+ { additionalProperties: false }
695
+ )
696
+ ),
697
+ hetzner: Type.Optional(
698
+ Type.Object(
699
+ { apiKey: Type.Optional(Type.String({ minLength: 1 })) },
700
+ { additionalProperties: false }
701
+ )
702
+ ),
353
703
  },
354
704
  { additionalProperties: false }
355
705
  )
package/src/settings.ts CHANGED
@@ -6,24 +6,41 @@ import { Value } from 'typebox/value';
6
6
  import { EmbeddingsError } from './errors.js';
7
7
  import {
8
8
  CLOUDFLARE_EMBEDDING_MODELS,
9
+ COHERE_EMBEDDING_MODELS,
10
+ DASHSCOPE_EMBEDDING_MODELS,
9
11
  EMBEDDINGS_SETTINGS_KEY,
10
12
  GATEWAY_EMBEDDING_MODELS,
11
13
  GEMINI_EMBEDDING_MODELS,
14
+ HETZNER_EMBEDDING_MODELS,
15
+ JINA_EMBEDDING_DIMENSIONS,
16
+ JINA_EMBEDDING_MODELS,
17
+ OPENAI_EMBEDDING_MODELS,
18
+ OPENCODE_EMBEDDING_MODELS,
19
+ OPENCODE_GO_EMBEDDING_MODELS,
12
20
  OPENROUTER_EMBEDDING_MODELS,
21
+ VOYAGE_EMBEDDING_MODELS,
13
22
  embeddingSettingsSchema,
14
23
  type EmbeddingRoute,
15
24
  type EmbeddingSettings,
25
+ type JinaEmbeddingModel,
16
26
  } from './schemas.js';
17
27
 
18
28
  const MODELS_BY_PROVIDER: Readonly<Record<EmbeddingRoute['provider'], readonly string[]>> = {
19
29
  local: ['embeddinggemma-2'],
20
- openai: ['text-embedding-3-small'],
30
+ openai: OPENAI_EMBEDDING_MODELS,
21
31
  sarvam: ['embeddinggemma-2'],
22
32
  gateway: GATEWAY_EMBEDDING_MODELS,
23
33
  openrouter: OPENROUTER_EMBEDDING_MODELS,
24
34
  cloudflare: CLOUDFLARE_EMBEDDING_MODELS,
25
35
  gemini: GEMINI_EMBEDDING_MODELS,
26
36
  vertex: GEMINI_EMBEDDING_MODELS,
37
+ opencode: OPENCODE_EMBEDDING_MODELS,
38
+ 'opencode-go': OPENCODE_GO_EMBEDDING_MODELS,
39
+ voyage: VOYAGE_EMBEDDING_MODELS,
40
+ cohere: COHERE_EMBEDDING_MODELS,
41
+ jina: JINA_EMBEDDING_MODELS,
42
+ dashscope: DASHSCOPE_EMBEDDING_MODELS,
43
+ hetzner: HETZNER_EMBEDDING_MODELS,
27
44
  };
28
45
 
29
46
  export const isEmbeddingSettings = (value: unknown): value is EmbeddingSettings =>
@@ -62,6 +79,18 @@ export function validateEmbeddingSettings(value: unknown): EmbeddingSettings {
62
79
  const routes = [value.default, ...(value.fallback ?? []), ...(value.compare ?? [])];
63
80
  if (routes.some((route) => route.provider === 'vertex') && value.providers?.vertex === undefined)
64
81
  return configuration('configuration-invalid');
82
+ // Jina documents a per-model Matryoshka set, so an undeclared size fails before any inference.
83
+ const jinaDimensions = value.providers?.jina?.dimensions;
84
+ if (jinaDimensions !== undefined) {
85
+ for (const route of routes) {
86
+ if (route.provider !== 'jina') continue;
87
+ if (!MODELS_BY_PROVIDER.jina.includes(route.model))
88
+ return configuration('configuration-invalid');
89
+ const documented = JINA_EMBEDDING_DIMENSIONS[route.model as JinaEmbeddingModel];
90
+ if (documented === undefined || !documented.includes(jinaDimensions))
91
+ return configuration('configuration-invalid');
92
+ }
93
+ }
65
94
  if (value.version !== undefined && value.version !== 1)
66
95
  return configuration('configuration-invalid');
67
96
  return value;