Skip to content

⚡ Bolt: optimize synthetic embedding generation and vector normalization#200

Draft
hackerxj2010 wants to merge 1 commit into
mainfrom
bolt-optimize-ai-embeddings-14641192464108532705
Draft

⚡ Bolt: optimize synthetic embedding generation and vector normalization#200
hackerxj2010 wants to merge 1 commit into
mainfrom
bolt-optimize-ai-embeddings-14641192464108532705

Conversation

@hackerxj2010
Copy link
Copy Markdown
Owner

💡 What: Optimized synthetic embedding generation and vector math in the @jeanbot/ai package.

🎯 Why: The original implementation was bottlenecked by excessive hashing (one SHA-256 per dimension) and slow string-based rounding (toFixed(8)) in hot loops.

📊 Impact:

  • Increased synthetic embedding throughput from ~102 embeddings/sec to ~4545 embeddings/sec (~45x improvement).
  • Reduced CPU overhead for vector normalization and similarity calculations.

🔬 Measurement:

  • Verified with packages/ai/src/benchmark.ts.
  • Correctness ensured by packages/ai/src/index.test.ts (determinism and normalization).

🛡️ Note: Uses the modern crypto.hash API (available in Node.js 22.22.1+ provided in the environment).


PR created automatically by Jules for task 14641192464108532705 started by @hackerxj2010

Optimized synthetic embedding generation and vector math in `@jeanbot/ai`.
- Replaced per-dimension hashing with a single SHA-256 hash and a Mulberry32 PRNG.
- Replaced `toFixed(8)` with a faster `round8` utility using `Math.round`.
- Optimized `normalizeVector` with a single pass and inverse multiplication.
- Removed redundant normalization calls in the generation pipeline.
- Added a benchmark script and unit tests to verify performance and correctness.

Throughput increased from ~102 to ~4500 embeddings/sec (~45x gain).

Co-authored-by: hackerxj2010 <198651211+hackerxj2010@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant