{"record":{"id":"6bad31a9505900db","repo":"diegosouzapw/OmniRoute","slug":"unexpected-safetensors-shape-json-stringify-sha","errorCode":null,"errorMessage":"Unexpected safetensors shape: ${JSON.stringify(shape)}","messagePattern":"Unexpected safetensors shape: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/memory/embedding/staticPotion.ts","lineNumber":123,"sourceCode":"  const modelPath = path.join(modelDir, \"model.safetensors\");\n  const tokenizerPath = path.join(modelDir, \"tokenizer.json\");\n\n  await Promise.all([\n    ensureFile(vocabPath, `${hfBase}/vocab.json`),\n    ensureFile(modelPath, `${hfBase}/model.safetensors`),\n    ensureFile(tokenizerPath, `${hfBase}/tokenizer.json`),\n  ]);\n\n  // Load vocab\n  const vocabRaw = await fs.readFile(vocabPath, \"utf8\");\n  const vocab = JSON.parse(vocabRaw) as Record<string, number>;\n\n  // Load matrix from safetensors\n  const modelBuf = await fs.readFile(modelPath);\n  const { matrix, shape } = parseSafetensors(modelBuf);\n\n  if (shape.length < 2) {\n    throw new Error(`Unexpected safetensors shape: ${JSON.stringify(shape)}`);\n  }\n  const vocabSize = shape[0];\n  const dim = shape[1];\n\n  const unkIdx = vocab[\"[UNK]\"] ?? 0;\n\n  return { vocab, matrix, dim, vocabSize, unkIdx };\n}\n\nexport function getOrLoadModel(): Promise<PotionModel> {\n  if (_model) return Promise.resolve(_model);\n  if (_loading) return _loading;\n  _loading = loadModel().then((m) => {\n    _model = m;\n    _loading = null;\n    return m;\n  });\n  return _loading;","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/memory/embedding/staticPotion.ts#L105-L141","documentation":"Error \"Unexpected safetensors shape: ${JSON.stringify(shape)}\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/memory/embedding/staticPotion.ts:123 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}