BYOK provider embeddings (wave 6 chunk B): kill local transformers
Replace the @huggingface/transformers local embedder (~316MB ONNX cache) with an EmbeddingPort seam: graph.embeddingModel (nullable "provider:id" slug) selects an OpenRouter/OpenAI/Gemini adapter, resolved fresh per call from settings + the auth store so key rotations land immediately. - src/server/embeddings.ts rewritten: slug grammar, injected-fetch adapters (OpenRouter input_type, Gemini taskType batching, OpenAI index-ordered rows), honest resolution (null = skip-with-info, set model with missing key = honest error), embedNewNodes with model-change re-embed wipe + ghost pruning + usage steps, federated catalog (OpenRouter /api/v1/embeddings/models — VERIFIED live, the inverse path 404s; OpenAI text-embedding- filter; Gemini embedContent filter). - GET /api/models/embeddings: federated catalog, empty when no keys. - Extraction tail records stages.embedding usage into the run's money channel; EMBEDDING_PRICES overlay in core/prices.ts (outside the sync-generated block), callCost falls back to it; cost-summary folds the fourth stage; graph-context injection resolves its embedder per run, fails honestly when unconfigured, records query tokens. - Settings: GraphSettings.embeddingModel (null factory), section parser validates slug shape (id may contain colons — OpenRouter :free suffixes, live catalog fact). - Removal: @huggingface/transformers uninstalled, PATHS.modelCache and onnx tracing entries deleted, @huggingface tracing-excludes guard added, stale sharp/libvips comments updated to historical. Live-verified on port 3004: catalog federates 36 rows (33 OpenRouter + 3 OpenAI), embedNewNodes embedded 10 nodes via the free liquid/lfm-2.5 model (dim 1024, 435 prompt tokens, 1 call, $0), settings PUT rejects bad slugs with 400. Gates: typecheck, lint, 895/895 tests, build.
This commit is contained in:
@@ -277,7 +277,11 @@ export function parseAppearanceSettingsBody(body: unknown): SettingsBodyResult<A
|
||||
return { ok: true, settings };
|
||||
}
|
||||
|
||||
/** graph: the four-rung ladder { enabled?, embedding?, clustering?, labeling? }. */
|
||||
/** graph: the four-rung ladder { enabled?, embedding?, clustering?, labeling? }
|
||||
* + embeddingModel? — the BYOK provider embedding model (wave 6,
|
||||
* 2026-09-23): null or a "provider:id" slug of a shipped provider.
|
||||
* Catalog validity is network-dependent — the parser checks SHAPE only
|
||||
* (the federated /api/models/embeddings gives the picker real options). */
|
||||
export function parseGraphSettingsBody(body: unknown): SettingsBodyResult<GraphSettings> {
|
||||
const raw = asRecord(body);
|
||||
if (!raw) return { ok: false, error: "Invalid JSON body" };
|
||||
@@ -290,6 +294,25 @@ export function parseGraphSettingsBody(body: unknown): SettingsBodyResult<GraphS
|
||||
settings[key] = raw[key];
|
||||
}
|
||||
}
|
||||
if (raw.embeddingModel !== undefined) {
|
||||
if (raw.embeddingModel !== null) {
|
||||
// NOTE: the id may itself contain colons (OpenRouter suffixes like
|
||||
// "liquid/lfm-2.5-embedding-350m:free") — the provider is the part
|
||||
// before the FIRST colon, so the id half just forbids whitespace.
|
||||
if (
|
||||
typeof raw.embeddingModel !== "string" ||
|
||||
!/^(openrouter|openai|google):\S+$/.test(raw.embeddingModel)
|
||||
) {
|
||||
return {
|
||||
ok: false,
|
||||
error: 'embeddingModel must be null or a "openrouter|openai|google:model-id" slug',
|
||||
};
|
||||
}
|
||||
settings.embeddingModel = raw.embeddingModel;
|
||||
} else {
|
||||
settings.embeddingModel = null;
|
||||
}
|
||||
}
|
||||
return { ok: true, settings };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user