{"record":{"id":"6a2a5a26369a4225","repo":"abhigyanpatwari/GitNexus","slug":"failed-to-load-embedding-model","errorCode":null,"errorMessage":"Failed to load embedding model","messagePattern":"Failed to load embedding model","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/mcp/core/embedder.ts","lineNumber":156,"sourceCode":"          }\n          logger.info({ device }, 'GitNexus: Embedding model loaded');\n          return embedderInstance!;\n        } catch (deviceError) {\n          // Network errors and circuit-open errors are not device-specific —\n          // they will fail the same way on every device. Rethrow immediately\n          // with actionable HF_ENDPOINT guidance rather than silently falling\n          // back to the next device.\n          const errMsg = deviceError instanceof Error ? deviceError.message : String(deviceError);\n          if (isHfDownloadFailure(errMsg)) {\n            const endpointHint = process.env.HF_ENDPOINT\n              ? `The configured endpoint (${process.env.HF_ENDPOINT}) may be unreachable.`\n              : `huggingface.co may be unreachable from your network.\\n` +\n                `  Set HF_ENDPOINT to a mirror and retry:\\n` +\n                `    HF_ENDPOINT=https://hf-mirror.com npx gitnexus analyze --embeddings\\n` +\n                `    (Windows: set HF_ENDPOINT=https://hf-mirror.com && npx gitnexus analyze --embeddings)`;\n            throw new Error(`Failed to download embedding model: ${errMsg}\\n  ${endpointHint}`);\n          }\n          if (device === 'cpu') throw new Error('Failed to load embedding model');\n        }\n      }\n\n      throw new Error('No suitable device found');\n    } catch (error) {\n      isInitializing = false;\n      initPromise = null;\n      embedderInstance = null;\n      throw error;\n    } finally {\n      isInitializing = false;\n    }\n  })();\n\n  return initPromise;\n};\n\n/**","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/mcp/core/embedder.ts#L138-L174","documentation":"In initEmbedder's device loop, when the last-resort 'cpu' device fails to load the model for a reason that is not an HF download failure, this generic message is thrown. The model bytes were obtained (or cached) but the pipeline could not be constructed on CPU — pointing at corrupted cache files or a transformers.js/onnxruntime version mismatch rather than networking.","triggerScenarios":"Loading a cached model on cpu after an interrupted first download left corrupt files in the transformers.js cache dir; upgrading gitnexus (which pins new @huggingface/transformers / onnxruntime-node versions) while an old cache layout remains; native runtime load failing for non-network reasons (missing system libs, OOM).","commonSituations":"Rerunning --embeddings after a Ctrl-C during the first download; long-lived machines with stale HF/transformers caches; Node major-version upgrades breaking native module ABI alongside the embedding stack.","solutions":["Clear the model cache and retry so it re-downloads cleanly: remove the transformers.js cache dir (HF_HOME / default ~/.cache/huggingface or .cache/transformers.js).","Refresh the embedding stack with `gitnexus embeddings install` to realign @huggingface/transformers and onnxruntime-node versions.","Update GitNexus to the latest patch so stack pins match the loader code.","If local loading stays broken, fall back to HTTP embeddings via GITNEXUS_EMBEDDING_URL/GITNEXUS_EMBEDDING_MODEL."],"exampleFix":"# before: corrupt/stale cache prevents cpu load\n$ gitnexus analyze --embeddings\n# → Failed to load embedding model\n\n# after: purge cache and refresh the stack, then retry\n$ rm -rf ~/.cache/huggingface/transformers\n$ gitnexus embeddings install\n$ gitnexus analyze --embeddings","handlingStrategy":"fallback","validationCode":"// Cheap sanity check on the cached model before starting a long analyze\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nconst cacheDir = process.env.HF_HOME\n  ? join(process.env.HF_HOME, 'transformers')\n  : join(process.env.HOME ?? '', '.cache', 'huggingface', 'transformers');\nconst modelCacheOk = existsSync(cacheDir); // absence just means a fresh download, corruption still surfaces at load","typeGuard":null,"tryCatchPattern":"try {\n  await runAnalyze({ embeddings: true });\n} catch (err) {\n  const msg = err instanceof Error ? err.message : '';\n  if (msg === 'Failed to load embedding model') {\n    // not a network issue: clear cache once, then fall back to HTTP embeddings if it recurs\n    await rm(hfTransformersCache(), { recursive: true, force: true });\n    return runAnalyzeWithHttpEmbeddings();\n  }\n  throw err;\n}","preventionTips":["Treat an interrupted first `analyze --embeddings` as suspect: clear the transformers cache before the next run.","Re-run `gitnexus embeddings install` after upgrading gitnexus to keep transformers/onnxruntime versions aligned.","Keep HF_HOME on fast local storage; network filesystems corrupt long model writes.","Configure GITNEXUS_EMBEDDING_URL as a standing fallback for embedding-critical workflows."],"tags":["embeddings","model-load","cache-corruption","onnxruntime","transformers-js"],"backgroundTag":"model-load-failed","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}