abhigyanpatwari/GitNexus · error · Error
initEmbedder() should not be called in HTTP mode. Use embedT
Error message
initEmbedder() should not be called in HTTP mode. Use embedText()/embedBatch() which handle HTTP transparently.
What it means
Thrown by initEmbedder() when isHttpMode() is true — i.e. both GITNEXUS_EMBEDDING_URL and GITNEXUS_EMBEDDING_MODEL are set. In HTTP mode the local ONNX Runtime pipeline is intentionally never loaded; embedText() and embedBatch() detect HTTP mode internally and dispatch to httpEmbed() transparently. Calling initEmbedder() would bypass that and try to load a native model, so it is rejected at the top of the function before any native import.
Source
Thrown at gitnexus/src/core/embeddings/embedder.ts:74
*/
export const getCurrentDevice = (): 'dml' | 'cuda' | 'cpu' | 'wasm' | null => currentDevice;
/**
* Initialize the embedding model
* Uses singleton pattern - only loads once, subsequent calls return cached instance
*
* @param onProgress - Optional callback for model download progress
* @param config - Optional configuration override
* @param forceDevice - Force a specific device
* @returns Promise resolving to the embedder pipeline
*/
export const initEmbedder = async (
onProgress?: ModelProgressCallback,
config: Partial<EmbeddingConfig> = {},
forceDevice?: 'dml' | 'cuda' | 'cpu' | 'wasm',
): Promise<FeatureExtractionPipeline> => {
if (isHttpMode()) {
throw new Error(
'initEmbedder() should not be called in HTTP mode. ' +
'Use embedText()/embedBatch() which handle HTTP transparently.',
);
}
// Fail fast on platforms where the bundled native ONNX Runtime binding is not
// shipped (macOS Intel, #1515). Must run before any transformers.js /
// onnxruntime-node import or resolution — otherwise the native module load
// crashes with a raw "Cannot find module ...onnxruntime_binding.node" that
// ONNX_WEB_BACKEND=wasm cannot rescue (#1516). HTTP mode was already handled
// above, so this only blocks the local-runtime path.
const runtimeBlocker = getLocalEmbeddingRuntimeBlocker();
if (runtimeBlocker) {
throw new Error(runtimeBlocker);
}
// Return existing instance if available
if (embedderInstance) {View on GitHub (pinned to d540b00184)
Solutions
- Replace initEmbedder() calls with embedText()/embedBatch() — they handle both HTTP and local modes.
- If you must branch, gate on isHttpMode() from http-client.js and skip init in HTTP mode.
- Run `gitnexus embeddings status` or check the two env vars to confirm which mode you are in.
Example fix
// before const pipe = await initEmbedder(); const vec = await embedText(text); // after — no init needed in either mode const vec = await embedText(text);
Defensive patterns
Strategy: type-guard
Validate before calling
import { isHttpMode } from 'gitnexus/src/core/embeddings/http-client.js';
// Never call initEmbedder() in HTTP mode.
if (!isHttpMode()) {
await initEmbedder(onProgress);
} Type guard
import { isHttpMode } from 'gitnexus/src/core/embeddings/http-client.js';
const shouldUseLocalPipeline = (): boolean => !isHttpMode(); Prevention
- Prefer embedText()/embedBatch() over initEmbedder()+getEmbedder() — they work in both modes.
- If you call initEmbedder(), gate it on !isHttpMode().
- Run `gitnexus embeddings status` to confirm which mode is active.
When it happens
Trigger: Any code path that calls initEmbedder() (or the MCP embedder entry point that mirrors it) while GITNEXUS_EMBEDDING_URL and GITNEXUS_EMBEDDING_MODEL are both exported. Typically a custom integration or a forked analyze flow that unconditionally initializes the local pipeline without checking isHttpMode() first.
Common situations: A user sets the two HTTP env vars to route embeddings through an OpenAI-compatible endpoint but has a wrapper script that still calls initEmbedder(); migrating from local to HTTP mode and forgetting to remove the init call; an MCP client that calls both init and embed.
Related errors
- getEmbedder() is not available in HTTP embedding mode. Use e
- Embedder not initialized. Call initEmbedder() first.
- ${name} must be a positive integer, got "${raw}"
- ${name} must be a positive integer <= ${max}, got "${raw}"
- ${name} must be a non-negative integer, got "${raw}"
AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12).
Data as JSON: /api/errors/c9857f502134cb6a.
Report an issue: GitHub.