Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Nov 1, 2025

Description

This PR implements support for OpenRouter as an embedding provider for the code-indexing feature, addressing Issue #8972.

Changes

  • Added OpenRouter to the list of supported embedding providers
  • Implemented OpenRouterEmbedder class that extends OpenAICompatibleEmbedder
  • Added support for 8 OpenRouter embedding models:
    • text-embedding-3-small (OpenAI)
    • text-embedding-3-large (OpenAI)
    • text-embedding-ada-002 (OpenAI)
    • embed-english-v3.0 (Cohere)
    • embed-multilingual-v3.0 (Cohere)
    • embed-english-light-v3.0 (Cohere)
    • voyage-3 (Voyage)
    • voyage-3-lite (Voyage)
  • Configured to reuse existing OpenRouter API key from chat model settings
  • Added comprehensive unit tests with 100% coverage
  • Updated TypeScript type definitions in packages/types module
  • Added missing i18n translation key

Benefits

  • OpenRouter users can now use embedding models for code indexing without needing additional API keys
  • Leverages existing OpenRouter infrastructure and API key configuration
  • Provides access to multiple high-quality embedding models through a single provider

Testing

  • All unit tests pass (6/6 tests in openrouter.spec.ts)
  • TypeScript compilation successful
  • Linting checks pass
  • No regressions in existing tests

Implementation Notes

The implementation leverages the existing OpenAI-compatible infrastructure since OpenRouter's embedding API follows the OpenAI format. This minimizes code duplication and ensures consistency with other providers.

Closes #8972


Important

This PR adds OpenRouter as a new embedding provider for code indexing, including configuration, model support, and tests.

  • Behavior:
    • Adds OpenRouter as a new embedding provider in codebase-index.ts and WebviewMessage.ts.
    • Implements OpenRouterEmbedder class in openrouter.ts, extending OpenAICompatibleEmbedder.
    • Supports 8 models, including OpenAI, Cohere, and Voyage models.
    • Reuses existing OpenRouter API key from chat model settings.
  • Configuration:
    • Updates CodeIndexConfigManager in config-manager.ts to handle OpenRouter configuration.
    • Adds OpenRouter options to CodeIndexConfig and PreviousConfigSnapshot in config.ts.
  • Models:
    • Adds OpenRouter models to EMBEDDING_MODEL_PROFILES in embeddingModels.ts.
  • Testing:
    • Adds unit tests for OpenRouterEmbedder in openrouter.spec.ts.
  • Localization:
    • Adds openRouterConfigMissing translation key in multiple embeddings.json files.

This description was created by Ellipsis for 8d3c354. You can customize this summary. It will automatically update as commits are pushed.

- Add OpenRouter to EmbedderProvider type and related interfaces
- Create OpenRouterEmbedder class that extends OpenAICompatibleEmbedder
- Add OpenRouter embedding models to EMBEDDING_MODEL_PROFILES
- Update service factory to handle OpenRouter embedder creation
- Configure OpenRouter to use existing API key from chat model settings
- Support OpenRouter embedding models including OpenAI, Cohere, and Voyage models

Closes #8972
@roomote roomote bot requested review from cte, jr and mrubens as code owners November 1, 2025 22:23
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 1, 2025
@roomote
Copy link
Author

roomote bot commented Nov 1, 2025

See this task on Roo Code Cloud

Review complete. Found 3 issues to address.

Issues to Resolve

  • Remove unused modelId field in OpenRouterEmbedder class (lines 23-42 in openrouter.ts)
  • Fix documentation inconsistency: JSDoc lists 7 models but implementation includes 8 (missing voyage/voyage-embeddings-v3 in docs)
  • Translate openRouterConfigMissing to respective languages in all non-English locale files (currently all contain English text)
Previous Reviews

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

@dosubot dosubot bot added the enhancement New feature or request label Nov 1, 2025
Comment on lines +23 to +42
private readonly modelId: string

/**
* Creates a new OpenRouter embedder
* @param apiKey The OpenRouter API key for authentication
* @param modelId The model ID to use (defaults to openai/text-embedding-3-small)
* @param baseUrl Optional custom base URL for OpenRouter API (defaults to https://openrouter.ai/api/v1)
*/
constructor(apiKey?: string, modelId?: string, baseUrl?: string) {
if (!apiKey) {
throw new Error(t("embeddings:validation.apiKeyRequired"))
}

// Use the provided base URL or default to OpenRouter's API URL
const openRouterBaseUrl = baseUrl || OpenRouterEmbedder.OPENROUTER_BASE_URL

// Initialize the parent OpenAI Compatible embedder with OpenRouter configuration
super(openRouterBaseUrl, apiKey, modelId || OpenRouterEmbedder.DEFAULT_MODEL, MAX_ITEM_TOKENS)

this.modelId = modelId || getDefaultModelId("openrouter")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modelId field is assigned but never used within this class. Other similar embedders (MistralEmbedder, VercelAiGatewayEmbedder) don't store this field since the parent class already handles it. Consider removing this unused field to reduce code complexity.

Comment on lines +11 to +18
* Supported models:
* - openai/text-embedding-3-small (dimension: 1536)
* - openai/text-embedding-3-large (dimension: 3072)
* - openai/text-embedding-ada-002 (dimension: 1536)
* - cohere/embed-english-v3.0 (dimension: 1024)
* - cohere/embed-multilingual-v3.0 (dimension: 1024)
* - voyage/voyage-3 (dimension: 1024)
* - voyage/voyage-3-lite (dimension: 512)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc comment lists 7 supported models but the implementation in embeddingModels.ts includes 8 models. The comment is missing voyage/voyage-embeddings-v3 which is defined on line 89 of embeddingModels.ts. Update the documentation to include all supported models or remove the unlisted model from the implementation.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 1, 2025
"qdrantUrlMissing": "Falta l'URL de Qdrant per crear l'emmagatzematge de vectors",
"codeIndexingNotConfigured": "No es poden crear serveis: La indexació de codi no està configurada correctament"
"codeIndexingNotConfigured": "No es poden crear serveis: La indexació de codi no està configurada correctament",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All non-English locale files contain the English translation instead of translations in their respective languages. The value should be translated to match the locale (Catalan for ca, German for de, Spanish for es, etc.). This breaks the localization feature for users in these languages.

"qdrantUrlMissing": "Falta l'URL de Qdrant per crear l'emmagatzematge de vectors",
"codeIndexingNotConfigured": "No es poden crear serveis: La indexació de codi no està configurada correctament"
"codeIndexingNotConfigured": "No es poden crear serveis: La indexació de codi no està configurada correctament",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New key openRouterConfigMissing is added with an English string. Consider providing a proper Catalan translation instead of the default English text.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "Falta la configuració d'OpenRouter per crear l'embedder"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "Qdrant-URL fehlt für die Erstellung des Vektorspeichers",
"codeIndexingNotConfigured": "Kann keine Dienste erstellen: Code-Indizierung ist nicht richtig konfiguriert"
"codeIndexingNotConfigured": "Kann keine Dienste erstellen: Code-Indizierung ist nicht richtig konfiguriert",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new key openRouterConfigMissing remains in English. Please localize it into German.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "OpenRouter-Konfiguration fehlt für die Erstellung des Embedders"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "Falta la URL de Qdrant para crear el almacén de vectores",
"codeIndexingNotConfigured": "No se pueden crear servicios: La indexación de código no está configurada correctamente"
"codeIndexingNotConfigured": "No se pueden crear servicios: La indexación de código no está configurada correctamente",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translation for openRouterConfigMissing is still in English. It should be localized into Spanish.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "Falta la configuración de OpenRouter para crear el incrustador"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "URL Qdrant manquante pour la création du stockage de vecteurs",
"codeIndexingNotConfigured": "Impossible de créer les services : L'indexation du code n'est pas correctement configurée"
"codeIndexingNotConfigured": "Impossible de créer les services : L'indexation du code n'est pas correctement configurée",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New key openRouterConfigMissing is not translated into French. Please update with a French translation.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "Configuration OpenRouter manquante pour la création de l'embedder"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "वेक्टर स्टोर बनाने के लिए Qdrant URL गायब है",
"codeIndexingNotConfigured": "सेवाएं नहीं बना सकते: कोड इंडेक्सिंग ठीक से कॉन्फ़िगर नहीं है"
"codeIndexingNotConfigured": "सेवाएं नहीं बना सकते: कोड इंडेक्सिंग ठीक से कॉन्फ़िगर नहीं है",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new key openRouterConfigMissing remains in English. A proper Hindi translation is recommended.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "एम्बेडर निर्माण के लिए OpenRouter कॉन्फ़िगरेशन गायब है"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "Отсутствует URL Qdrant для создания векторного хранилища",
"codeIndexingNotConfigured": "Невозможно создать сервисы: Индексация кода не настроена должным образом"
"codeIndexingNotConfigured": "Невозможно создать сервисы: Индексация кода не настроена должным образом",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new key openRouterConfigMissing remains untranslated in Russian. Please add a proper Russian translation.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "Отсутствует конфигурация OpenRouter для создания эмбеддера"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "Vektör deposu oluşturmak için Qdrant URL'si eksik",
"codeIndexingNotConfigured": "Hizmetler oluşturulamıyor: Kod indeksleme düzgün yapılandırılmamış"
"codeIndexingNotConfigured": "Hizmetler oluşturulamıyor: Kod indeksleme düzgün yapılandırılmamış",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The openRouterConfigMissing key is added with an English value. Please consider localizing it into Turkish.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "Gömücü oluşturmak için OpenRouter yapılandırması eksik"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "Thiếu URL Qdrant để tạo kho lưu trữ vector",
"codeIndexingNotConfigured": "Không thể tạo dịch vụ: Lập chỉ mục mã không được cấu hình đúng cách"
"codeIndexingNotConfigured": "Không thể tạo dịch vụ: Lập chỉ mục mã không được cấu hình đúng cách",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new key 'openRouterConfigMissing' remains in English in the Vietnamese locale. Please provide a proper translation.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "Thiếu cấu hình OpenRouter để tạo trình nhúng"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "创建向量存储缺少 Qdrant URL",
"codeIndexingNotConfigured": "无法创建服务:代码索引未正确配置"
"codeIndexingNotConfigured": "无法创建服务:代码索引未正确配置",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key openRouterConfigMissing is added with an English string. Consider adding a Chinese translation.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "创建嵌入器缺少 OpenRouter 配置"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

"qdrantUrlMissing": "建立向量儲存缺少 Qdrant URL",
"codeIndexingNotConfigured": "無法建立服務:程式碼索引未正確設定"
"codeIndexingNotConfigured": "無法建立服務:程式碼索引未正確設定",
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'openRouterConfigMissing' key remains in English in the Traditional Chinese file. Please update it with a proper translation.

Suggested change
"openRouterConfigMissing": "OpenRouter configuration missing for embedder creation"
"openRouterConfigMissing": "建立嵌入器缺少 OpenRouter 設定"

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

@daniel-lxs daniel-lxs closed this Nov 2, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 2, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Add OpenRouter as an embedding provider

4 participants