Skip to content

⚡ Bolt: optimize synthetic embedding generation#222

Draft
hackerxj2010 wants to merge 1 commit into
mainfrom
bolt/optimize-synthetic-embeddings-2725135362605627358
Draft

⚡ Bolt: optimize synthetic embedding generation#222
hackerxj2010 wants to merge 1 commit into
mainfrom
bolt/optimize-synthetic-embeddings-2725135362605627358

Conversation

@hackerxj2010
Copy link
Copy Markdown
Owner

💡 What: The optimization implemented

Optimized the syntheticVector generation in the @jeanbot/ai package by leveraging the one-shot crypto.hash function available in Node.js 22 and eliminating redundant string normalization operations.

🎯 Why: The performance problem it solves

The previous implementation used crypto.createHash('sha256').update(...).digest() within a loop of 1536 iterations per vector, and performed redundant normalizeText calls. This created unnecessary object instantiation and CPU overhead for a high-frequency operation.

📊 Impact: Expected performance improvement

  • Reduces generation time by ~50%.
  • Benchmarked at ~3.6ms per vector, down from ~7.5ms.

🔬 Measurement: How to verify the improvement

I created a temporary benchmark script that ran 1000 iterations of syntheticVector and compared the total duration before and after the change. Determinism was also verified to ensure the output vectors remained identical.


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

This commit optimizes the `syntheticVector` generation in `@jeanbot/ai` by:
1. Using the one-shot `crypto.hash` method (Node 22+) instead of `crypto.createHash`.
2. Reducing redundant `normalizeText` calls within the generation loop.

Expected Impact:
- ~2x speedup in synthetic embedding generation.
- Measured improvement from ~7.5ms to ~3.6ms per vector (1536 dimensions).

Verification:
- Ran `benchmark.ts` to measure execution time and verify determinism.
- Ran `pnpm test` to ensure no regressions.

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