microsoft/semantic-kernel · critical · ServiceInitializationError

The Google AI embedding model ID is required.

Error message

The Google AI embedding model ID is required.

What it means

Raised in the GoogleAITextEmbedding constructor when GoogleAISettings resolves embedding_model_id to None or empty. The embedding service needs an embedding model identifier (e.g. 'text-embedding-004'). embedding_model_id is declared str | None in settings, so Pydantic won't reject its absence — this explicit guard does.

Source

Thrown at python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py:79

        Raises:
            ServiceInitializationError: If an error occurs during initialization.
        """
        try:
            google_ai_settings = GoogleAISettings(
                embedding_model_id=embedding_model_id,
                api_key=api_key,
                cloud_project_id=project_id,
                cloud_region=region,
                use_vertexai=use_vertexai,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as e:
            raise ServiceInitializationError(f"Failed to validate Google AI settings: {e}") from e

        if not google_ai_settings.embedding_model_id:
            raise ServiceInitializationError("The Google AI embedding model ID is required.")

        if not client:
            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
                raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
                raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
            if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
                raise ServiceInitializationError("The API key is required when use_vertexai is False.")

        super().__init__(
            ai_model_id=google_ai_settings.embedding_model_id,
            service_id=service_id or google_ai_settings.embedding_model_id,
            service_settings=google_ai_settings,
            client=client,
        )

    @override
    async def generate_embeddings(

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set GOOGLE_AI_EMBEDDING_MODEL_ID=<model> in your environment or .env file (e.g. GOOGLE_AI_EMBEDDING_MODEL_ID=text-embedding-004).
  2. Pass embedding_model_id=<model> to the GoogleAITextEmbedding constructor.
  3. Verify that the .env file pointed to by env_file_path contains the variable.

Example fix

# before
embed_service = GoogleAITextEmbedding(api_key=key)

# after
embed_service = GoogleAITextEmbedding(api_key=key, embedding_model_id='text-embedding-004')
Defensive patterns

Strategy: validation

Validate before calling

import os
if not os.environ.get('GOOGLE_AI_EMBEDDING_MODEL_ID'):
    raise EnvironmentError('Set GOOGLE_AI_EMBEDDING_MODEL_ID before constructing GoogleAITextEmbedding.')

Try / catch

try:
    service = GoogleAITextEmbedding()
except ServiceInitializationError as e:
    if 'embedding model ID is required' in str(e):
        os.environ['GOOGLE_AI_EMBEDDING_MODEL_ID'] = 'text-embedding-004'
        service = GoogleAITextEmbedding()
    else:
        raise

Prevention

When it happens

Trigger: Constructing GoogleAITextEmbedding() with no embedding_model_id argument and no GOOGLE_AI_EMBEDDING_MODEL_ID environment variable.

Common situations: Set GOOGLE_AI_GEMINI_MODEL_ID for chat/text but forgot GOOGLE_AI_EMBEDDING_MODEL_ID for embeddings; .env file lacks the embedding model var; misnamed the variable.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/9dfc1c9b839bb605. Report an issue: GitHub.