Skip to content

feat: Add support for Google Gemini embedding model #5621

@Jopo-JP

Description

@Jopo-JP

What specific problem does this solve?

Problem: Roo Code currently only supports Google's text-embedding-004 model, which is an older generation of embedding models. Users who want to leverage the newer, more powerful, and potentially more cost-effective gemini-embedding-exp-03-07 model are unable to do so.

Impact: This limits the quality and flexibility of the codebase indexing feature. The new Gemini model offers elastic output dimensions (3072, 1536, 768), allowing users to balance performance and cost, but this capability is currently inaccessible. Developers are forced to use an outdated model, which may not meet their project's requirements.

Additional context (optional)

The gemini-embedding-exp-03-07 model is Google's latest-generation embedding model and is the recommended model for new applications. Adding support for it will ensure Roo Code stays current with the latest AI technologies.

Roo Code Task Links (Optional)

No response

Request checklist

  • I've searched existing Issues and Discussions for duplicates
  • This describes a specific problem with clear impact and context

Interested in implementing this?

  • Yes, I'd like to help implement this feature

Implementation requirements

  • I understand this needs approval before implementation begins

How should this be solved? (REQUIRED if contributing, optional otherwise)

The solution involves adding support for the gemini-embedding-exp-03-07 model and its flexible output dimensions.

  1. Update Model Definitions: Add model profiles for gemini-embedding-exp-03-07 with dimensions 3072, 1536, and 768 to src/shared/embeddingModels.ts.
  2. Update Embedder Logic: Modify the GeminiEmbedder in src/services/code-index/embedders/gemini.ts to pass the selected outputDimension to the underlying API.
  3. Update Base Embedder: The OpenAICompatibleEmbedder will be updated to accept and handle the outputDimension parameter.
  4. Bug Fix: A related TypeError in webviewMessageHandler will be fixed by adding a null check for provider.codeIndexManager.

How will we know it works? (Acceptance Criteria - REQUIRED if contributing, optional otherwise)

Given a user wants to configure codebase indexing with the latest Google model
When they navigate to the "Roo-Code: Codebase Indexing Settings"
And select "Gemini" as the Embedder Provider
Then the "Select a model" dropdown should list gemini-embedding-exp-03-07 with options for 3072, 1536, and 768 dimensions.
And the user can select any of these options and save the settings without errors.
But the existing text-embedding-004 model must remain available and fully functional.

Technical considerations (REQUIRED if contributing, optional otherwise)

The implementation will affect the following files:

  • src/shared/embeddingModels.ts
  • src/services/code-index/embedders/gemini.ts
  • src/services/code-index/embedders/openai-compatible.ts
  • src/core/webview/webviewMessageHandler.ts
  • src/services/code-index/embedders/__tests__/gemini.spec.ts

Trade-offs and risks (REQUIRED if contributing, optional otherwise)

The primary risk was a potential regression in the webview, which manifested as a TypeError. This has been identified and fixed by adding a null check, making the implementation low-risk. There are no breaking changes, as the existing text-embedding-004 model is preserved.

Metadata

Metadata

Assignees

Labels

EnhancementNew feature or requestIssue - In ProgressSomeone is actively working on this. Should link to a PR soon.proposal

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions