{"record":{"id":"016df0133d613014","repo":"mastra-ai/mastra","slug":"config-file-not-found-at-configpath","errorCode":null,"errorMessage":"Config file not found at ${configPath}","messagePattern":"Config file not found at (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/fastembed/src/fastembed.ts","lineNumber":156,"sourceCode":"    typeof token === 'object' &&\n    token !== null &&\n    'content' in token &&\n    'single_word' in token &&\n    'rstrip' in token &&\n    'lstrip' in token &&\n    'normalized' in token\n  );\n}\n\nfunction loadTokenizerFromDir(modelDir: PathLike, maxLength: number): Tokenizer {\n  const tokenizerPath = path.join(modelDir.toString(), 'tokenizer.json');\n  if (!fs.existsSync(tokenizerPath)) {\n    throw new Error(`Tokenizer file not found at ${tokenizerPath}`);\n  }\n\n  const configPath = path.join(modelDir.toString(), 'config.json');\n  if (!fs.existsSync(configPath)) {\n    throw new Error(`Config file not found at ${configPath}`);\n  }\n  const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));\n\n  const tokenizerFilePath = path.join(modelDir.toString(), 'tokenizer_config.json');\n  if (!fs.existsSync(tokenizerFilePath)) {\n    throw new Error(`Tokenizer config file not found at ${tokenizerFilePath}`);\n  }\n  const tokenizerConfig = JSON.parse(fs.readFileSync(tokenizerFilePath, 'utf-8'));\n  maxLength = Math.min(maxLength, tokenizerConfig['model_max_length']);\n\n  const tokensMapPath = path.join(modelDir.toString(), 'special_tokens_map.json');\n  if (!fs.existsSync(tokensMapPath)) {\n    throw new Error(`Tokens map file not found at ${tokensMapPath}`);\n  }\n  const tokensMap = JSON.parse(fs.readFileSync(tokensMapPath, 'utf-8'));\n\n  const tokenizer = Tokenizer.fromFile(tokenizerPath);\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/fastembed/src/fastembed.ts#L138-L174","documentation":"After tokenizer.json is found, loadTokenizerFromDir reads config.json to obtain model metadata (e.g. model type/dimensions). If <modelDir>/config.json does not exist on disk, the loader throws with the resolved path. The model directory is incomplete even though tokenizer.json was present.","triggerScenarios":"FlagEmbedding.init with a modelDir that has tokenizer.json but no config.json — typically a hand-assembled custom model directory, a custom HF checkpoint exported without config, or a manually pruned cache.","commonSituations":"Copying only tokenizer + ONNX weights when preparing a CUSTOM model; a download that fetched tokenizer.json but failed before config.json; minifying a model directory and deleting files deemed unused.","solutions":["Copy config.json from the source Hugging Face model repo into the model directory.","If the download was interrupted, clear the model cache and re-initialize to re-download everything.","For CUSTOM models, verify the full file set exists (config.json, tokenizer.json, tokenizer_config.json, special_tokens_map.json, model .onnx) before calling init."],"exampleFix":"// before\n$ cp my-model/model.onnx ./deploy-model/  # only weights copied\n// after\n$ cp my-model/{model.onnx,config.json,tokenizer.json,tokenizer_config.json,special_tokens_map.json} ./deploy-model/","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nif (!fs.existsSync(path.join(dir, 'config.json'))) {\n  throw new Error(`${dir} missing config.json; copy it from the model repo root`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const embedder = await FlagEmbedding.init(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Config file not found')) {\n    // restore config.json into the model dir, then retry once\n  } else throw err;\n}","preventionTips":["Copy the complete file set (tokenizer.json, config.json, tokenizer_config.json, special_tokens_map.json, *.onnx) when preparing custom model dirs.","Add a preflight directory completeness check in deployment scripts.","Avoid pruning 'unused' JSON files from model directories."],"tags":["filesystem","missing-file","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"}