{"record":{"id":"9dfc1c9b839bb605","repo":"microsoft/semantic-kernel","slug":"the-google-ai-embedding-model-id-is-required","errorCode":null,"errorMessage":"The Google AI embedding model ID is required.","messagePattern":"The Google AI embedding model ID is required\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"critical","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py","lineNumber":79,"sourceCode":"\n        Raises:\n            ServiceInitializationError: If an error occurs during initialization.\n        \"\"\"\n        try:\n            google_ai_settings = GoogleAISettings(\n                embedding_model_id=embedding_model_id,\n                api_key=api_key,\n                cloud_project_id=project_id,\n                cloud_region=region,\n                use_vertexai=use_vertexai,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as e:\n            raise ServiceInitializationError(f\"Failed to validate Google AI settings: {e}\") from e\n\n        if not google_ai_settings.embedding_model_id:\n            raise ServiceInitializationError(\"The Google AI embedding model ID is required.\")\n\n        if not client:\n            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:\n                raise ServiceInitializationError(\"Project ID must be provided when use_vertexai is True.\")\n            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:\n                raise ServiceInitializationError(\"Region must be provided when use_vertexai is True.\")\n            if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:\n                raise ServiceInitializationError(\"The API key is required when use_vertexai is False.\")\n\n        super().__init__(\n            ai_model_id=google_ai_settings.embedding_model_id,\n            service_id=service_id or google_ai_settings.embedding_model_id,\n            service_settings=google_ai_settings,\n            client=client,\n        )\n\n    @override\n    async def generate_embeddings(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py#L61-L97","documentation":"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.","triggerScenarios":"Constructing GoogleAITextEmbedding() with no embedding_model_id argument and no GOOGLE_AI_EMBEDDING_MODEL_ID environment variable.","commonSituations":"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.","solutions":["Set GOOGLE_AI_EMBEDDING_MODEL_ID=<model> in your environment or .env file (e.g. GOOGLE_AI_EMBEDDING_MODEL_ID=text-embedding-004).","Pass embedding_model_id=<model> to the GoogleAITextEmbedding constructor.","Verify that the .env file pointed to by env_file_path contains the variable."],"exampleFix":"# before\nembed_service = GoogleAITextEmbedding(api_key=key)\n\n# after\nembed_service = GoogleAITextEmbedding(api_key=key, embedding_model_id='text-embedding-004')","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get('GOOGLE_AI_EMBEDDING_MODEL_ID'):\n    raise EnvironmentError('Set GOOGLE_AI_EMBEDDING_MODEL_ID before constructing GoogleAITextEmbedding.')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextEmbedding()\nexcept ServiceInitializationError as e:\n    if 'embedding model ID is required' in str(e):\n        os.environ['GOOGLE_AI_EMBEDDING_MODEL_ID'] = 'text-embedding-004'\n        service = GoogleAITextEmbedding()\n    else:\n        raise","preventionTips":["Set GOOGLE_AI_EMBEDDING_MODEL_ID in .env alongside GOOGLE_AI_GEMINI_MODEL_ID.","Use distinct model IDs for chat vs embedding — they are different endpoints.","Fail fast in CI when required embedding env vars are absent."],"tags":["google-ai","embeddings","model-id","configuration","constructor"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}