{"record":{"id":"7aa4180d35d94a4a","repo":"mastra-ai/mastra","slug":"for-custom-model-modelabsolutedirpath-is-required-7aa418","errorCode":null,"errorMessage":"For custom model, modelAbsoluteDirPath is required in SparseTextEmbedding.init","messagePattern":"For custom model, modelAbsoluteDirPath is required in SparseTextEmbedding\\.init","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/fastembed/src/fastembed.ts","lineNumber":451,"sourceCode":"    private session: ort.InferenceSession,\n  ) {\n    super();\n  }\n\n  static async init(options: InitSparseStandardOptions): Promise<SparseTextEmbedding>;\n  static async init(options: InitSparseCustomOptions): Promise<SparseTextEmbedding>;\n  static async init({\n    model = SparseEmbeddingModel.SpladePPEnV1,\n    executionProviders = [ExecutionProvider.CPU],\n    maxLength = 512,\n    cacheDir = 'local_cache',\n    showDownloadProgress = true,\n    modelAbsoluteDirPath = '',\n    modelName = '',\n  }: Partial<InitSparseOptions> = {}) {\n    if (model === SparseEmbeddingModel.CUSTOM) {\n      if (!modelAbsoluteDirPath) {\n        throw new Error('For custom model, modelAbsoluteDirPath is required in SparseTextEmbedding.init');\n      }\n      if (!modelName) {\n        throw new Error('For custom model, modelName is required in SparseTextEmbedding.init');\n      }\n    }\n\n    const modelDir =\n      model === SparseEmbeddingModel.CUSTOM\n        ? modelAbsoluteDirPath\n        : await SparseTextEmbedding.retrieveModel(model, cacheDir, showDownloadProgress);\n\n    const { tokenizer } = this.loadTokenizer(modelDir, maxLength);\n\n    const defaultModelName = 'model.onnx';\n    const modelPath = path.join(modelDir.toString(), 'onnx', modelName || defaultModelName);\n\n    if (!fs.existsSync(modelPath)) {\n      throw new Error(`Model file not found at ${modelPath}`);","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/fastembed/src/fastembed.ts#L433-L469","documentation":"SparseTextEmbedding.init() throws this when model is SparseEmbeddingModel.CUSTOM but no modelAbsoluteDirPath option was provided. Custom models are loaded from a local directory, so the library cannot proceed without it.","triggerScenarios":"Calling SparseTextEmbedding.init({ model: SparseEmbeddingModel.CUSTOM }) with modelAbsoluteDirPath omitted, empty string, or undefined.","commonSituations":"Developer forgets that CUSTOM is a special case requiring local paths; options object built dynamically and the path key dropped; empty-string default ('') from destructuring counts as missing.","solutions":["Pass modelAbsoluteDirPath pointing to the directory containing the ONNX model and tokenizer files.","Verify the options object actually includes modelAbsoluteDirPath and that it is not an empty string.","If you meant a built-in model, use a non-CUSTOM SparseEmbeddingModel value instead."],"exampleFix":"// before\nawait SparseTextEmbedding.init({ model: SparseEmbeddingModel.CUSTOM });\n// after\nawait SparseTextEmbedding.init({\n  model: SparseEmbeddingModel.CUSTOM,\n  modelAbsoluteDirPath: '/models/my-sparse-onnx',\n  modelName: 'model.onnx',\n});","handlingStrategy":"validation","validationCode":"function assertSparseInitOptions(opts) {\n  if (opts.model === SparseEmbeddingModel.CUSTOM && !opts.modelAbsoluteDirPath) {\n    throw new Error('modelAbsoluteDirPath is required for SparseEmbeddingModel.CUSTOM');\n  }\n}","typeGuard":"function hasCustomDir(opts) {\n  return typeof opts.modelAbsoluteDirPath === 'string' && opts.modelAbsoluteDirPath.length > 0;\n}","tryCatchPattern":"try {\n  await SparseTextEmbedding.init(opts);\n} catch (e) {\n  if (e.message.includes('modelAbsoluteDirPath is required')) {\n    console.error('Provide modelAbsoluteDirPath when model is CUSTOM');\n  }\n  throw e;\n}","preventionTips":["Use TypeScript with the full InitSparseOptions type and avoid Partial defaults silently emptying strings.","Centralize custom-model init in one factory function that validates options.","Document that CUSTOM differs from built-in models and always requires a local dir."],"tags":["validation","configuration","fastembed"],"backgroundTag":"missing-required-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}