abhigyanpatwari/GitNexus · error · Error

Embedder not initialized. Call initEmbedder() first.

Error message

Embedder not initialized. Call initEmbedder() first.

What it means

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.

Source

Thrown at gitnexus/src/core/embeddings/embedder.ts:294

 */
export const getEmbeddingDimensions = (): number => {
  if (isHttpMode()) {
    return getHttpDimensions() ?? DEFAULT_EMBEDDING_CONFIG.dimensions;
  }
  return DEFAULT_EMBEDDING_CONFIG.dimensions;
};

/**
 * Get the embedder instance (throws if not initialized)
 */
export const getEmbedder = (): FeatureExtractionPipeline => {
  if (isHttpMode()) {
    throw new Error(
      'getEmbedder() is not available in HTTP embedding mode. Use embedText()/embedBatch() instead.',
    );
  }
  if (!embedderInstance) {
    throw new Error('Embedder not initialized. Call initEmbedder() first.');
  }
  return embedderInstance;
};

/**
 * Embed a single text string
 *
 * @param text - Text to embed
 * @returns Float32Array of embedding vector
 */
export const embedText = async (
  text: string,
  options: EmbeddingRequestOptions = {},
): Promise<Float32Array> => {
  options.signal?.throwIfAborted();
  if (isHttpMode()) {
    const [vec] = await httpEmbed([text], options);
    return vec;

View on GitHub (pinned to d540b00184)

Solutions

  1. Call await initEmbedder() once before using embedText()/embedBatch() in local mode.
  2. Guard with isEmbedderReady() before attempting local embedding and surface a clear message if not ready.
  3. Run `gitnexus analyze --embeddings` to populate the index before querying.
  4. If you want zero local init, switch to HTTP mode (GITNEXUS_EMBEDDING_URL) so embedText() never touches the local singleton.

Example fix

// before
const vec = await embedText(query); // throws if not initialized
// after
if (!isEmbedderReady()) {
  throw new Error('Run `gitnexus analyze --embeddings` first.');
}
const vec = await embedText(query);
Defensive patterns

Strategy: validation

Validate before calling

import { isEmbedderReady } from 'gitnexus/src/core/embeddings/embedder.js';
// Check readiness before embedding in local mode.
if (!isEmbedderReady()) {
  throw new Error('Embedder not ready. Run `gitnexus analyze --embeddings` or set HTTP mode env vars.');
}
const vec = await embedText(text);

Type guard

import { isEmbedderReady } from 'gitnexus/src/core/embeddings/embedder.js';
const embedderAvailable = (): boolean => isEmbedderReady();

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/bd2d1d8e24023ca5. Report an issue: GitHub.