{"record":{"id":"bd2d1d8e24023ca5","repo":"abhigyanpatwari/GitNexus","slug":"embedder-not-initialized-call-initembedder-firs","errorCode":null,"errorMessage":"Embedder not initialized. Call initEmbedder() first.","messagePattern":"Embedder not initialized\\. Call initEmbedder\\(\\) first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/embeddings/embedder.ts","lineNumber":294,"sourceCode":" */\nexport const getEmbeddingDimensions = (): number => {\n  if (isHttpMode()) {\n    return getHttpDimensions() ?? DEFAULT_EMBEDDING_CONFIG.dimensions;\n  }\n  return DEFAULT_EMBEDDING_CONFIG.dimensions;\n};\n\n/**\n * Get the embedder instance (throws if not initialized)\n */\nexport const getEmbedder = (): FeatureExtractionPipeline => {\n  if (isHttpMode()) {\n    throw new Error(\n      'getEmbedder() is not available in HTTP embedding mode. Use embedText()/embedBatch() instead.',\n    );\n  }\n  if (!embedderInstance) {\n    throw new Error('Embedder not initialized. Call initEmbedder() first.');\n  }\n  return embedderInstance;\n};\n\n/**\n * Embed a single text string\n *\n * @param text - Text to embed\n * @returns Float32Array of embedding vector\n */\nexport const embedText = async (\n  text: string,\n  options: EmbeddingRequestOptions = {},\n): Promise<Float32Array> => {\n  options.signal?.throwIfAborted();\n  if (isHttpMode()) {\n    const [vec] = await httpEmbed([text], options);\n    return vec;","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/embeddings/embedder.ts#L276-L312","documentation":"Thrown by getEmbedder() when not in HTTP mode and embedderInstance is still null — i.e. initEmbedder() has not completed (or was never called, or failed and reset the singleton). The local pipeline is a lazily-loaded singleton; any embedText()/embedBatch() call in local mode routes through getEmbedder(), so this surfaces whenever a local-mode embed is attempted before initialization. isEmbedderReady() is the presence probe that returns false instead of throwing.","triggerScenarios":"Calling embedText()/embedBatch() in local mode before the embedding pipeline finished loading; calling getEmbedder() after a failed init (the catch block at line 253 resets embedderInstance to null); a semantic search query before runEmbeddingPipeline ran; an MCP query path that skipped the analyze-side init.","commonSituations":"Running `gitnexus serve` and issuing a semantic query before `analyze --embeddings` has populated the index; a failed model download (error 105/106) leaving the singleton null; concurrent init where one failed and reset state.","solutions":["Call await initEmbedder() once before using embedText()/embedBatch() in local mode.","Guard with isEmbedderReady() before attempting local embedding and surface a clear message if not ready.","Run `gitnexus analyze --embeddings` to populate the index before querying.","If you want zero local init, switch to HTTP mode (GITNEXUS_EMBEDDING_URL) so embedText() never touches the local singleton."],"exampleFix":"// before\nconst vec = await embedText(query); // throws if not initialized\n// after\nif (!isEmbedderReady()) {\n  throw new Error('Run `gitnexus analyze --embeddings` first.');\n}\nconst vec = await embedText(query);","handlingStrategy":"validation","validationCode":"import { isEmbedderReady } from 'gitnexus/src/core/embeddings/embedder.js';\n// Check readiness before embedding in local mode.\nif (!isEmbedderReady()) {\n  throw new Error('Embedder not ready. Run `gitnexus analyze --embeddings` or set HTTP mode env vars.');\n}\nconst vec = await embedText(text);","typeGuard":"import { isEmbedderReady } from 'gitnexus/src/core/embeddings/embedder.js';\nconst embedderAvailable = (): boolean => isEmbedderReady();","tryCatchPattern":null,"preventionTips":["Call await initEmbedder() once before local embedding, or run `analyze --embeddings` first.","Guard query paths with isEmbedderReady() and surface a clear message.","Use HTTP mode (GITNEXUS_EMBEDDING_URL+MODEL) to avoid the local lifecycle entirely."],"tags":["embeddings","lifecycle","singleton","api-misuse"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}