⚡ Bolt: optimize synthetic embedding generation#207
Conversation
- Replaced per-dimension SHA-256 hashing in `syntheticVector` with a single hash seeding a Mulberry32 PRNG. - Optimized `normalizeVector` using for-loops and faster rounding (`Math.round` vs `toFixed`). - Used `Float64Array` for efficient intermediate vector storage. - Preserved unit vector normalization and deterministic output. Performance Impact: - Throughput increased from ~180 embeddings/sec to ~4900 embeddings/sec (~27x improvement). - Reduced CPU overhead for synthetic data generation in testing and development environments. Measurement: - Verified using `packages/ai/src/verify_v2.mjs` (removed after verification). Co-authored-by: hackerxj2010 <198651211+hackerxj2010@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What
This PR optimizes the synthetic embedding generation in
@jeanbot/ai. It replaces a highly inefficient cryptographic hashing loop with a fast, deterministic PRNG (Mulberry32) and optimizes vector normalization.🎯 Why
The original implementation performed a full SHA-256 hash for every single dimension of a 1536-dimensional vector. This was extremely CPU-intensive and created a significant bottleneck in environments where synthetic embeddings are used (e.g., development, CI/CD, or when OpenAI keys are not provided).
📊 Impact
🔬 Measurement
Benchmark ran on Node v22:
PR created automatically by Jules for task 4876807457926495130 started by @hackerxj2010