@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/src/response.ts CHANGED
@@ -277,3 +277,155 @@ export function parseCloudflareBatchResponse(args: {
277
277
  },
278
278
  };
279
279
  }
280
+
281
+ const orderedVectorsResponseSchema = Type.Object({
282
+ model: Type.Optional(Type.String({ minLength: 1 })),
283
+ data: Type.Array(
284
+ Type.Object({
285
+ index: Type.Integer({ minimum: 0 }),
286
+ embedding: Type.Array(Type.Number()),
287
+ })
288
+ ),
289
+ });
290
+
291
+ const voyageUsageSchema = Type.Object({ total_tokens: Type.Integer({ minimum: 0 }) });
292
+ const promptTokensUsageSchema = Type.Object({
293
+ prompt_tokens: Type.Optional(Type.Integer({ minimum: 0 })),
294
+ });
295
+
296
+ /**
297
+ * Ordered one-vector-per-input response for providers that report usage under their own field names
298
+ * or not at all. The declared dimension is enforced, so an unexpected vector length fails closed.
299
+ */
300
+ function parseOrderedVectors(args: {
301
+ response: unknown;
302
+ space: EmbeddingSpace;
303
+ expectedModels: readonly string[];
304
+ expectedCount: number;
305
+ providerReportedInputTokens: number | null;
306
+ }): ProviderBatchResult {
307
+ if (!Value.Check(orderedVectorsResponseSchema, args.response))
308
+ throw new EmbeddingsError('provider-response-invalid', { knownUsage: {} });
309
+ const parsed = args.response;
310
+ const knownUsage = {
311
+ providerReportedInputTokens: args.providerReportedInputTokens,
312
+ preparedInputTokens: null,
313
+ };
314
+ const fail = (
315
+ code: 'provider-response-mismatch' | 'vector-invalid' | 'vector-zero'
316
+ ): never => {
317
+ throw new EmbeddingsError(code, { knownUsage });
318
+ };
319
+ if (parsed.model !== undefined && !args.expectedModels.includes(parsed.model))
320
+ fail('provider-response-mismatch');
321
+ const ordered = [...parsed.data].sort((left, right) => left.index - right.index);
322
+ if (ordered.length !== args.expectedCount || ordered.some((item, index) => item.index !== index))
323
+ fail('provider-response-mismatch');
324
+ let vectors: number[][];
325
+ try {
326
+ vectors = ordered.map((item) => normalizeVector(item.embedding, dimensionsOf(args.space)));
327
+ } catch (error) {
328
+ if (error instanceof EmbeddingsError)
329
+ fail(error.code === 'vector-zero' ? 'vector-zero' : 'vector-invalid');
330
+ throw error;
331
+ }
332
+ return {
333
+ vectors,
334
+ usage: {
335
+ providerReportedInputTokens: args.providerReportedInputTokens,
336
+ preparedInputTokens: null,
337
+ billedTokens: null,
338
+ },
339
+ };
340
+ }
341
+
342
+ const usageField = (response: unknown, field: string): unknown => {
343
+ if (typeof response !== 'object' || response === null || Array.isArray(response)) return undefined;
344
+ const usage = (response as Record<string, unknown>).usage;
345
+ if (typeof usage !== 'object' || usage === null || Array.isArray(usage)) return undefined;
346
+ return (usage as Record<string, unknown>)[field];
347
+ };
348
+
349
+ /** Voyage reports `usage.total_tokens` rather than an OpenAI `prompt_tokens` count. */
350
+ export function parseVoyageBatchResponse(args: {
351
+ response: unknown;
352
+ space: EmbeddingSpace;
353
+ expectedModels: readonly string[];
354
+ expectedCount: number;
355
+ }): ProviderBatchResult {
356
+ const usage: unknown = (() => {
357
+ const holder = usageField(args.response, 'total_tokens');
358
+ return holder === undefined ? undefined : { total_tokens: holder };
359
+ })();
360
+ if (!Value.Check(voyageUsageSchema, usage))
361
+ throw new EmbeddingsError('provider-response-invalid', { knownUsage: {} });
362
+ return parseOrderedVectors({ ...args, providerReportedInputTokens: usage.total_tokens });
363
+ }
364
+
365
+ /** Hetzner documents no embedding usage payload, so a missing count stays explicitly unknown. */
366
+ export function parseOptionalUsageBatchResponse(args: {
367
+ response: unknown;
368
+ space: EmbeddingSpace;
369
+ expectedModels: readonly string[];
370
+ expectedCount: number;
371
+ }): ProviderBatchResult {
372
+ const reported = usageField(args.response, 'prompt_tokens');
373
+ const usage: unknown = reported === undefined ? undefined : { prompt_tokens: reported };
374
+ if (usage !== undefined && !Value.Check(promptTokensUsageSchema, usage))
375
+ throw new EmbeddingsError('provider-response-invalid', { knownUsage: {} });
376
+ const tokens = Value.Check(promptTokensUsageSchema, usage) ? (usage.prompt_tokens ?? null) : null;
377
+ return parseOrderedVectors({ ...args, providerReportedInputTokens: tokens });
378
+ }
379
+
380
+ const cohereResponseSchema = Type.Object({
381
+ embeddings: Type.Object({
382
+ float: Type.Array(Type.Array(Type.Number())),
383
+ }),
384
+ meta: Type.Optional(
385
+ Type.Object({
386
+ billed_units: Type.Optional(
387
+ Type.Object({ input_tokens: Type.Optional(Type.Number({ minimum: 0 })) })
388
+ ),
389
+ tokens: Type.Optional(
390
+ Type.Object({ input_tokens: Type.Optional(Type.Number({ minimum: 0 })) })
391
+ ),
392
+ })
393
+ ),
394
+ });
395
+
396
+ /**
397
+ * Cohere `/v2/embed` returns embeddings grouped by type in input order and echoes no model id.
398
+ * Only the requested float vectors are accepted; the count and declared dimension are enforced.
399
+ */
400
+ export function parseCohereBatchResponse(args: {
401
+ response: unknown;
402
+ space: EmbeddingSpace;
403
+ expectedCount: number;
404
+ }): ProviderBatchResult {
405
+ if (!Value.Check(cohereResponseSchema, args.response))
406
+ throw new EmbeddingsError('provider-response-invalid', { knownUsage: {} });
407
+ const parsed = args.response;
408
+ const billed = parsed.meta?.tokens?.input_tokens ?? parsed.meta?.billed_units?.input_tokens ?? null;
409
+ const providerReportedInputTokens = billed === null ? null : Math.round(billed);
410
+ const knownUsage = { providerReportedInputTokens, preparedInputTokens: null };
411
+ const fail = (
412
+ code: 'provider-response-mismatch' | 'vector-invalid' | 'vector-zero'
413
+ ): never => {
414
+ throw new EmbeddingsError(code, { knownUsage });
415
+ };
416
+ if (parsed.embeddings.float.length !== args.expectedCount) fail('provider-response-mismatch');
417
+ let vectors: number[][];
418
+ try {
419
+ vectors = parsed.embeddings.float.map((vector) =>
420
+ normalizeVector(vector, dimensionsOf(args.space))
421
+ );
422
+ } catch (error) {
423
+ if (error instanceof EmbeddingsError)
424
+ fail(error.code === 'vector-zero' ? 'vector-zero' : 'vector-invalid');
425
+ throw error;
426
+ }
427
+ return {
428
+ vectors,
429
+ usage: { providerReportedInputTokens, preparedInputTokens: null, billedTokens: null },
430
+ };
431
+ }
package/src/schemas.ts CHANGED
@@ -25,15 +25,97 @@ export const EMBEDDING_ROUTE_IDS = [
25
25
  'vertex',
26
26
  'opencode',
27
27
  'opencode-go',
28
+ 'voyage',
29
+ 'cohere',
30
+ 'jina',
31
+ 'dashscope',
32
+ 'hetzner',
28
33
  ] as const;
29
34
  export type EmbeddingRouteId = (typeof EMBEDDING_ROUTE_IDS)[number];
30
35
  export type OpenCodeRouteId = Extract<EmbeddingRouteId, 'opencode' | 'opencode-go'>;
31
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>);
48
+
32
49
  export const GATEWAY_EMBEDDING_MODELS = [
33
50
  'text-embedding-3-small',
34
51
  'openai/text-embedding-3-small',
35
52
  ] as const;
36
53
 
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
+
37
119
  /** Console (pay-as-you-go) embedding model IDs documented by OpenCode. */
38
120
  export const OPENCODE_EMBEDDING_MODELS = [
39
121
  'text-embedding-3-small',
@@ -59,7 +141,11 @@ export const OPENCODE_GO_EMBEDDING_MODELS = [
59
141
  ] as const;
60
142
  export type OpenCodeGoEmbeddingModel = (typeof OPENCODE_GO_EMBEDDING_MODELS)[number];
61
143
 
62
- export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'] as const;
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];
63
149
  export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'] as const;
64
150
  export const GEMINI_EMBEDDING_MODELS = ['gemini-embedding-2'] as const;
65
151
  export const GEMINI_EMBEDDING_MIN_DIMENSIONS = 128;
@@ -97,7 +183,61 @@ const gatewayModelSchema = Type.Union([
97
183
  Type.Literal('openai/text-embedding-3-small'),
98
184
  ]);
99
185
 
100
- 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');
101
241
  const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
102
242
  const geminiModelSchema = Type.Literal(GEMINI_EMBEDDING_MODELS[0]);
103
243
  const openCodeModelSchema = Type.Union([
@@ -208,6 +348,11 @@ const embeddingProviderSchema = Type.Union([
208
348
  Type.Literal('vertex'),
209
349
  Type.Literal('opencode'),
210
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'),
211
356
  ]);
212
357
 
213
358
  export const embeddingRouteSchema = Type.Object(
@@ -281,6 +426,81 @@ export const embeddingSpaceSchema = Type.Union([
281
426
  },
282
427
  { additionalProperties: false }
283
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
+ ),
284
504
  Type.Object(
285
505
  {
286
506
  ...spaceCommon,
@@ -437,6 +657,49 @@ export const embeddingSettingsSchema = Type.Object(
437
657
  { additionalProperties: false }
438
658
  )
439
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
+ ),
440
703
  },
441
704
  { additionalProperties: false }
442
705
  )
package/src/settings.ts CHANGED
@@ -6,20 +6,28 @@ 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,
12
18
  OPENCODE_EMBEDDING_MODELS,
13
19
  OPENCODE_GO_EMBEDDING_MODELS,
14
20
  OPENROUTER_EMBEDDING_MODELS,
21
+ VOYAGE_EMBEDDING_MODELS,
15
22
  embeddingSettingsSchema,
16
23
  type EmbeddingRoute,
17
24
  type EmbeddingSettings,
25
+ type JinaEmbeddingModel,
18
26
  } from './schemas.js';
19
27
 
20
28
  const MODELS_BY_PROVIDER: Readonly<Record<EmbeddingRoute['provider'], readonly string[]>> = {
21
29
  local: ['embeddinggemma-2'],
22
- openai: ['text-embedding-3-small'],
30
+ openai: OPENAI_EMBEDDING_MODELS,
23
31
  sarvam: ['embeddinggemma-2'],
24
32
  gateway: GATEWAY_EMBEDDING_MODELS,
25
33
  openrouter: OPENROUTER_EMBEDDING_MODELS,
@@ -28,6 +36,11 @@ const MODELS_BY_PROVIDER: Readonly<Record<EmbeddingRoute['provider'], readonly s
28
36
  vertex: GEMINI_EMBEDDING_MODELS,
29
37
  opencode: OPENCODE_EMBEDDING_MODELS,
30
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,
31
44
  };
32
45
 
33
46
  export const isEmbeddingSettings = (value: unknown): value is EmbeddingSettings =>
@@ -66,6 +79,18 @@ export function validateEmbeddingSettings(value: unknown): EmbeddingSettings {
66
79
  const routes = [value.default, ...(value.fallback ?? []), ...(value.compare ?? [])];
67
80
  if (routes.some((route) => route.provider === 'vertex') && value.providers?.vertex === undefined)
68
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
+ }
69
94
  if (value.version !== undefined && value.version !== 1)
70
95
  return configuration('configuration-invalid');
71
96
  return value;