{"record":{"id":"1293d2b6ea2216c0","repo":"mastra-ai/mastra","slug":"model-file-not-found-at-modelpath","errorCode":null,"errorMessage":"Model file not found at ${modelPath}","messagePattern":"Model file not found at (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/fastembed/src/fastembed.ts","lineNumber":239,"sourceCode":"      }\n      if (!modelName) {\n        throw new Error('For custom model, modelName is required in FlagEmbedding.init');\n      }\n    }\n\n    const modelDir =\n      model === EmbeddingModel.CUSTOM\n        ? modelAbsoluteDirPath\n        : await FlagEmbedding.retrieveModel(model, cacheDir, showDownloadProgress);\n\n    const tokenizer = loadTokenizerFromDir(modelDir, maxLength);\n    const defaultModelName =\n      model === EmbeddingModel.MLE5Large || model === EmbeddingModel.AllMiniLML6V2\n        ? 'model.onnx'\n        : 'model_optimized.onnx';\n    const modelPath = path.join(modelDir.toString(), modelName || defaultModelName);\n    if (!fs.existsSync(modelPath)) {\n      throw new Error(`Model file not found at ${modelPath}`);\n    }\n    const session = await ort.InferenceSession.create(modelPath, {\n      executionProviders,\n      graphOptimizationLevel: 'all',\n    });\n    return new FlagEmbedding(tokenizer, session, model);\n  }\n\n  private static async downloadFileFromGCS(\n    outputFilePath: PathLike,\n    model: string,\n    showDownloadProgress: boolean = true,\n  ): Promise<PathLike> {\n    if (fs.existsSync(outputFilePath)) {\n      return outputFilePath;\n    }\n\n    // The AllMiniLML6V2 model URL doesn't follow the same naming convention as the other models","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/fastembed/src/fastembed.ts#L221-L257","documentation":"After resolving modelDir and the ONNX filename (explicit modelName or a default like model.onnx / model_optimized.onnx), init checks fs.existsSync on the joined path before creating the onnxruntime InferenceSession. If the file is missing it throws with the full resolved path. This catches bad paths, wrong filenames, and incomplete downloads before ORT fails with a less clear error.","triggerScenarios":"FlagEmbedding.init where <modelDir>/<modelName> does not exist — CUSTOM model with a modelName that doesn't match the actual file, a built-in model whose cached download is incomplete, or a platform-specific default name (model.onnx vs model_optimized.onnx) not present in a custom dir.","commonSituations":"Typoed modelName ('model.onx'); pointing modelAbsoluteDirPath at the parent of the model folder; cache wiped between runs by ephemeral CI filesystems; copying the ONNX file under a different name than passed.","solutions":["Verify the exact file exists: ls <modelDir> and make modelName match (including extension).","For CUSTOM, ensure the .onnx file was actually copied into modelAbsoluteDirPath alongside the tokenizer files.","For built-in models, clear the corrupted cache directory and re-init with showDownloadProgress: true to re-download.","In ephemeral CI, cache the model directory between jobs or download it in a setup step."],"exampleFix":"// before\nawait FlagEmbedding.init({ model: EmbeddingModel.CUSTOM, modelAbsoluteDirPath: '/models/mine', modelName: 'model.onx' });\n// after\nawait FlagEmbedding.init({ model: EmbeddingModel.CUSTOM, modelAbsoluteDirPath: '/models/mine', modelName: 'model.onnx' }); // matches file on disk","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst modelPath = path.join(modelAbsoluteDirPath, modelName);\nif (!fs.existsSync(modelPath)) {\n  throw new Error(`ONNX weights missing at ${modelPath}; re-download or fix modelName`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const embedder = await FlagEmbedding.init(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Model file not found')) {\n    // trigger model download / fix path, then retry once\n  } else throw err;\n}","preventionTips":["Preflight fs.existsSync on the resolved ONNX path before init.","Persist model caches between CI runs to avoid ephemeral wipes.","Match modelName exactly to the file on disk (watch .onnx vs .onnx-data and typos)."],"tags":["filesystem","missing-file","onnx","model-loading","embeddings"],"backgroundTag":"file-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}