{"record":{"id":"e43650a792215db1","repo":"janhq/jan","slug":"failed-to-determine-embedding-context-size-e-in","errorCode":null,"errorMessage":"Failed to determine embedding context size: ${e instanceof Error ? e.message : String(e)}","messagePattern":"Failed to determine embedding context size: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extensions/vector-db-extension/src/index.ts","lineNumber":211,"sourceCode":"    for (const chunk of chunks) {\n      out.push(...(await this.splitChunkToFit(chunk, budget, llm)))\n    }\n    return out\n  }\n\n  /**\n   * A rejected probe/count means the embedding engine is unhealthy (e.g. the\n   * embedding model failed to load). Skipping verification here would let\n   * oversized chunks through and surface later as a confusing HTTP 400\n   * (exceed_context_size_error), so fail ingestion with the real cause.\n   */\n  private async probeEmbeddingContextSize(llm: {\n    getEmbeddingContextSize?: () => Promise<number | undefined>\n  }): Promise<number | undefined> {\n    try {\n      return await llm.getEmbeddingContextSize!()\n    } catch (e) {\n      throw new Error(\n        `Failed to determine embedding context size: ${e instanceof Error ? e.message : String(e)}`\n      )\n    }\n  }\n\n  private async splitChunkToFit(\n    text: string,\n    budget: number,\n    llm: { countEmbeddingTokens: (texts: string[]) => Promise<number[]> }\n  ): Promise<string[]> {\n    if (!text) return []\n    let count: number\n    try {\n      ;[count] = await llm.countEmbeddingTokens([text])\n    } catch (e) {\n      throw new Error(\n        `Failed to count embedding tokens: ${e instanceof Error ? e.message : String(e)}`\n      )","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/extensions/vector-db-extension/src/index.ts#L193-L229","documentation":"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.","triggerScenarios":"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.","commonSituations":"Ingestion attempted before the embedding model finished loading; llamacpp extension in a bad state; embedding model path invalid so context-size query fails.","solutions":["Ensure the embedding model is loaded and healthy before ingesting documents.","Restart the llamacpp extension / reload the embedding model.","Retry ingestion after confirming getEmbeddingContextSize() resolves.","If the model genuinely lacks the method, update llamacpp-extension so the probe is skipped (the caller no-ops when the method is absent)."],"exampleFix":"// before\nawait vecdbExt.ingestFileForProject(projectId, file, opts)\n\n// after\nconst llm = (window.core?.extensionManager.getByName('@janhq/llamacpp-extension') as any)\ntry {\n  await llm?.getEmbeddingContextSize?.()\n} catch (e) {\n  throw new Error('Embedding engine unhealthy; reload the embedding model before ingesting')\n}\nawait vecdbExt.ingestFileForProject(projectId, file, opts)","handlingStrategy":"try-catch","validationCode":"const llm = (window.core?.extensionManager.getByName('@janhq/llamacpp-extension') as any)\nconst ready = typeof llm?.getEmbeddingContextSize === 'function'\n  ? await llm.getEmbeddingContextSize().then(() => true).catch(() => false)\n  : true // method absent => probe is skipped by the caller anyway\nif (!ready) {\n  // embedding engine unhealthy; reload before ingesting\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vecdbExt.ingestFileForProject(projectId, file, opts)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to determine embedding context size')) {\n    await reloadEmbeddingModel()\n  }\n  throw e\n}","preventionTips":["Confirm the embedding model is loaded and getEmbeddingContextSize resolves before ingestion.","Restart the llamacpp extension if the embedding model fails to load.","Run a health check before bulk document ingestion."],"tags":["vector-db","embeddings","context-size","llamacpp","chunking"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}