@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/README.md +32 -6
- package/dist/execute.js +2 -1
- package/dist/extension.js +23 -5
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/provider-types.d.ts +4 -0
- package/dist/providers.d.ts +29 -4
- package/dist/providers.js +580 -20
- package/dist/response.d.ts +34 -0
- package/dist/response.js +179 -3
- package/dist/runtime.d.ts +6 -1
- package/dist/runtime.js +8 -3
- package/dist/schemas.d.ts +1121 -45
- package/dist/schemas.js +268 -2
- package/dist/settings.js +22 -2
- package/dist/tool-contracts.d.ts +507 -9
- package/package.json +9 -3
- package/src/execute.ts +2 -1
- package/src/extension.ts +43 -5
- package/src/index.ts +35 -0
- package/src/provider-types.ts +7 -0
- package/src/providers.ts +719 -16
- package/src/response.ts +225 -3
- package/src/runtime.ts +25 -6
- package/src/schemas.ts +352 -2
- package/src/settings.ts +30 -1
package/README.md
CHANGED
|
@@ -59,13 +59,24 @@ Settings live under the `pi-embeddings` namespace. Pi loading follows global < a
|
|
|
59
59
|
"apiKey": "${GEMINI_API_KEY}",
|
|
60
60
|
"dimensions": 3072,
|
|
61
61
|
"taskFormat": "retrieval-document"
|
|
62
|
-
}
|
|
62
|
+
},
|
|
63
|
+
"opencode": { "apiKey": "${OPENCODE_API_KEY}" },
|
|
64
|
+
"opencode-go": { "apiKey": "${OPENCODE_API_KEY}" },
|
|
65
|
+
"voyage": { "apiKey": "${VOYAGE_API_KEY}", "dimensions": 1024 },
|
|
66
|
+
"cohere": { "apiKey": "${COHERE_API_KEY}", "dimensions": 2048 },
|
|
67
|
+
"jina": { "apiKey": "${JINA_API_KEY}", "dimensions": 1024 },
|
|
68
|
+
"dashscope": {
|
|
69
|
+
"baseUrl": "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com",
|
|
70
|
+
"apiKey": "${DASHSCOPE_API_KEY}",
|
|
71
|
+
"dimensions": 1024
|
|
72
|
+
},
|
|
73
|
+
"hetzner": { "apiKey": "${HETZNER_INFERENCE_TOKEN}" }
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
77
|
```
|
|
67
78
|
|
|
68
|
-
Provider IDs are route identifiers: `local`, `openai`, `sarvam`, `gateway`, `openrouter`, `cloudflare`, `gemini` and `
|
|
79
|
+
Provider IDs are route identifiers: `local`, `openai`, `sarvam`, `gateway`, `openrouter`, `cloudflare`, `gemini`, `vertex`, `opencode`, `opencode-go`, `voyage`, `cohere`, `jina`, `dashscope` and `hetzner`. Only the declared model pairs are valid. Omitted or empty `fallback` and `compare` lists are inactive. No route is activated by a schema annotation, a present key or existing model files. Credentials and identifiers may also come from `OPENROUTER_API_KEY`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_AI_GATEWAY_ID`, `GEMINI_API_KEY`, `OPENCODE_API_KEY`, `VOYAGE_API_KEY`, `COHERE_API_KEY`, `JINA_API_KEY`, `DASHSCOPE_API_KEY`, `DASHSCOPE_BASE_URL` and `HETZNER_INFERENCE_TOKEN` in the trusted host environment. An environment fallback works only when the MCP process itself receives that variable; a hosted settings file that is copied without environment forwarding must carry the relevant `providers.<route>.apiKey` directly. In the Pi extension, OpenCode routes can also use the provider key already resolved by Pi through `ModelRegistry.getApiKeyForProvider`; the library and MCP server never read Pi's credential file.
|
|
69
80
|
|
|
70
81
|
### Google Cloud Vertex (keyless ADC)
|
|
71
82
|
|
|
@@ -102,15 +113,24 @@ Ordinary calls use the configured default, then configured fallback in order, ad
|
|
|
102
113
|
## Routes and batching
|
|
103
114
|
|
|
104
115
|
- `local`: pinned EmbeddingGemma 2 Q8 CPU, 768 dimensions. The operator supplies assets; the package verifies the exact model hash and runtime commit, starts only its own loopback child, uses CPU-only flags, shares it across acquisitions and closes it once. No download, install, global binary search, warmup or foreign listener takeover.
|
|
105
|
-
- `openai`: `text-embedding-3-small
|
|
116
|
+
- `openai`: `text-embedding-3-small` (1536 dimensions) or `text-embedding-3-large` (3072 dimensions). Complete prefixed strings are submitted; `cl100k_base` counts the exact prepared string and a local encode/decode round-trip is checked. Mandatory limits are 8192 tokens per input, 2048 inputs and 300000 tokens per request.
|
|
106
117
|
- `sarvam`: hosted `embeddinggemma-2`, 768 dimensions. Strings are submitted and the service enforces its documented per-string token estimate; no local count or borrowed aggregate cap is invented.
|
|
107
118
|
- `gateway`: the declared OpenAI recipe through LiteLLM. Only `text-embedding-3-small` and `openai/text-embedding-3-small` aliases are supported. One request carries generic host attribution as `x-litellm-customer-id` and `x-litellm-tags`; missing or unsafe attribution refuses before inference.
|
|
108
|
-
- `openrouter`: `openai/text-embedding-3-small` through `https://openrouter.ai/api/v1/embeddings` with bearer authentication and float output.
|
|
119
|
+
- `openrouter`: `openai/text-embedding-3-small` or `openai/text-embedding-3-large` through `https://openrouter.ai/api/v1/embeddings` with bearer authentication and float output. Each model shares the matching direct-OpenAI generating-space descriptor because the declared model, text preparation and normalization are identical.
|
|
109
120
|
- `cloudflare`: `@cf/baai/bge-base-en-v1.5` through Cloudflare's documented REST `POST /ai/run/{model}`. The Cloudflare API token goes in `Authorization`, and the gateway ID goes in `cf-aig-gateway-id` as Workers AI requires. `pooling` defaults to `mean`; `cls` produces a different generating space and is recorded in the result. The REST API wraps the model output in its standard `result` envelope; the parser also accepts the model's raw `{ shape, data, pooling }` form. Cloudflare reports no local token usage, so usage fields are null.
|
|
110
121
|
- `gemini`: `gemini-embedding-2` through the fixed Gemini API `POST /v1beta/models/gemini-embedding-2:embedContent` endpoint with the `x-goog-api-key` header. `dimensions` accepts the documented 128–3072 range (768, 1536 and 3072 are Google's recommended sizes) and defaults to `3072`. `taskFormat` selects the documented Gemini 2 text prefix (`retrieval-document` by default, plus query and single-input formats); the package does not send `task_type`, which applies only to `gemini-embedding-001`. Each exact prepared prompt is counted with the model's `countTokens` endpoint before a single-input `embedContent` request; inputs over the documented 8192-token boundary fail before inference, and the embed response token count must match the preflight count before a vector is accepted. `autoTruncate: false` is deliberately not sent because the official SDK marks it Enterprise/Vertex-only. The exact dimension, task format and prefix are recorded in the generating space.
|
|
111
122
|
|
|
123
|
+
- `opencode`: OpenCode Console pay-as-you-go models through the fixed `POST https://opencode.ai/inference/openai/v1/embeddings` endpoint with bearer authentication. Pi calls this catalog OpenCode Zen. The twelve documented embedding model IDs are `text-embedding-3-small`, `text-embedding-3-large`, `gemini-embedding-2`, `gemini-embedding-001`, `codestral-embed`, `mistral-embed`, `cohere-embed-v5-pro`, `cohere-embed-v5-fast`, `voyage-4`, `voyage-code-4`, `qwen3-embedding-8b` and `bge-m3`. No `dimensions` option is guessed; the response's vector length becomes the observed dimension in the actual generating space. An echoed model that differs from the configured model fails closed.
|
|
124
|
+
- `opencode-go`: OpenCode Go subscription through the fixed `POST https://opencode.ai/inference/go/openai/v1/embeddings` endpoint. The documented models are `text-embedding-3-small`, `qwen3-embedding-8b` and `gemini-embedding-2`. Embeddings do not need the chat `x-opencode-session` header; the adapter identifies itself with a `pi-embeddings` user agent. A missing or non-Go key returns HTTP 401 or 403; 403 entitlement failures do not advance fallback. Both OpenCode routes use explicit `providers.opencode.apiKey` or `providers.opencode-go.apiKey`, Pi's stored provider key in the extension, or `OPENCODE_API_KEY`, in that order.
|
|
125
|
+
|
|
112
126
|
- `vertex`: Google Cloud `gemini-embedding-2` through the fixed Vertex `v1` `embedContent` and `countTokens` resource methods with keyless ADC. Each exact instruction-prefixed text is counted before inference and must fit the documented 8192-token window; `role: user` is consistent in both operations. Dimensions use `embedContentConfig.outputDimensionality`. The model's `task_type` and `autoTruncate` options are not used. A true response `truncated` flag, mismatched prompt count, missing usage, invalid dimensions or invalid vector fails closed; no truncated vector is accepted. Its complete descriptor has `provider: vertex` and `runtime: vertex-ai-v1`, distinct from `gemini` even for identical model names and dimensions.
|
|
113
127
|
|
|
128
|
+
- `voyage`: `voyage-4-large`, `voyage-4`, `voyage-4-lite` or `voyage-code-4` through the fixed `POST https://api.voyageai.com/v1/embeddings` endpoint with bearer authentication. Requests carry `input_type: "document"` (Voyage then prepends its documented document prompt), the configured `output_dimension` (1024 default; 256, 512 or 2048) and `truncation: false`, so an over-length input fails instead of being shortened. Documented limits are 32000 tokens per input and a 1000-input list; Voyage documents aggregate caps of 1M tokens for `voyage-4-lite`, 320K for `voyage-4` and 120K for `voyage-4-large`, enforces them itself, and this package does not approximate the model tokenizer. No aggregate cap is documented for `voyage-code-4`, so none is claimed. `voyage-4-nano` is an open-weight Hugging Face release, not a Voyage API model, and `voyage-context-4` is a separate contextualized-chunk endpoint that returns one vector per chunk; neither is a route here.
|
|
129
|
+
- `cohere`: `embed-v5.0-pro` or `embed-v5.0-fast` through `POST https://api.cohere.com/v2/embed` with bearer authentication. Requests carry the required `input_type: "search_document"`, `texts`, `embedding_types: ["float"]`, the configured `output_dimension` (2048 default; 256, 512, 768, 1024 or 1536) and `truncate: "NONE"`. Documented limits are 96 texts per call and a 128K-token context per text. Cohere also documents image and mixed PDF input for these models; this package stays text-in/text-out and sends only `texts`.
|
|
130
|
+
- `jina`: `jina-embeddings-v5-text-small` or `jina-embeddings-v5-text-nano` through the fixed `POST https://api.jina.ai/v1/embeddings` endpoint with bearer authentication. Requests carry `task: "retrieval.passage"`, the configured `dimensions` from that model's documented Matryoshka set (small: 32, 64, 128, 256, 512 or 1024 with a 1024 default; nano: 32, 64, 128, 256, 512 or 768 with a 768 default), `embedding_type: "float"`, `normalized: false` because this package owns L2 normalization, and `truncate: false`. Context is 32K tokens for small and 8K for nano; Jina publishes RPM/TPM rate limits but no per-request input-count ceiling, so none is invented. The multimodal v5 Omni family is not declared.
|
|
131
|
+
- `dashscope`: Alibaba Model Studio `qwen3.7-text-embedding` through the OpenAI-compatible `POST {baseUrl}/compatible-mode/v1/embeddings` endpoint and bearer `DASHSCOPE_API_KEY`. The host is workspace-scoped, so `baseUrl` is operator-supplied and required; the adapter appends `/compatible-mode/v1/embeddings` to it. Requests carry `dimensions` (1024 default; 64, 128, 256, 512, 768 or 2560) and `encoding_format: "float"`. Documented limits are 20 rows per request and 128000 tokens per row; the response is OpenAI-shaped with `usage.prompt_tokens`. Model Studio's parameter reference restricts 1536 and 2048 to `text-embedding-v4`, so neither is declared; its model overview table also omits 64 and 128, while the parameter reference lists them for every model, so those two are kept and the conflict is recorded in the evidence file. The same `DASHSCOPE_API_KEY` serves the DashScope image route in `pi-image-gen`; it is a shared credential across packages, not a shared space.
|
|
132
|
+
- `hetzner`: `BAAI/bge-m3` through the fixed `POST https://inference.hetzner.com/v1/embeddings` endpoint with bearer `HETZNER_INFERENCE_TOKEN`. Hetzner Inference is EU-hosted and OpenAI-shaped for this endpoint: the request carries `model`, `input` and `encoding_format: "float"` (Hetzner's compatibility page documents `float` and `base64`), and the response returns `data[i].embedding`, text only. The model produces 1024 dimensions with an 8192-token context; documented request boundaries are a 32 MiB body and about 1M tokens recommended per request with no fixed input count. `dimensions` is not sent because BGE-M3 is not Matryoshka and Hetzner rejects a custom dimension for models that do not support one. Hetzner documents no embedding usage payload, so usage fields are null when the response omits them.
|
|
133
|
+
|
|
114
134
|
The package supplies the document prefix `title: none | text: ` exactly once and normalizes vectors with the recorded stable L2 identity. It never summarizes, trims, chunks or truncates input text.
|
|
115
135
|
|
|
116
136
|
## MCP attribution
|
|
@@ -127,12 +147,18 @@ This is attribution only. The authenticated server-to-server boundary supplies c
|
|
|
127
147
|
|
|
128
148
|
Descriptors record canonical provider, model, known revision or explicit null, quantization/runtime/pooling provenance, dimensions, preparation prefix and normalization identity. Local, Sarvam and Cloudflare remain distinct at 768 dimensions, and Cloudflare `mean` and `cls` are distinct spaces. Gemini and Vertex dimensions and task formats are distinct spaces, including 768-dimensional MRL output; Vertex is never relabeled as the Developer API or vice versa, because the provider, prompt format and normalization provenance differ. Direct OpenAI, the declared gateway alias and the declared OpenRouter alias share the OpenAI descriptor only when the effective text, preparation and normalization remain identical. API keys, service URLs, account IDs and gateway IDs are route metadata, not implicit new spaces. The ordinary embed result carries these descriptors for actual successful work; no separate metadata call is required.
|
|
129
149
|
|
|
130
|
-
Existing stored vector documents are preserved. Package outcome descriptors allow callers to compare complete identity before persistence; a successful inference from an incompatible space is still reported truthfully.
|
|
150
|
+
OpenCode Console and Go are always distinct from direct OpenAI and from each other, even when the model ID is the same: their runtime provenance differs, and bit-for-bit equivalence has not been verified. OpenCode preflight descriptors report `dimensions: null`; a successful outcome records the positive vector length observed in that response. Existing stored vector documents are preserved. Package outcome descriptors allow callers to compare complete identity before persistence; a successful inference from an incompatible space is still reported truthfully.
|
|
151
|
+
|
|
152
|
+
Voyage, Cohere, Jina, DashScope and Hetzner each add their own descriptor family, and every declared model keeps its own `model` value. Two vendor-documented shared-space facts are recorded in the README rather than encoded by aliasing: Voyage states that all embeddings from the four general-purpose 4-series models (`voyage-4-large`, `voyage-4`, `voyage-4-lite`, `voyage-4-nano`) are compatible and can be mixed for asymmetric retrieval, and Cohere states that `embed-v5.0-pro` and `embed-v5.0-fast` share one space. Both claims are written down here; a result still reports the provider and model that actually generated it, so no model is relabeled as another and no distinct model is merged into a single space. `voyage-code-4` is not covered by Voyage's compatibility statement and is therefore its own space. The new descriptors also record the provider-native prompt selector: `inputType: "document"` for Voyage, `inputType: "search_document"` for Cohere and `task: "retrieval.passage"` for Jina, so a document embedding is never confused with a differently prompted one. DashScope and Hetzner record only the model, runtime and dimensions they can verify.
|
|
131
153
|
|
|
132
154
|
## Limits
|
|
133
155
|
|
|
134
|
-
No application capacity caps are added. Provider request limits above are mandatory documented constraints. Sarvam, local and
|
|
156
|
+
No application capacity caps are added. Provider request limits above are mandatory documented constraints. Sarvam, local, Cloudflare, OpenCode, Jina and Hetzner publish no aggregate request cap, so none is invented; Jina and Hetzner also publish no per-request input count ceiling, and Hetzner's documented 32 MiB body limit is a transport ceiling this package does not approximate. Voyage, Cohere and DashScope publish input count ceilings (1000, 96 and 20) that the mandatory batching enforces; their per-input context limits (32000, 128K and 128K tokens) are provider-enforced because no local tokenizer is shipped. OpenCode requires each input to fit the chosen model's context window; the package does not guess a local tokenizer or dimension ceiling for its multi-model catalog, so the service may reject an oversized input. Gemini publishes an 8192-token input boundary and no aggregate request cap; one exact prompt per request is pre-counted with `countTokens`, and a mismatched embed token count fails closed. Cloudflare documents a 512-token per-input ceiling for `bge-base-en-v1.5`; this package does not ship that model's tokenizer and does not approximate the ceiling locally, so Cloudflare may reject an oversized input. No cost estimator or pricing table is included; unknown provider accounting is reported as null. OpenCode's reported `usage.cost` and Go allowance are billing metadata outside the token-usage protocol and remain null in `billedTokens`.
|
|
135
157
|
|
|
136
158
|
Official Vertex contracts: [embedContent](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.publishers.models/embedContent), [countTokens](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.publishers.models/countTokens), [multimodal model constraints and task instructions](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/embeddings/get-multimodal-embeddings), and [ADC discovery order](https://docs.cloud.google.com/docs/authentication/application-default-credentials).
|
|
137
159
|
|
|
160
|
+
Other official contracts: [Voyage text embeddings](https://docs.voyageai.com/docs/embeddings) and [embeddings API reference](https://docs.voyageai.com/reference/embeddings-api), [Cohere Embed models](https://docs.cohere.com/docs/cohere-embed) and [Embed API v2](https://docs.cohere.com/reference/embed), [Jina embeddings API](https://api.jina.ai/docs), [Model Studio OpenAI-compatible embeddings](https://www.alibabacloud.com/help/en/model-studio/embedding-interfaces-compatible-with-openai), and [Hetzner Inference embeddings](https://docs.hetzner.com/ai/inference-api/api-usage/embeddings/).
|
|
161
|
+
|
|
162
|
+
Not implemented here, with the documented reason: Mistral Multimodal Embed ("Clipstral") is an Apache-2.0 open-weights release deployed on-premise or through Mistral Forge, and Mistral documents no hosted embedding endpoint for it; `voyage-4-nano` is open-weight on Hugging Face only; `voyage-context-4` returns one vector per chunk from a separate endpoint; and Jina v5 Omni and Cohere image/PDF input are multimodal. Each would widen the package's text-in/text-out contract, so they are recorded as scope limits rather than routes.
|
|
163
|
+
|
|
138
164
|
The public result protocol is version 2; stored generating-space documents keep their existing descriptor format. Live cloud or local inference, service deployment and shared database writes are not performed by this package.
|
package/dist/execute.js
CHANGED
|
@@ -163,6 +163,7 @@ export async function executeEmbeddings(args) {
|
|
|
163
163
|
attempt.usage = result.usage;
|
|
164
164
|
if (result.vectors.length !== captured.length)
|
|
165
165
|
throw new EmbeddingsError('provider-response-mismatch');
|
|
166
|
+
const actualSpace = result.space ?? provider.space;
|
|
166
167
|
for (const [offset, entry] of captured.entries()) {
|
|
167
168
|
const vector = result.vectors[offset];
|
|
168
169
|
if (vector === undefined)
|
|
@@ -173,7 +174,7 @@ export async function executeEmbeddings(args) {
|
|
|
173
174
|
vector: [...vector],
|
|
174
175
|
route: route.provider,
|
|
175
176
|
model: provider.model,
|
|
176
|
-
space:
|
|
177
|
+
space: actualSpace,
|
|
177
178
|
attemptId,
|
|
178
179
|
normalization: EMBEDDING_NORMALIZATION_VERSION,
|
|
179
180
|
};
|
package/dist/extension.js
CHANGED
|
@@ -13,15 +13,33 @@ const summary = (result) => {
|
|
|
13
13
|
};
|
|
14
14
|
const codeOf = (error) => error instanceof EmbeddingsError ? error.code : 'configuration-invalid';
|
|
15
15
|
const signalOptions = (signal) => signal === undefined ? {} : { signal };
|
|
16
|
+
/** Pi exposes provider keys through ModelRegistry; only nonsecret availability is retained. */
|
|
17
|
+
async function piCredentials(ctx) {
|
|
18
|
+
const opencode = (await ctx.modelRegistry.getApiKeyForProvider('opencode')) !== undefined;
|
|
19
|
+
const go = (await ctx.modelRegistry.getApiKeyForProvider('opencode-go')) !== undefined;
|
|
20
|
+
return {
|
|
21
|
+
available: { opencode, 'opencode-go': go },
|
|
22
|
+
resolver: async (provider) => {
|
|
23
|
+
if (provider === 'opencode' || provider === 'opencode-go')
|
|
24
|
+
return ctx.modelRegistry.getApiKeyForProvider(provider);
|
|
25
|
+
return undefined;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
16
29
|
export default function piEmbeddingsExtension(pi) {
|
|
17
30
|
let settings;
|
|
18
31
|
let runtime;
|
|
19
32
|
let cwd = process.cwd();
|
|
20
|
-
const refresh = async (next, nextCwd
|
|
33
|
+
const refresh = async (next, nextCwd, credentials) => {
|
|
21
34
|
await runtime?.close();
|
|
22
35
|
settings = next;
|
|
23
36
|
cwd = nextCwd;
|
|
24
|
-
runtime = createEmbeddingsRuntimeWithDiagnostics({
|
|
37
|
+
runtime = createEmbeddingsRuntimeWithDiagnostics({
|
|
38
|
+
settings: next,
|
|
39
|
+
cwd: nextCwd,
|
|
40
|
+
credentialResolver: credentials.resolver,
|
|
41
|
+
piCredentialAvailable: credentials.available,
|
|
42
|
+
});
|
|
25
43
|
};
|
|
26
44
|
const currentRuntime = (ctx) => {
|
|
27
45
|
if (runtime === undefined || cwd !== ctx.cwd)
|
|
@@ -29,7 +47,7 @@ export default function piEmbeddingsExtension(pi) {
|
|
|
29
47
|
return runtime;
|
|
30
48
|
};
|
|
31
49
|
pi.on('session_start', async (_event, ctx) => {
|
|
32
|
-
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd);
|
|
50
|
+
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd, await piCredentials(ctx));
|
|
33
51
|
});
|
|
34
52
|
pi.on('session_shutdown', async () => {
|
|
35
53
|
await runtime?.close();
|
|
@@ -122,7 +140,7 @@ export default function piEmbeddingsExtension(pi) {
|
|
|
122
140
|
if (parts.length !== 1)
|
|
123
141
|
throw new EmbeddingsError('configuration-invalid');
|
|
124
142
|
const next = loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx));
|
|
125
|
-
await refresh(next, ctx.cwd);
|
|
143
|
+
await refresh(next, ctx.cwd, await piCredentials(ctx));
|
|
126
144
|
reply(pi, ctx, `${EMBEDDINGS_SETTINGS_KEY} settings reloaded. No inference was run.`);
|
|
127
145
|
return;
|
|
128
146
|
}
|
|
@@ -136,7 +154,7 @@ export default function piEmbeddingsExtension(pi) {
|
|
|
136
154
|
projectTrusted: isProjectTrusted(ctx),
|
|
137
155
|
route,
|
|
138
156
|
});
|
|
139
|
-
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd);
|
|
157
|
+
await refresh(loadEmbeddingSettings(ctx.cwd, isProjectTrusted(ctx)), ctx.cwd, await piCredentials(ctx));
|
|
140
158
|
reply(pi, ctx, `Selected ${route.provider}/${route.model} in trusted project settings.`);
|
|
141
159
|
return;
|
|
142
160
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createEmbeddingsRuntime, type EmbeddingsRuntime } from './runtime.js';
|
|
2
2
|
export { loadEmbeddingSettings, validateEmbeddingSettings, configuredDefault, configuredRoutes, isEmbeddingSettings, } from './settings.js';
|
|
3
3
|
export { EmbeddingsError } from './errors.js';
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
4
|
+
export type { EmbeddingCredentialResolver } from './provider-types.js';
|
|
5
|
+
export { EMBEDDINGS_SETTINGS_KEY, EMBEDDINGS_PROTOCOL_VERSION, EMBEDDING_FORMAT_VERSION, EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_NORMALIZATION_VERSION, EMBEDDING_CONTEXT_META_KEY, EMBEDDING_ROUTE_IDS, OPENAI_EMBEDDING_MODELS, OPENAI_EMBEDDING_DIMENSIONS, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, VERTEX_EMBEDDING_LOCATIONS, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_EMBEDDING_MODELS, OPENROUTER_EMBEDDING_MODELS, VOYAGE_EMBEDDING_MODELS, VOYAGE_EMBEDDING_DIMENSIONS, VOYAGE_INPUT_TYPES, COHERE_EMBEDDING_MODELS, COHERE_EMBEDDING_DIMENSIONS, COHERE_INPUT_TYPES, JINA_EMBEDDING_MODELS, JINA_EMBEDDING_DIMENSIONS, JINA_EMBEDDING_TASKS, DASHSCOPE_EMBEDDING_MODELS, DASHSCOPE_EMBEDDING_DIMENSIONS, HETZNER_EMBEDDING_MODELS, HETZNER_EMBEDDING_DIMENSIONS, GEMINI_EMBEDDING_MIN_DIMENSIONS, GEMINI_EMBEDDING_MAX_DIMENSIONS, GEMINI_EMBEDDING_TASK_FORMATS, GEMINI_TASK_PREFIXES, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, EMBEDDING_ERROR_CODES, } from './schemas.js';
|
|
6
|
+
export type { EmbeddingSettings, EmbeddingRoute, EmbeddingRouteId, EmbeddingSpace, EmbeddingRequest, EmbeddingContext, EmbeddingUsage, EmbeddingAttempt, EmbeddingOutcome, EmbeddingGeneration, EmbeddingResult, EmbeddingCompareEntry, EmbeddingCompareResult, EmbeddingErrorCode, GeminiEmbeddingDimension, GeminiEmbeddingTaskFormat, OpenAiEmbeddingModel, OpenRouterEmbeddingModel, VoyageEmbeddingModel, VoyageEmbeddingDimension, VoyageInputType, CohereEmbeddingModel, CohereEmbeddingDimension, CohereInputType, JinaEmbeddingModel, JinaEmbeddingTask, DashScopeEmbeddingModel, DashScopeEmbeddingDimension, HetznerEmbeddingModel, OpenCodeRouteId, OpenCodeEmbeddingModel, OpenCodeGoEmbeddingModel, } from './schemas.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createEmbeddingsRuntime } from './runtime.js';
|
|
2
2
|
export { loadEmbeddingSettings, validateEmbeddingSettings, configuredDefault, configuredRoutes, isEmbeddingSettings, } from './settings.js';
|
|
3
3
|
export { EmbeddingsError } from './errors.js';
|
|
4
|
-
export { EMBEDDINGS_SETTINGS_KEY, EMBEDDINGS_PROTOCOL_VERSION, EMBEDDING_FORMAT_VERSION, EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_NORMALIZATION_VERSION, EMBEDDING_CONTEXT_META_KEY, EMBEDDING_ROUTE_IDS, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, VERTEX_EMBEDDING_LOCATIONS, GEMINI_EMBEDDING_MIN_DIMENSIONS, GEMINI_EMBEDDING_MAX_DIMENSIONS, GEMINI_EMBEDDING_TASK_FORMATS, GEMINI_TASK_PREFIXES, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, EMBEDDING_ERROR_CODES, } from './schemas.js';
|
|
4
|
+
export { EMBEDDINGS_SETTINGS_KEY, EMBEDDINGS_PROTOCOL_VERSION, EMBEDDING_FORMAT_VERSION, EMBEDDING_DOCUMENT_PREFIX, EMBEDDING_NORMALIZATION_VERSION, EMBEDDING_CONTEXT_META_KEY, EMBEDDING_ROUTE_IDS, OPENAI_EMBEDDING_MODELS, OPENAI_EMBEDDING_DIMENSIONS, GATEWAY_EMBEDDING_MODELS, GEMINI_EMBEDDING_MODELS, VERTEX_EMBEDDING_LOCATIONS, OPENCODE_EMBEDDING_MODELS, OPENCODE_GO_EMBEDDING_MODELS, OPENROUTER_EMBEDDING_MODELS, VOYAGE_EMBEDDING_MODELS, VOYAGE_EMBEDDING_DIMENSIONS, VOYAGE_INPUT_TYPES, COHERE_EMBEDDING_MODELS, COHERE_EMBEDDING_DIMENSIONS, COHERE_INPUT_TYPES, JINA_EMBEDDING_MODELS, JINA_EMBEDDING_DIMENSIONS, JINA_EMBEDDING_TASKS, DASHSCOPE_EMBEDDING_MODELS, DASHSCOPE_EMBEDDING_DIMENSIONS, HETZNER_EMBEDDING_MODELS, HETZNER_EMBEDDING_DIMENSIONS, GEMINI_EMBEDDING_MIN_DIMENSIONS, GEMINI_EMBEDDING_MAX_DIMENSIONS, GEMINI_EMBEDDING_TASK_FORMATS, GEMINI_TASK_PREFIXES, DEFAULT_GEMINI_DIMENSIONS, DEFAULT_GEMINI_TASK_FORMAT, EMBEDDING_ERROR_CODES, } from './schemas.js';
|
package/dist/provider-types.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ export type ProviderUsage = Readonly<{
|
|
|
16
16
|
export type ProviderBatchResult = Readonly<{
|
|
17
17
|
readonly vectors: readonly (readonly number[])[];
|
|
18
18
|
readonly usage: ProviderUsage;
|
|
19
|
+
/** Set only when the response establishes a more specific space than the preflight descriptor. */
|
|
20
|
+
readonly space?: EmbeddingSpace | undefined;
|
|
19
21
|
}>;
|
|
22
|
+
/** Supplied by hosts with a supported provider-key lookup; never invoked with a secret value. */
|
|
23
|
+
export type EmbeddingCredentialResolver = (provider: EmbeddingRouteId) => Promise<string | undefined>;
|
|
20
24
|
export interface EmbeddingsProvider {
|
|
21
25
|
readonly route: EmbeddingRouteId;
|
|
22
26
|
readonly model: string;
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
import { type EmbeddingRoute, type EmbeddingSettings, type EmbeddingSpace, type GeminiEmbeddingDimension, type GeminiEmbeddingTaskFormat } from './schemas.js';
|
|
2
|
-
import type { EmbeddingsProvider } from './provider-types.js';
|
|
1
|
+
import { type CohereEmbeddingDimension, type CohereEmbeddingModel, type DashScopeEmbeddingDimension, type EmbeddingRoute, type EmbeddingSettings, type EmbeddingSpace, type GeminiEmbeddingDimension, type GeminiEmbeddingTaskFormat, type JinaEmbeddingModel, type OpenAiEmbeddingModel, type OpenCodeRouteId, type VoyageEmbeddingDimension, type VoyageEmbeddingModel } from './schemas.js';
|
|
2
|
+
import type { EmbeddingCredentialResolver, EmbeddingsProvider } from './provider-types.js';
|
|
3
|
+
export declare const openaiEmbeddingSpace: (model: OpenAiEmbeddingModel) => EmbeddingSpace;
|
|
3
4
|
export declare const OPENAI_EMBEDDING_SPACE: EmbeddingSpace;
|
|
5
|
+
export declare const voyageEmbeddingSpace: (config: {
|
|
6
|
+
model: VoyageEmbeddingModel;
|
|
7
|
+
dimensions: VoyageEmbeddingDimension;
|
|
8
|
+
}) => EmbeddingSpace;
|
|
9
|
+
export declare const cohereEmbeddingSpace: (config: {
|
|
10
|
+
model: CohereEmbeddingModel;
|
|
11
|
+
dimensions: CohereEmbeddingDimension;
|
|
12
|
+
}) => EmbeddingSpace;
|
|
13
|
+
/** Jina documents per-model Matryoshka sizes; an undeclared size is a configuration error. */
|
|
14
|
+
export declare const jinaEmbeddingSpace: (config: {
|
|
15
|
+
model: JinaEmbeddingModel;
|
|
16
|
+
dimensions: number;
|
|
17
|
+
}) => EmbeddingSpace;
|
|
18
|
+
export declare const dashScopeEmbeddingSpace: (dimensions: DashScopeEmbeddingDimension) => EmbeddingSpace;
|
|
19
|
+
export declare const HETZNER_EMBEDDING_SPACE: EmbeddingSpace;
|
|
4
20
|
export declare const SARVAM_EMBEDDING_SPACE: EmbeddingSpace;
|
|
5
21
|
type CloudflarePooling = 'mean' | 'cls';
|
|
6
22
|
export declare const cloudflareEmbeddingSpace: (pooling: CloudflarePooling) => EmbeddingSpace;
|
|
@@ -8,22 +24,31 @@ export declare const geminiEmbeddingSpace: (config: {
|
|
|
8
24
|
dimensions: GeminiEmbeddingDimension;
|
|
9
25
|
taskFormat: GeminiEmbeddingTaskFormat;
|
|
10
26
|
}) => EmbeddingSpace;
|
|
27
|
+
export declare const OPENCODE_CONSOLE_EMBEDDINGS_URL = "https://opencode.ai/inference/openai/v1/embeddings";
|
|
28
|
+
export declare const OPENCODE_GO_EMBEDDINGS_URL = "https://opencode.ai/inference/go/openai/v1/embeddings";
|
|
29
|
+
export declare const opencodeEmbeddingSpace: (args: {
|
|
30
|
+
provider: OpenCodeRouteId;
|
|
31
|
+
model: string;
|
|
32
|
+
dimensions: number | null;
|
|
33
|
+
}) => EmbeddingSpace;
|
|
11
34
|
export declare const routeKey: (route: EmbeddingRoute) => string;
|
|
35
|
+
export type OpenCodeCredentialAvailability = Readonly<Partial<Record<OpenCodeRouteId, boolean>>>;
|
|
12
36
|
export type EmbeddingDiagnostic = Readonly<{
|
|
13
37
|
readonly code: string;
|
|
14
38
|
readonly severity: 'error' | 'warning' | 'info';
|
|
15
39
|
}>;
|
|
16
40
|
/** Diagnostics are provider-free and never contain keys, origins or model paths. */
|
|
17
|
-
export declare function routeDiagnostics(settings: EmbeddingSettings, route: EmbeddingRoute): EmbeddingDiagnostic[];
|
|
41
|
+
export declare function routeDiagnostics(settings: EmbeddingSettings, route: EmbeddingRoute, piCredentialAvailable?: OpenCodeCredentialAvailability): EmbeddingDiagnostic[];
|
|
18
42
|
export type AcquiredProvider = Readonly<{
|
|
19
43
|
readonly provider: EmbeddingsProvider;
|
|
20
44
|
readonly release: () => Promise<void>;
|
|
21
45
|
}>;
|
|
22
46
|
/** Resolve a configured route only when that route is actually about to be used. */
|
|
23
|
-
export declare function acquireProvider({ settings, route, signal, }: {
|
|
47
|
+
export declare function acquireProvider({ settings, route, signal, credentialResolver, }: {
|
|
24
48
|
settings: EmbeddingSettings;
|
|
25
49
|
route: EmbeddingRoute;
|
|
26
50
|
signal: AbortSignal;
|
|
51
|
+
credentialResolver?: EmbeddingCredentialResolver | undefined;
|
|
27
52
|
}): Promise<AcquiredProvider>;
|
|
28
53
|
export declare const spaceForRoute: (route: EmbeddingRoute, settings?: EmbeddingSettings | undefined) => EmbeddingSpace;
|
|
29
54
|
export {};
|