Make cosine reject vectors of different lengths in the copilot diarizer #1

Open
opened 2026-10-02 06:34:20 +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:.
  2. cosine([1, 0], [1, 0, 5]) throws an Error whose message starts with cosine:.
  3. cosine([1, 0], [1, 0]) returns 1.
  4. cosine([0, 0], [0, 0]) returns 0.

Files

  • diarize.mjs

T2T-Issue: 0x98062380597bea3942e80b35090b356d0ac3e0e54c88cbbf251faa36758056f4
Number: 1
Kind: bug
Origin: imported
Proposer: 0x08809b42d05ae9526f4aa4c9670ce168aac68919
Ledger: elffuss/ledger, event 164

`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:`. 2. `cosine([1, 0], [1, 0, 5])` throws an Error whose message starts with `cosine:`. 3. `cosine([1, 0], [1, 0])` returns 1. 4. `cosine([0, 0], [0, 0])` returns 0. ### Files - `diarize.mjs` --- T2T-Issue: 0x98062380597bea3942e80b35090b356d0ac3e0e54c88cbbf251faa36758056f4 Number: 1 Kind: bug Origin: imported Proposer: 0x08809b42d05ae9526f4aa4c9670ce168aac68919 Ledger: elffuss/ledger, event 164
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: elffuss/copilot#1