mastra-ai/mastra · error · Error
Config file not found at ${configPath}
Error message
Config file not found at ${configPath} What it means
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.
Source
Thrown at packages/fastembed/src/fastembed.ts:156
typeof token === 'object' &&
token !== null &&
'content' in token &&
'single_word' in token &&
'rstrip' in token &&
'lstrip' in token &&
'normalized' in token
);
}
function loadTokenizerFromDir(modelDir: PathLike, maxLength: number): Tokenizer {
const tokenizerPath = path.join(modelDir.toString(), 'tokenizer.json');
if (!fs.existsSync(tokenizerPath)) {
throw new Error(`Tokenizer file not found at ${tokenizerPath}`);
}
const configPath = path.join(modelDir.toString(), 'config.json');
if (!fs.existsSync(configPath)) {
throw new Error(`Config file not found at ${configPath}`);
}
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
const tokenizerFilePath = path.join(modelDir.toString(), 'tokenizer_config.json');
if (!fs.existsSync(tokenizerFilePath)) {
throw new Error(`Tokenizer config file not found at ${tokenizerFilePath}`);
}
const tokenizerConfig = JSON.parse(fs.readFileSync(tokenizerFilePath, 'utf-8'));
maxLength = Math.min(maxLength, tokenizerConfig['model_max_length']);
const tokensMapPath = path.join(modelDir.toString(), 'special_tokens_map.json');
if (!fs.existsSync(tokensMapPath)) {
throw new Error(`Tokens map file not found at ${tokensMapPath}`);
}
const tokensMap = JSON.parse(fs.readFileSync(tokensMapPath, 'utf-8'));
const tokenizer = Tokenizer.fromFile(tokenizerPath);
View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
$ cp my-model/model.onnx ./deploy-model/ # only weights copied
// after
$ cp my-model/{model.onnx,config.json,tokenizer.json,tokenizer_config.json,special_tokens_map.json} ./deploy-model/ Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
if (!fs.existsSync(path.join(dir, 'config.json'))) {
throw new Error(`${dir} missing config.json; copy it from the model repo root`);
} Try / catch
try {
const embedder = await FlagEmbedding.init(opts);
} catch (err) {
if (err instanceof Error && err.message.includes('Config file not found')) {
// restore config.json into the model dir, then retry once
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Tokenizer file not found at ${tokenizerPath}
- Model file not found at ${modelPath}
- Tokenizer config file not found at ${tokenizerFilePath}
- Tokens map file not found at ${tokensMapPath}
- Snapshot file not found: ${snapshotPath} Run with { updateSn
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/016df0133d613014.
Report an issue: GitHub.