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:
@@ -19,7 +19,7 @@ const REPO_ROOT = path.resolve(import.meta.dirname, "..");
|
||||
const TSX_LOADER = path.join(REPO_ROOT, "node_modules", "tsx", "dist", "loader.mjs");
|
||||
|
||||
describe("LH_DATA_DIR seam", () => {
|
||||
it("relocates data/chats/graph + modelCache under LH_DATA_DIR, keeps prompts ROOT-anchored", async () => {
|
||||
it("relocates data/chats/graph under LH_DATA_DIR, keeps prompts ROOT-anchored", async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "lh-seam-"));
|
||||
process.env.LH_DATA_DIR = dir;
|
||||
try {
|
||||
@@ -27,7 +27,6 @@ describe("LH_DATA_DIR seam", () => {
|
||||
assert.equal(PATHS.data, dir, "PATHS.data resolves the env value (resolved absolute)");
|
||||
assert.equal(PATHS.chats, path.join(dir, "chats"));
|
||||
assert.equal(PATHS.graph, path.join(dir, "graph"));
|
||||
assert.equal(PATHS.modelCache, path.join(dir, "models"), "the HF model cache follows the seam");
|
||||
assert.equal(
|
||||
PATHS.teacherPrompt,
|
||||
path.join(ROOT, "src", "agent", "system-prompt.md"),
|
||||
@@ -41,12 +40,11 @@ describe("LH_DATA_DIR seam", () => {
|
||||
it("unset = the repo data/ exactly as before (fresh child process, no env)", () => {
|
||||
const out = execFileSync(
|
||||
process.execPath,
|
||||
["--import", TSX_LOADER, "--eval", `const m = await import(${JSON.stringify(path.join(REPO_ROOT, "config.ts"))}); console.log(JSON.stringify({ data: m.PATHS.data, chats: m.PATHS.chats, modelCache: m.PATHS.modelCache }));`],
|
||||
["--import", TSX_LOADER, "--eval", `const m = await import(${JSON.stringify(path.join(REPO_ROOT, "config.ts"))}); console.log(JSON.stringify({ data: m.PATHS.data, chats: m.PATHS.chats }));`],
|
||||
{ cwd: REPO_ROOT, encoding: "utf-8" },
|
||||
);
|
||||
const parsed = JSON.parse(out) as { data: string; chats: string | null; modelCache: string | null };
|
||||
const parsed = JSON.parse(out) as { data: string; chats: string | null };
|
||||
assert.equal(parsed.data, path.join(REPO_ROOT, "data"));
|
||||
assert.equal(parsed.chats, path.join(REPO_ROOT, "data", "chats"));
|
||||
assert.equal(parsed.modelCache, null, "dev keeps the transformers package default cache");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user