Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 4, 2026

The quantizeToUint8 and quantizeToUint16 methods used spread operators with Math.min(...values) and Math.max(...values), causing performance degradation and potential stack overflow on large vectors.

Changes:

  • Added findMinMax() helper that computes min/max in single pass using explicit loop
  • Updated quantizeToUint8 and quantizeToUint16 to use optimized helper
  • Fixed edge case: empty arrays now return { min: 0, max: 1 } to prevent division by zero

Before:

const min = Math.min(...values);  // Two iterations + intermediate arrays
const max = Math.max(...values);

After:

const { min, max } = this.findMinMax(values);  // Single pass, no spreading

Addresses feedback: #154 (comment)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 4, 2026 00:59
Co-authored-by: sroussey <127349+sroussey@users.noreply.github.com>
Co-authored-by: sroussey <127349+sroussey@users.noreply.github.com>
Copilot AI changed the title [WIP] Update VectorQuantizeTask and VectorSimilarityTask based on feedback Optimize VectorQuantizeTask min/max finding with single-pass algorithm Jan 4, 2026
Copilot AI requested a review from sroussey January 4, 2026 01:02
@sroussey sroussey marked this pull request as ready for review January 4, 2026 01:24
@sroussey sroussey merged commit c44fd0a into rag Jan 4, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants