Skip to content

Add batched embeddings example #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

aparna534
Copy link

Description

This adds a working example of batch text embeddings using genai.embed_content().

Key Changes

  • New file: examples/gemini/python/batched_embeddings.py
    • It processes multiple texts in a single API call
    • It uses environment variables for API key configuration
    • It includes comprehensive error handling
  • Updated: examples/gemini/python/README.md with instructions

Verification

Locally tested with successful output:

Success! Generated 5 embeddings:

Text 1: The quick brown fox jumps over the lazy dog.
First 5 dimensions: [0.053, -0.001, -0.065, -0.005, 0.026]
Total dimensions: 768

Text 2: Gemini's batch embeddings are more efficient...
First 5 dimensions: [0.045, -0.028, -0.061, 0.012, 0.011] 
Total dimensions: 768

The app.yaml should use nodejs as runtime for React application. The python runtime will cause the deployment failure. The PR suggests using nodejs18 as stable Nodejs runtime.
@aparna534 aparna534 requested a review from a team as a code owner April 16, 2025 11:22
Copy link

google-cla bot commented Apr 16, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added demos:travel-planner status:awaiting review PR awaiting review from a maintainer component:demos Update demos labels Apr 16, 2025
@aparna534 aparna534 force-pushed the clean_embeddings_fix branch from c05b26a to 839058c Compare April 16, 2025 11:38
@aparna534 aparna534 closed this Apr 16, 2025
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label Apr 16, 2025
@aparna534 aparna534 deleted the clean_embeddings_fix branch April 16, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant