ruvnet/ruflo · error

Vector length mismatch: ${a.length} vs ${b.length}

Error message

Vector length mismatch: ${a.length} vs ${b.length}

What it means

cosineSimilarity() received vectors a and b of different lengths; the mismatched lengths are embedded in the message. Dot product and norms require aligned dimensions — typically vectors from different embedding models or a truncated input.

Source

Thrown at v3/plugins/prime-radiant/src/tools/types.ts:395

        error,
        metrics: {
          operationName,
          startTime,
          endTime,
          duration: endTime - startTime,
          success: false,
          error: error instanceof Error ? error.message : String(error),
        },
      };
    });
}

/**
 * Calculate cosine similarity between two vectors
 */
export function cosineSimilarity(a: number[] | Float32Array, b: number[] | Float32Array): number {
  if (a.length !== b.length) {
    throw new Error(`Vector length mismatch: ${a.length} vs ${b.length}`);
  }

  let dotProduct = 0;
  let normA = 0;
  let normB = 0;

  for (let i = 0; i < a.length; i++) {
    dotProduct += a[i] * b[i];
    normA += a[i] * a[i];
    normB += b[i] * b[i];
  }

  const denominator = Math.sqrt(normA) * Math.sqrt(normB);
  if (denominator === 0) return 0;

  return dotProduct / denominator;
}

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Ensure both inputs have identical lengths before the operation; pad or truncate as appropriate for the domain.
  2. Validate lengths at the call site and fail fast with both lengths in the message.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at v3/plugins/prime-radiant/src/tools/types.ts:395 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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