Skip to content

Add Google GenAI embedding model support #1389

Open
azanux wants to merge 2 commits intoembabel:mainfrom
azanux:feature/add-text-embedding-001
Open

Add Google GenAI embedding model support #1389
azanux wants to merge 2 commits intoembabel:mainfrom
azanux:feature/add-text-embedding-001

Conversation

@azanux
Copy link
Contributor

@azanux azanux commented Feb 7, 2026

Summary

  • Adds support for Google GenAI (Gemini) embedding models
  • Introduces gemini-embedding-001 (3072 dimensions) as the recommended GA embedding model
  • Uses Spring AI 1.1.1's spring-ai-google-genai-embedding artifact with GoogleGenAiTextEmbeddingModel and GoogleGenAiEmbeddingConnectionDetails
  • Supports both API key and Vertex AI authentication modes, consistent with the existing LLM configuration

Documentation

  • Added embedding models list, updated example application.yml with default-embedding-model
  • Added embedding models table (name, model ID, dimensions, pricing)

Note on createGoogleGenAiEmbeddingConnectionDetails()

Unlike other providers (OpenAI, Bedrock, Ollama) where a single API client is shared between chat and embedding models, Spring AI exposes two distinct connection types for Google GenAI:

  • Client for the chat model
  • GoogleGenAiEmbeddingConnectionDetails for the embedding model

These two classes are incompatible, requiring a separate factory method (createGoogleGenAiEmbeddingConnectionDetails()) that mirrors the authentication logic (API key vs Vertex AI) from createGoogleGenAiClient(). This is a constraint imposed by the Spring AI library.

Test plan

  • Module compiles successfully
  • All tests pass (26 existing + 13 new embedding tests)
  • Verify in ragbot that Google GenAI embeddings appear in startup logs

Changes

pom.xml

  • Added spring-ai-google-genai-embedding dependency (managed by Spring AI BOM)

GoogleGenAiModelLoader.kt

  • Added GoogleGenAiEmbeddingModelDefinition and EmbeddingPricingModel data classes
  • Extended GoogleGenAiModelDefinitions with embeddingModels property
  • Added embedding model validation (name, modelId, dimensions, pricing)

GoogleGenAiModelsConfig.kt

  • Added createGoogleGenAiEmbeddingConnectionDetails() with same auth logic as LLM client
  • Added createGoogleGenAiEmbedding() that creates a SpringAiEmbeddingService wrapping GoogleGenAiTextEmbeddingModel
  • Updated googleGenAiModelsInitializer() to register embedding beans alongside LLMs and return registeredEmbeddings in ProviderInitialization

google-genai-models.yml

  • Added embedding_models section with gemini-embedding-001

GoogleGenAiModelLoaderTest.kt

  • Added 16 new tests covering embedding model loading, validation (invalid dimensions, blank name/modelId, negative pricing), and combined LLM+embedding scenarios

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