Summary
cosineSimilarityMatrix (typescript/src/internals/helpers/math.ts) has a column-count guard that can never fire, because it compares matrixA[0] to itself:
if ((matrixA[0]?.length ?? 0) !== (matrixA[0]?.length ?? 0)) {
throw new ValueError("Matrices must have the same number of columns.");
}
The error message shows the intent is to compare A vs B, so the second operand should be matrixB[0].
Impact
Matrices with differing column counts bypass validation. For an empty matrixB the function returns [[]] instead of raising; for other mismatches it eventually throws the less-specific inner "Vectors must have equal length" error, and the intended guard message is unreachable.
Fix
if ((matrixA[0]?.length ?? 0) !== (matrixB[0]?.length ?? 0)) {
PR to follow.
Summary
cosineSimilarityMatrix(typescript/src/internals/helpers/math.ts) has a column-count guard that can never fire, because it comparesmatrixA[0]to itself:The error message shows the intent is to compare A vs B, so the second operand should be
matrixB[0].Impact
Matrices with differing column counts bypass validation. For an empty
matrixBthe function returns[[]]instead of raising; for other mismatches it eventually throws the less-specific inner "Vectors must have equal length" error, and the intended guard message is unreachable.Fix
PR to follow.