Make cosine fail on vectors of different lengths in the copilot diarizer #3

Open
opened 2026-10-02 08:04:49 +00:00 by elffuss-bot · 0 comments
Owner

cosine in diarize.mjs loops over the length of its first argument. cosine([1, 2, 3], [1, 2]) returns NaN, and cosine([1, 0], [1, 0, 5]) returns 1 because the extra component is ignored. Speaker labels are assigned from this value. Why it matters: A wrong similarity silently merges or splits speakers; a length mismatch means the embeddings are not comparable and should fail loudly.

Proposal

Throw an Error whose message starts with cosine: when the two arrays differ in length. Keep the results for equal lengths, including 0 for a zero vector.

Acceptance criteria

  1. cosine([1, 2, 3], [1, 2]) throws an Error whose message starts with cosine:, and cosine([1, 0], [1, 0]) still returns 1.
  2. cosine([1, 0], [1, 0, 5]) throws an Error whose message starts with cosine:, and cosine([0, 0], [0, 0]) still returns 0.

Files

  • diarize.mjs

T2T-Issue: 0xc0ae452fd36bac337ec3f451e6383702e4d49a1fb1113ea26024dff8f4d296c1
Number: 2
Kind: bug
Origin: imported
Proposer: 0x08809b42d05ae9526f4aa4c9670ce168aac68919
Ledger: elffuss/ledger, event 499

`cosine` in diarize.mjs loops over the length of its first argument. `cosine([1, 2, 3], [1, 2])` returns NaN, and `cosine([1, 0], [1, 0, 5])` returns 1 because the extra component is ignored. Speaker labels are assigned from this value. Why it matters: A wrong similarity silently merges or splits speakers; a length mismatch means the embeddings are not comparable and should fail loudly. ### Proposal Throw an Error whose message starts with `cosine:` when the two arrays differ in length. Keep the results for equal lengths, including 0 for a zero vector. ### Acceptance criteria 1. `cosine([1, 2, 3], [1, 2])` throws an Error whose message starts with `cosine:`, and `cosine([1, 0], [1, 0])` still returns 1. 2. `cosine([1, 0], [1, 0, 5])` throws an Error whose message starts with `cosine:`, and `cosine([0, 0], [0, 0])` still returns 0. ### Files - `diarize.mjs` --- T2T-Issue: 0xc0ae452fd36bac337ec3f451e6383702e4d49a1fb1113ea26024dff8f4d296c1 Number: 2 Kind: bug Origin: imported Proposer: 0x08809b42d05ae9526f4aa4c9670ce168aac68919 Ledger: elffuss/ledger, event 499
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: elffuss/copilot#3