janhq/jan · error · Error

Failed to determine embedding context size: ${e instanceof E

Error message

Failed to determine embedding context size: ${e instanceof Error ? e.message : String(e)}

What it means

Thrown by VectorDBExtension.probeEmbeddingContextSize() when llm.getEmbeddingContextSize() rejects. The doc comment is explicit: a rejected probe means the embedding engine is unhealthy (e.g. model failed to load), and skipping verification would let oversized chunks through and later surface as a confusing HTTP 400 exceed_context_size_error. So the real cause is re-thrown wrapped in this message.

Source

Thrown at extensions/vector-db-extension/src/index.ts:211

    for (const chunk of chunks) {
      out.push(...(await this.splitChunkToFit(chunk, budget, llm)))
    }
    return out
  }

  /**
   * A rejected probe/count means the embedding engine is unhealthy (e.g. the
   * embedding model failed to load). Skipping verification here would let
   * oversized chunks through and surface later as a confusing HTTP 400
   * (exceed_context_size_error), so fail ingestion with the real cause.
   */
  private async probeEmbeddingContextSize(llm: {
    getEmbeddingContextSize?: () => Promise<number | undefined>
  }): Promise<number | undefined> {
    try {
      return await llm.getEmbeddingContextSize!()
    } catch (e) {
      throw new Error(
        `Failed to determine embedding context size: ${e instanceof Error ? e.message : String(e)}`
      )
    }
  }

  private async splitChunkToFit(
    text: string,
    budget: number,
    llm: { countEmbeddingTokens: (texts: string[]) => Promise<number[]> }
  ): Promise<string[]> {
    if (!text) return []
    let count: number
    try {
      ;[count] = await llm.countEmbeddingTokens([text])
    } catch (e) {
      throw new Error(
        `Failed to count embedding tokens: ${e instanceof Error ? e.message : String(e)}`
      )

View on GitHub (pinned to fad3f12a14)

Solutions

  1. Ensure the embedding model is loaded and healthy before ingesting documents.
  2. Restart the llamacpp extension / reload the embedding model.
  3. Retry ingestion after confirming getEmbeddingContextSize() resolves.
  4. If the model genuinely lacks the method, update llamacpp-extension so the probe is skipped (the caller no-ops when the method is absent).

Example fix

// before
await vecdbExt.ingestFileForProject(projectId, file, opts)

// after
const llm = (window.core?.extensionManager.getByName('@janhq/llamacpp-extension') as any)
try {
  await llm?.getEmbeddingContextSize?.()
} catch (e) {
  throw new Error('Embedding engine unhealthy; reload the embedding model before ingesting')
}
await vecdbExt.ingestFileForProject(projectId, file, opts)
Defensive patterns

Strategy: try-catch

Validate before calling

const llm = (window.core?.extensionManager.getByName('@janhq/llamacpp-extension') as any)
const ready = typeof llm?.getEmbeddingContextSize === 'function'
  ? await llm.getEmbeddingContextSize().then(() => true).catch(() => false)
  : true // method absent => probe is skipped by the caller anyway
if (!ready) {
  // embedding engine unhealthy; reload before ingesting
}

Try / catch

try {
  await vecdbExt.ingestFileForProject(projectId, file, opts)
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Failed to determine embedding context size')) {
    await reloadEmbeddingModel()
  }
  throw e
}

Prevention

When it happens

Trigger: Chunking path calls clampToEmbeddingContext or ensureChunksFitEmbeddingContext; getEmbeddingContextSize() rejects because the embedding model is not loaded, the llamacpp server is down, or the method itself errored.

Common situations: Ingestion attempted before the embedding model finished loading; llamacpp extension in a bad state; embedding model path invalid so context-size query fails.

Related errors


AI-assisted analysis of janhq/jan@fad3f12a14 (2026-08-12). Data as JSON: /api/errors/e43650a792215db1. Report an issue: GitHub.