Skip to content

[ENH] Implements a new embedding function for ChromaDB that uses the modern google-genai library (the recommended replacement for google.generativeai). #4278

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yrangana
Copy link

This PR adds a new embedding function that uses the modern google-genai library for ChromaDB.

Improvements & Bug fixes
Addresses dependency on deprecated google.generativeai package
Ensures compatibility with the latest Google Generative AI API
Fixes response structure handling to properly extract embeddings

New functionality

  • Adds GoogleGenAiEmbeddingFunction class that implements ChromaDB's EmbeddingFunction interface
  • Uses text-embedding-004 as the default model (Google's recommended embedding model)
  • Maintains the original GoogleGenerativeAiEmbeddingFunction for backward compatibility
  • Provides comprehensive error handling and validation for API key configuration
  • Supports the same vector spaces (cosine, l2, ip) as the original implementation

Test plan
How are these changes tested?

  • Tests pass locally with pytest for python
  • Manually tested embedding generation
  • Verified compatibility with existing ChromaDB collections
  • Confirmed proper error handling when API keys are missing or invalid
  • Tested with various document types and lengths to ensure consistent embedding generation

Documentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

  • All docstrings have been updated with comprehensive descriptions and parameter details
  • The main class docstring clearly indicates this is using the newer google-genai package
  • The documentation repository should be updated to include:

… google-genai library (the recommended replacement for google.generativeai).

- Added GoogleGenAiEmbeddingFunction class that implements ChromaDB's EmbeddingFunction interface
- Maintained compatibility with existing GoogleGenerativeAiEmbeddingFunction
- Uses text-embedding-004 as the default model (same as in the main API)
- Properly handles the new response structure from the google-genai library
- Provides comprehensive error handling and validation
- Supports the same vector spaces (cosine, l2, ip) as the original implementation
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@jairad26
Copy link
Contributor

jairad26 commented Apr 15, 2025

thank you for the PR! Could you also add the js embedding function to match, and add the google_genai.json to match? No worries if not, I can add to the PR as well if youre ok with that. Also could you prepend the PR title with [ENH]

@yrangana yrangana changed the title Implements a new embedding function for ChromaDB that uses the modern google-genai library (the recommended replacement for google.generativeai). [ENH] Implements a new embedding function for ChromaDB that uses the modern google-genai library (the recommended replacement for google.generativeai). Apr 15, 2025
@yrangana
Copy link
Author

Im not familiar with JS function @jairad26, Can you add it pls. I have renamed the title. Thank you

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