{"record":{"id":"7d343f173854d140","repo":"ruvnet/ruflo","slug":"vector-length-mismatch-a-length-vs-b-length","errorCode":null,"errorMessage":"Vector length mismatch: ${a.length} vs ${b.length}","messagePattern":"Vector length mismatch: (.+?) vs (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/plugins/prime-radiant/src/tools/types.ts","lineNumber":395,"sourceCode":"        error,\n        metrics: {\n          operationName,\n          startTime,\n          endTime,\n          duration: endTime - startTime,\n          success: false,\n          error: error instanceof Error ? error.message : String(error),\n        },\n      };\n    });\n}\n\n/**\n * Calculate cosine similarity between two vectors\n */\nexport function cosineSimilarity(a: number[] | Float32Array, b: number[] | Float32Array): number {\n  if (a.length !== b.length) {\n    throw new Error(`Vector length mismatch: ${a.length} vs ${b.length}`);\n  }\n\n  let dotProduct = 0;\n  let normA = 0;\n  let normB = 0;\n\n  for (let i = 0; i < a.length; i++) {\n    dotProduct += a[i] * b[i];\n    normA += a[i] * a[i];\n    normB += b[i] * b[i];\n  }\n\n  const denominator = Math.sqrt(normA) * Math.sqrt(normB);\n  if (denominator === 0) return 0;\n\n  return dotProduct / denominator;\n}\n","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/plugins/prime-radiant/src/tools/types.ts#L377-L413","documentation":"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.","triggerScenarios":"Thrown at v3/plugins/prime-radiant/src/tools/types.ts:395 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure both inputs have identical lengths before the operation; pad or truncate as appropriate for the domain.","Validate lengths at the call site and fail fast with both lengths in the message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}