Skip to content

Guard GoogleGenAiEmbeddingConnectionAutoConfiguration with the model enablement property - #6794

Open
hoyo1744 wants to merge 1 commit into
spring-projects:mainfrom
hoyo1744:gemini-embedding-connection-conditional
Open

Guard GoogleGenAiEmbeddingConnectionAutoConfiguration with the model enablement property#6794
hoyo1744 wants to merge 1 commit into
spring-projects:mainfrom
hoyo1744:gemini-embedding-connection-conditional

Conversation

@hoyo1744

@hoyo1744 hoyo1744 commented Aug 13, 2026

Copy link
Copy Markdown

GoogleGenAiEmbeddingConnectionAutoConfiguration is not guarded by the
model enablement property, so it is applied whenever the artifact is on
the classpath. When nothing is configured it falls back to Vertex AI mode
and fails the context:

java.lang.IllegalArgumentException: Google GenAI project-id must be set!

This means adding spring-ai-starter-model-google-genai-embedding breaks
startup for applications that do not use Google GenAI embeddings, and
spring.ai.model.embedding.text=none does not help because the condition
is never evaluated.

Reproduce

  1. Add spring-ai-starter-model-google-genai-embedding.
  2. Set spring.ai.model.embedding.text=none (or leave everything unset).
  3. Start the application.

Relation to previous reports

The same symptom was reported in #6130 and closed as a duplicate of
#6171, which removed the embedding artifact from the chat starter. That
resolves the reported case, where the artifact was pulled in
unintentionally.

It does not cover this one. Here the embedding starter is added on
purpose, because the application does use Google GenAI embeddings in some
environments and selects another provider in others. Since the artifact
is wanted on the classpath, dependency removal is not an option and the
missing condition is the only thing left.

This is exactly what was pointed out in #6130:

There is @ConditionalOnProperty annotation on
GoogleGenAiTextEmbeddingAutoConfiguration, so it should disable it,
but not on GoogleGenAiEmbeddingConnectionAutoConfiguration, which is
not ideal because it can't be disabled like this for now.

Unlike #6156, which gated the auto-configuration on the presence of
credentials, this reuses the existing model enablement property so that
the connection and the model it feeds share one switch.

See #6130
See #6171

Inconsistency

The sibling auto-configurations in the same module are guarded, the
connection one is not:

Auto-configuration Property condition
GoogleGenAiChatAutoConfiguration spring.ai.model.chat
GoogleGenAiTextEmbeddingAutoConfiguration spring.ai.model.embedding.text
GoogleGenAiImageAutoConfiguration spring.ai.model.image
GoogleGenAiEmbeddingConnectionAutoConfiguration none

Change

Applies the same condition already used by
GoogleGenAiTextEmbeddingAutoConfiguration, so the connection and the
model it feeds share a single switch. matchIfMissing = true keeps the
current default-on behaviour, so applications that configure nothing are
unaffected.

Adds GoogleGenAiEmbeddingConnectionAutoConfigurationTests covering
explicit enable, default enable, none, another provider, and that the
context starts when nothing is configured.

Note

GoogleGenAiImageConnectionAutoConfiguration has the same missing
condition. I left it out because its bean method does not fail fast the
same way and I could not confirm a broken startup for it. Happy to
extend this PR if you would like both aligned.

This may also be a small piece of the broader auto-configuration
activation discussion raised in #6130 and #5989.

Apply the model enablement property condition already used by
GoogleGenAiTextEmbeddingAutoConfiguration, so the connection is not
created when Google GenAI embeddings are disabled.

Without it the auto-configuration runs unconditionally and falls back
to Vertex AI mode, failing startup with "Google GenAI project-id must
be set!" for applications that do not use Google GenAI embeddings.

Signed-off-by: hoyong.eom <hoyo1744@gmail.com>
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.

2 participants