@abhishek944/pi-embeddings 0.2.0 → 0.5.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
@@ -19,19 +19,110 @@ export const EMBEDDING_ROUTE_IDS = [
19
19
  'gateway',
20
20
  'openrouter',
21
21
  'cloudflare',
22
+ 'gemini',
23
+ 'vertex',
24
+ 'opencode',
25
+ 'opencode-go',
22
26
  ];
23
27
  export const GATEWAY_EMBEDDING_MODELS = [
24
28
  'text-embedding-3-small',
25
29
  'openai/text-embedding-3-small',
26
30
  ];
31
+ /** Console (pay-as-you-go) embedding model IDs documented by OpenCode. */
32
+ export const OPENCODE_EMBEDDING_MODELS = [
33
+ 'text-embedding-3-small',
34
+ 'text-embedding-3-large',
35
+ 'gemini-embedding-2',
36
+ 'gemini-embedding-001',
37
+ 'codestral-embed',
38
+ 'mistral-embed',
39
+ 'cohere-embed-v5-pro',
40
+ 'cohere-embed-v5-fast',
41
+ 'voyage-4',
42
+ 'voyage-code-4',
43
+ 'qwen3-embedding-8b',
44
+ 'bge-m3',
45
+ ];
46
+ /** Go subscription embedding model IDs documented by OpenCode. */
47
+ export const OPENCODE_GO_EMBEDDING_MODELS = [
48
+ 'text-embedding-3-small',
49
+ 'qwen3-embedding-8b',
50
+ 'gemini-embedding-2',
51
+ ];
27
52
  export const OPENROUTER_EMBEDDING_MODELS = ['openai/text-embedding-3-small'];
28
53
  export const CLOUDFLARE_EMBEDDING_MODELS = ['@cf/baai/bge-base-en-v1.5'];
54
+ export const GEMINI_EMBEDDING_MODELS = ['gemini-embedding-2'];
55
+ export const GEMINI_EMBEDDING_MIN_DIMENSIONS = 128;
56
+ export const GEMINI_EMBEDDING_MAX_DIMENSIONS = 3072;
57
+ export const DEFAULT_GEMINI_DIMENSIONS = 3072;
58
+ export const GEMINI_EMBEDDING_TASK_FORMATS = [
59
+ 'retrieval-document',
60
+ 'search-query',
61
+ 'question-answering',
62
+ 'fact-checking',
63
+ 'code-retrieval',
64
+ 'classification',
65
+ 'clustering',
66
+ 'sentence-similarity',
67
+ ];
68
+ export const DEFAULT_GEMINI_TASK_FORMAT = 'retrieval-document';
69
+ /** Official Gemini Embedding 2 text task prefixes. `task_type` is not used for this model. */
70
+ export const GEMINI_TASK_PREFIXES = {
71
+ 'retrieval-document': 'title: none | text: ',
72
+ 'search-query': 'task: search result | query: ',
73
+ 'question-answering': 'task: question answering | query: ',
74
+ 'fact-checking': 'task: fact checking | query: ',
75
+ 'code-retrieval': 'task: code retrieval | query: ',
76
+ classification: 'task: classification | query: ',
77
+ clustering: 'task: clustering | query: ',
78
+ 'sentence-similarity': 'task: sentence similarity | query: ',
79
+ };
29
80
  const gatewayModelSchema = Type.Union([
30
81
  Type.Literal('text-embedding-3-small'),
31
82
  Type.Literal('openai/text-embedding-3-small'),
32
83
  ]);
33
84
  const openRouterModelSchema = Type.Literal('openai/text-embedding-3-small');
34
85
  const cloudflareModelSchema = Type.Literal('@cf/baai/bge-base-en-v1.5');
86
+ const geminiModelSchema = Type.Literal(GEMINI_EMBEDDING_MODELS[0]);
87
+ const openCodeModelSchema = Type.Union([
88
+ Type.Literal('text-embedding-3-small'),
89
+ Type.Literal('text-embedding-3-large'),
90
+ Type.Literal('gemini-embedding-2'),
91
+ Type.Literal('gemini-embedding-001'),
92
+ Type.Literal('codestral-embed'),
93
+ Type.Literal('mistral-embed'),
94
+ Type.Literal('cohere-embed-v5-pro'),
95
+ Type.Literal('cohere-embed-v5-fast'),
96
+ Type.Literal('voyage-4'),
97
+ Type.Literal('voyage-code-4'),
98
+ Type.Literal('qwen3-embedding-8b'),
99
+ Type.Literal('bge-m3'),
100
+ ]);
101
+ const openCodeGoModelSchema = Type.Union([
102
+ Type.Literal('text-embedding-3-small'),
103
+ Type.Literal('qwen3-embedding-8b'),
104
+ Type.Literal('gemini-embedding-2'),
105
+ ]);
106
+ export const VERTEX_EMBEDDING_LOCATIONS = ['us', 'eu', 'global'];
107
+ const vertexLocationSchema = Type.Union([
108
+ Type.Literal('us'),
109
+ Type.Literal('eu'),
110
+ Type.Literal('global'),
111
+ ]);
112
+ const geminiDimensionsSchema = Type.Integer({
113
+ minimum: GEMINI_EMBEDDING_MIN_DIMENSIONS,
114
+ maximum: GEMINI_EMBEDDING_MAX_DIMENSIONS,
115
+ });
116
+ const geminiTaskFormatSchema = Type.Union([
117
+ Type.Literal('retrieval-document'),
118
+ Type.Literal('search-query'),
119
+ Type.Literal('question-answering'),
120
+ Type.Literal('fact-checking'),
121
+ Type.Literal('code-retrieval'),
122
+ Type.Literal('classification'),
123
+ Type.Literal('clustering'),
124
+ Type.Literal('sentence-similarity'),
125
+ ]);
35
126
  const embeddingErrorCodeSchema = Type.Union([
36
127
  Type.Literal('configuration-invalid'),
37
128
  Type.Literal('route-unconfigured'),
@@ -93,6 +184,10 @@ const embeddingProviderSchema = Type.Union([
93
184
  Type.Literal('gateway'),
94
185
  Type.Literal('openrouter'),
95
186
  Type.Literal('cloudflare'),
187
+ Type.Literal('gemini'),
188
+ Type.Literal('vertex'),
189
+ Type.Literal('opencode'),
190
+ Type.Literal('opencode-go'),
96
191
  ]);
97
192
  export const embeddingRouteSchema = Type.Object({
98
193
  provider: embeddingProviderSchema,
@@ -103,6 +198,32 @@ const spaceCommon = {
103
198
  prefix: Type.Literal(EMBEDDING_DOCUMENT_PREFIX),
104
199
  normalization: Type.Literal(EMBEDDING_NORMALIZATION_VERSION),
105
200
  };
201
+ const openCodeSpaceCommon = {
202
+ ...spaceCommon,
203
+ revision: Type.Null(),
204
+ quantization: Type.Null(),
205
+ // Observed only after a successful response; preflight descriptors never invent a dimension.
206
+ dimensions: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
207
+ };
208
+ const geminiSpaceCommon = {
209
+ format: Type.Literal(EMBEDDING_FORMAT_VERSION),
210
+ prefix: Type.Union([
211
+ Type.Literal('title: none | text: '),
212
+ Type.Literal('task: search result | query: '),
213
+ Type.Literal('task: question answering | query: '),
214
+ Type.Literal('task: fact checking | query: '),
215
+ Type.Literal('task: code retrieval | query: '),
216
+ Type.Literal('task: classification | query: '),
217
+ Type.Literal('task: clustering | query: '),
218
+ Type.Literal('task: sentence similarity | query: '),
219
+ ]),
220
+ normalization: Type.Literal(EMBEDDING_NORMALIZATION_VERSION),
221
+ model: geminiModelSchema,
222
+ revision: Type.Null(),
223
+ quantization: Type.Null(),
224
+ dimensions: geminiDimensionsSchema,
225
+ taskFormat: geminiTaskFormatSchema,
226
+ };
106
227
  /**
107
228
  * Complete generating-space identity. `provider` is canonical: the gateway route deliberately
108
229
  * reports the OpenAI recipe it declares, not its transport alias.
@@ -135,6 +256,16 @@ export const embeddingSpaceSchema = Type.Union([
135
256
  runtime: Type.Literal('sarvam-v2'),
136
257
  dimensions: Type.Literal(768),
137
258
  }, { additionalProperties: false }),
259
+ Type.Object({
260
+ ...geminiSpaceCommon,
261
+ provider: Type.Literal('gemini'),
262
+ runtime: Type.Literal('gemini-api-v1beta'),
263
+ }, { additionalProperties: false }),
264
+ Type.Object({
265
+ ...geminiSpaceCommon,
266
+ provider: Type.Literal('vertex'),
267
+ runtime: Type.Literal('vertex-ai-v1'),
268
+ }, { additionalProperties: false }),
138
269
  Type.Object({
139
270
  ...spaceCommon,
140
271
  provider: Type.Literal('cloudflare'),
@@ -145,6 +276,18 @@ export const embeddingSpaceSchema = Type.Union([
145
276
  dimensions: Type.Literal(768),
146
277
  pooling: Type.Union([Type.Literal('mean'), Type.Literal('cls')]),
147
278
  }, { additionalProperties: false }),
279
+ Type.Object({
280
+ ...openCodeSpaceCommon,
281
+ provider: Type.Literal('opencode'),
282
+ model: openCodeModelSchema,
283
+ runtime: Type.Literal('opencode-console-embeddings-v1'),
284
+ }, { additionalProperties: false }),
285
+ Type.Object({
286
+ ...openCodeSpaceCommon,
287
+ provider: Type.Literal('opencode-go'),
288
+ model: openCodeGoModelSchema,
289
+ runtime: Type.Literal('opencode-go-embeddings-v1'),
290
+ }, { additionalProperties: false }),
148
291
  ]);
149
292
  export const embeddingSettingsSchema = Type.Object({
150
293
  version: Type.Optional(Type.Literal(1)),
@@ -173,6 +316,19 @@ export const embeddingSettingsSchema = Type.Object({
173
316
  model: Type.Optional(cloudflareModelSchema),
174
317
  pooling: Type.Optional(Type.Union([Type.Literal('mean'), Type.Literal('cls')])),
175
318
  }, { additionalProperties: false })),
319
+ vertex: Type.Optional(Type.Object({
320
+ project: Type.String({ minLength: 1, pattern: '^[a-zA-Z0-9_-]+$' }),
321
+ location: vertexLocationSchema,
322
+ dimensions: geminiDimensionsSchema,
323
+ taskFormat: geminiTaskFormatSchema,
324
+ }, { additionalProperties: false })),
325
+ gemini: Type.Optional(Type.Object({
326
+ apiKey: Type.Optional(Type.String({ minLength: 1 })),
327
+ dimensions: Type.Optional(geminiDimensionsSchema),
328
+ taskFormat: Type.Optional(geminiTaskFormatSchema),
329
+ }, { additionalProperties: false })),
330
+ opencode: Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
331
+ 'opencode-go': Type.Optional(Type.Object({ apiKey: Type.Optional(Type.String({ minLength: 1 })) }, { additionalProperties: false })),
176
332
  }, { additionalProperties: false })),
177
333
  }, { additionalProperties: false });
178
334
  export const embeddingRequestSchema = Type.Object({
@@ -2,13 +2,13 @@ import { randomUUID } from 'node:crypto';
2
2
  import { lstat, mkdir, open, readFile, rename, unlink } from 'node:fs/promises';
3
3
  import { withFileMutationQueue } from '@earendil-works/pi-coding-agent';
4
4
  import { join, resolve } from 'node:path';
5
- import { validateEmbeddingSettings } from './settings.js';
5
+ import { configuredDefault } from './settings.js';
6
6
  import { EMBEDDINGS_SETTINGS_KEY } from './schemas.js';
7
7
  export class EmbeddingsSettingsWriteError extends Error {
8
8
  }
9
9
  /** Update only the trusted project's `pi-embeddings.default`, preserving every unrelated key. */
10
10
  export function updateProjectEmbeddingSettings({ cwd, projectTrusted, route, }) {
11
- validateEmbeddingSettings({ default: route });
11
+ configuredDefault({ default: route });
12
12
  const settingsPath = resolve(cwd, '.pi', 'settings.json');
13
13
  return withFileMutationQueue(settingsPath, () => updateProjectEmbeddingSettingsNow({ cwd, projectTrusted, route }));
14
14
  }
package/dist/settings.js CHANGED
@@ -4,7 +4,7 @@ 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, OPENROUTER_EMBEDDING_MODELS, embeddingSettingsSchema, } from './schemas.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';
8
8
  const MODELS_BY_PROVIDER = {
9
9
  local: ['embeddinggemma-2'],
10
10
  openai: ['text-embedding-3-small'],
@@ -12,6 +12,10 @@ const MODELS_BY_PROVIDER = {
12
12
  gateway: GATEWAY_EMBEDDING_MODELS,
13
13
  openrouter: OPENROUTER_EMBEDDING_MODELS,
14
14
  cloudflare: CLOUDFLARE_EMBEDDING_MODELS,
15
+ gemini: GEMINI_EMBEDDING_MODELS,
16
+ vertex: GEMINI_EMBEDDING_MODELS,
17
+ opencode: OPENCODE_EMBEDDING_MODELS,
18
+ 'opencode-go': OPENCODE_GO_EMBEDDING_MODELS,
15
19
  };
16
20
  export const isEmbeddingSettings = (value) => Value.Check(embeddingSettingsSchema, value);
17
21
  function configuration(message) {
@@ -41,6 +45,9 @@ export function validateEmbeddingSettings(value) {
41
45
  assertRoute(route, `fallback[${index}]`);
42
46
  for (const [index, route] of (value.compare ?? []).entries())
43
47
  assertRoute(route, `compare[${index}]`);
48
+ const routes = [value.default, ...(value.fallback ?? []), ...(value.compare ?? [])];
49
+ if (routes.some((route) => route.provider === 'vertex') && value.providers?.vertex === undefined)
50
+ return configuration('configuration-invalid');
44
51
  if (value.version !== undefined && value.version !== 1)
45
52
  return configuration('configuration-invalid');
46
53
  return value;