ruvnet/ruflo · error

Embedding dimensions must match

Error message

Embedding dimensions must match

What it means

cosineSimilarity() received two embedding vectors of different lengths. The dot product and norms are only meaningful for aligned dimensions, so the mismatch is rejected up front — usually embeddings from two different models or a truncated vector.

Source

Thrown at v3/@claude-flow/embeddings/src/embedding-service.ts:1094

    return result.embedding;
  } finally {
    await service.shutdown();
  }
}

// ============================================================================
// Similarity Functions
// ============================================================================

/**
 * Compute cosine similarity between two embeddings
 */
export function cosineSimilarity(
  a: Float32Array | number[],
  b: Float32Array | number[]
): number {
  if (a.length !== b.length) {
    throw new Error('Embedding dimensions must match');
  }

  let dot = 0;
  let normA = 0;
  let normB = 0;

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

  const denom = Math.sqrt(normA) * Math.sqrt(normB);
  return denom > 0 ? dot / denom : 0;
}

/**
 * Compute Euclidean distance between two embeddings

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Embed all compared texts with the same model and provider so dimensions match.
  2. Do not mix vectors from caches built with different models; clear the cache after switching models.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at v3/@claude-flow/embeddings/src/embedding-service.ts:1094 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/26a928f205bb6287. Report an issue: GitHub.