{"record":{"id":"a0be2c45f3191287","repo":"abhigyanpatwari/GitNexus","slug":"no-suitable-device-found-for-embedding-model","errorCode":null,"errorMessage":"No suitable device found for embedding model","messagePattern":"No suitable device found for embedding model","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/embeddings/embedder.ts","lineNumber":252,"sourceCode":"              ? `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 (isDev && (device === 'cuda' || device === 'dml')) {\n            const gpuType = device === 'dml' ? 'DirectML' : 'CUDA';\n            logger.info(`⚠️  ${gpuType} not available, falling back to CPU...`);\n          }\n          // Continue to next device in list\n          if (device === devicesToTry[devicesToTry.length - 1]) {\n            throw deviceError; // Last device failed, propagate error\n          }\n        }\n      }\n\n      throw new Error('No suitable device found for embedding model');\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/**\n * Check if the embedder is initialized and ready\n */\nexport const isEmbedderReady = (): boolean => {\n  return isHttpMode() || embedderInstance !== null;","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/core/embeddings/embedder.ts#L234-L270","documentation":"Thrown by getEmbedder() when the @huggingface/transformers pipeline() call fails to create an ONNX Runtime session on every candidate device. Devices tried are [requestedDevice, 'cpu'] for GITNEXUS_EMBEDDING_DEVICE=cuda|dml, or just ['cpu']/['wasm'] otherwise; note that when the LAST device fails, the original deviceError propagates (embedder.ts:247), so this literal message is the defensive exhaustiveness guard for the no-device-succeeded path.","triggerScenarios":"Initializing the local embedding model with GITNEXUS_EMBEDDING_DEVICE=cuda or dml where GPU init fails AND the CPU fallback also fails (or a direct cpu/wasm request failing), e.g. onnxruntime native module mismatch, corrupted model cache under ~/.cache/huggingface, or insufficient memory for even the CPU session.","commonSituations":"Node/onnxruntime-node version skew after a package upgrade, a partially downloaded model in the HF cache, CI containers without GPU libs where even CPU WASM init fails, or low-memory environments where the fp32 session cannot allocate.","solutions":["Set GITNEXUS_EMBEDDING_DEVICE=cpu explicitly and retry to bypass GPU probing.","Clear the HuggingFace cache (rm -rf ~/.cache/huggingface or your HF_HOME dir) so the model re-downloads cleanly.","Free memory or reduce GITNEXUS_EMBEDDING_THREADS; fp32 sessions are large.","Reinstall gitnexus so onnxruntime-node native bindings match your Node version.","Switch to HTTP embedding mode (set GITNEXUS_EMBEDDING_URL + GITNEXUS_EMBEDDING_MODEL) to skip local ONNX entirely."],"exampleFix":"# before\nGITNEXUS_EMBEDDING_DEVICE=cuda npx gitnexus analyze --embeddings\n# after (force CPU, or use an HTTP endpoint)\nGITNEXUS_EMBEDDING_DEVICE=cpu npx gitnexus analyze --embeddings\n# or: export GITNEXUS_EMBEDDING_URL=http://localhost:11434/v1 GITNEXUS_EMBEDDING_MODEL=nomic-embed-text","handlingStrategy":"fallback","validationCode":"import { isEmbedderReady, getEmbedder } from './embedder';\n// warm the model at startup, not lazily mid-query\nif (!isEmbedderReady()) {\n  await getEmbedder(); // throws early with the real deviceError\n}","typeGuard":"const isDeviceError = (e: unknown): boolean =>\n  e instanceof Error && /No suitable device found|device/i.test(e.message);","tryCatchPattern":"try {\n  await getEmbedder();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('No suitable device')) {\n    // fall back to HTTP embedding mode or skip embeddings\n  } else throw e;\n}","preventionTips":["Set GITNEXUS_EMBEDDING_DEVICE=cpu in CI/containers where GPU runtimes are absent or broken.","Warm up the embedder at process start so device failures surface before long indexing work.","Keep HF_HOME on writable storage and clear it after upgrading gitnexus/model versions.","Provide an HTTP embedding endpoint as the deployment-grade fallback."],"tags":["embeddings","onnxruntime","device","gpu","initialization"],"backgroundTag":"onnx-runtime-device-unavailable","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}