ruvnet/ruflo · error

Expected embedding dimension ${INPUT_DIM}, got ${input.lengt

Error message

Expected embedding dimension ${INPUT_DIM}, got ${input.length}

What it means

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.

Source

Thrown at v3/@claude-flow/neural/src/moe-router.ts:381

    await this.loadWeights();
  }

  /**
   * Route task to top-k experts based on embedding
   *
   * @param taskEmbedding - 384-dim task embedding from ONNX
   * @returns Routing result with selected experts and weights
   */
  route(taskEmbedding: Float32Array | number[]): RoutingResult {
    // Convert to Float32Array if needed
    const input =
      taskEmbedding instanceof Float32Array
        ? taskEmbedding
        : new Float32Array(taskEmbedding);

    // Validate input dimension
    if (input.length !== INPUT_DIM) {
      throw new Error(
        `Expected embedding dimension ${INPUT_DIM}, got ${input.length}`
      );
    }

    // Forward pass through gating network
    // Layer 1: Linear + ReLU
    matmul(this.W1, input, HIDDEN_DIM, INPUT_DIM, this.hidden);
    addBias(this.hidden, this.b1, this.hiddenWithBias);
    relu(this.hiddenWithBias, this.hiddenActivated);

    // Layer 2: Linear
    matmul(this.W2, this.hiddenActivated, NUM_EXPERTS, HIDDEN_DIM, this.logits);
    addBias(this.logits, this.b2, this.logitsWithBias);

    // Add noise for exploration if enabled
    if (this.config.enableNoise) {
      addNoise(this.logitsWithBias, this.config.noiseStd, this.noisyLogits);
    } else {

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Use a 384-dim embedding model (e.g. all-MiniLM-L6-v2) to embed task descriptions
  2. Pad or truncate embeddings to 384 (or project them) before calling route()
  3. Import INPUT_DIM from @claude-flow/neural and assert embeddings against it instead of hardcoding 384

Example fix

// before
router.route(embedding768); // throws: expected 384

// after
import { INPUT_DIM } from '@claude-flow/neural';
const input = new Float32Array(INPUT_DIM);
input.set(embedding768.subarray(0, INPUT_DIM)); // truncate (or re-embed with a 384-dim model)
router.route(input);
Defensive patterns

Strategy: validation

Validate before calling

import { INPUT_DIM } from '@claude-flow/neural';
const embedding = await embed(taskDescription); // 384-dim ONNX encoder
if (embedding.length !== INPUT_DIM) {
  throw new Error(`Embedding dim ${embedding.length} != ${INPUT_DIM} - wrong embedding model`);
}
const routing = router.route(embedding);

Type guard

import { INPUT_DIM } from '@claude-flow/neural';
function isRouterEmbedding(v: Float32Array | number[]): v is Float32Array & { length: typeof INPUT_DIM } {
  return v.length === INPUT_DIM;
}

Prevention

When it happens

Trigger: 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.

Common situations: Swapping the embedding model without re-exporting 384-dim features; mixing pipeline stages from different package versions; tests with random-length vectors.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/e9aea8d175167d0a. Report an issue: GitHub.