{"record":{"id":"e9aea8d175167d0a","repo":"ruvnet/ruflo","slug":"expected-embedding-dimension-input-dim-got-i","errorCode":null,"errorMessage":"Expected embedding dimension ${INPUT_DIM}, got ${input.length}","messagePattern":"Expected embedding dimension (.+?), got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/neural/src/moe-router.ts","lineNumber":381,"sourceCode":"    await this.loadWeights();\n  }\n\n  /**\n   * Route task to top-k experts based on embedding\n   *\n   * @param taskEmbedding - 384-dim task embedding from ONNX\n   * @returns Routing result with selected experts and weights\n   */\n  route(taskEmbedding: Float32Array | number[]): RoutingResult {\n    // Convert to Float32Array if needed\n    const input =\n      taskEmbedding instanceof Float32Array\n        ? taskEmbedding\n        : new Float32Array(taskEmbedding);\n\n    // Validate input dimension\n    if (input.length !== INPUT_DIM) {\n      throw new Error(\n        `Expected embedding dimension ${INPUT_DIM}, got ${input.length}`\n      );\n    }\n\n    // Forward pass through gating network\n    // Layer 1: Linear + ReLU\n    matmul(this.W1, input, HIDDEN_DIM, INPUT_DIM, this.hidden);\n    addBias(this.hidden, this.b1, this.hiddenWithBias);\n    relu(this.hiddenWithBias, this.hiddenActivated);\n\n    // Layer 2: Linear\n    matmul(this.W2, this.hiddenActivated, NUM_EXPERTS, HIDDEN_DIM, this.logits);\n    addBias(this.logits, this.b2, this.logitsWithBias);\n\n    // Add noise for exploration if enabled\n    if (this.config.enableNoise) {\n      addNoise(this.logitsWithBias, this.config.noiseStd, this.noisyLogits);\n    } else {","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/neural/src/moe-router.ts#L363-L399","documentation":"MoERouter gates a task embedding through fixed weight matrices sized for INPUT_DIM = 384; route() validates input.length === 384 before the first matmul and reports the actual length otherwise. The router is hard-wired for the 384-dim embedding produced by the all-MiniLM-style ONNX encoder — it is not dimension-agnostic, and the constant is exported as INPUT_DIM for callers to check against.","triggerScenarios":"Feeding an embedding from a different model (e.g. 768-dim); passing a raw token vector, a truncated array, or text instead of an embedding; an ONNX session configured with a different model file; number[] to Float32Array conversion that drops or duplicates elements.","commonSituations":"Swapping the embedding model without re-exporting 384-dim features; mixing pipeline stages from different package versions; tests with random-length vectors.","solutions":["Use a 384-dim embedding model (e.g. all-MiniLM-L6-v2) to embed task descriptions","Pad or truncate embeddings to 384 (or project them) before calling route()","Import INPUT_DIM from @claude-flow/neural and assert embeddings against it instead of hardcoding 384"],"exampleFix":"// before\nrouter.route(embedding768); // throws: expected 384\n\n// after\nimport { INPUT_DIM } from '@claude-flow/neural';\nconst input = new Float32Array(INPUT_DIM);\ninput.set(embedding768.subarray(0, INPUT_DIM)); // truncate (or re-embed with a 384-dim model)\nrouter.route(input);","handlingStrategy":"validation","validationCode":"import { INPUT_DIM } from '@claude-flow/neural';\nconst embedding = await embed(taskDescription); // 384-dim ONNX encoder\nif (embedding.length !== INPUT_DIM) {\n  throw new Error(`Embedding dim ${embedding.length} != ${INPUT_DIM} - wrong embedding model`);\n}\nconst routing = router.route(embedding);","typeGuard":"import { INPUT_DIM } from '@claude-flow/neural';\nfunction isRouterEmbedding(v: Float32Array | number[]): v is Float32Array & { length: typeof INPUT_DIM } {\n  return v.length === INPUT_DIM;\n}","tryCatchPattern":null,"preventionTips":["Pin the embedding pipeline to a 384-dim model (e.g. all-MiniLM-L6-v2)","Assert against the exported INPUT_DIM constant, not a hardcoded 384","Re-verify dimensions after any ONNX model swap"],"tags":["neural","moe","embedding","input-shape"],"backgroundTag":"embedding-dimension-mismatch","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}