{"record":{"id":"85d45c633e728b6e","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-generate-embeddings","errorCode":null,"errorMessage":"{type(self)} service failed to generate embeddings","messagePattern":"(.+?) service failed to generate embeddings","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/nvidia/services/nvidia_handler.py","lineNumber":58,"sourceCode":"        if self.ai_model_type == NvidiaModelTypes.EMBEDDING:\n            assert isinstance(settings, NvidiaEmbeddingPromptExecutionSettings)  # nosec\n            return await self._send_embedding_request(settings)\n        if self.ai_model_type == NvidiaModelTypes.CHAT:\n            assert isinstance(settings, NvidiaChatPromptExecutionSettings)  # nosec\n            return await self._send_chat_completion_request(settings)\n\n        raise NotImplementedError(f\"Model type {self.ai_model_type} is not supported\")\n\n    async def _send_embedding_request(self, settings: NvidiaEmbeddingPromptExecutionSettings) -> list[Any]:\n        \"\"\"Send a request to the OpenAI embeddings endpoint.\"\"\"\n        try:\n            # unsupported parameters are internally excluded from main dict and added to extra_body\n            response = await self.client.embeddings.create(**settings.prepare_settings_dict())\n\n            self.store_usage(response)\n            return [x.embedding for x in response.data]\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to generate embeddings\",\n                ex,\n            ) from ex\n\n    async def _send_chat_completion_request(\n        self, settings: NvidiaChatPromptExecutionSettings\n    ) -> ChatCompletion | AsyncStream[Any]:\n        \"\"\"Send a request to the NVIDIA chat completion endpoint.\"\"\"\n        try:\n            settings_dict = settings.prepare_settings_dict()\n\n            # Handle structured output if nvext is present in extra_body\n            if settings.extra_body and \"nvext\" in settings.extra_body:\n                if \"extra_body\" not in settings_dict:\n                    settings_dict[\"extra_body\"] = {}\n                settings_dict[\"extra_body\"][\"nvext\"] = settings.extra_body[\"nvext\"]\n\n            response = await self.client.chat.completions.create(**settings_dict)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/nvidia/services/nvidia_handler.py#L40-L76","documentation":"Raised as ServiceResponseException (chaining `ex`) when `self.client.embeddings.create(**settings.prepare_settings_dict())` throws any exception in `NvidiaHandler._send_embedding_request`. It is the NVIDIA embeddings catch-all around the OpenAI-compatible client; the real cause is in `ex`/`__cause__`. store_usage and result parsing only run if the call succeeds.","triggerScenarios":"Generating NVIDIA embeddings where the OpenAI-style client raises: 401 auth, 404 unknown embedding model, 400/422 from unsupported parameters that were not excluded into extra_body, 429 rate limit, or network/timeout.","commonSituations":"ai_model_id is a chat/vision model id instead of an embedding model, unsupported param leaked into the main dict (the comment notes they should be moved to extra_body), bad/empty inputs list, expired NVIDIA key.","solutions":["Inspect `e.__cause__` for the upstream HTTP status/message.","Ensure ai_model_id is an NVIDIA embedding model (e.g. 'nvidia/nv-embedqa-e5-v5', 'NV-Embed-QA').","Filter empty/oversized inputs from the texts list before calling.","Retry on 429/timeout with backoff; verify NVIDIA_API_KEY is valid."],"exampleFix":"# before\nvecs = await svc.generate_embeddings(texts)\n\n# after\ntry:\n    vecs = await svc.generate_embeddings([t for t in texts if t.strip()])\nexcept ServiceResponseException as e:\n    raise RuntimeError(f\"NVIDIA embedding upstream error: {e.__cause__!r}\") from e","handlingStrategy":"retry","validationCode":"assert texts and all(t.strip() for t in texts), 'embed non-empty texts only'\nassert svc.ai_model_id and 'embed' in svc.ai_model_id.lower(), 'use an NVIDIA embedding model id'","typeGuard":"from semantic_kernel.exceptions import ServiceResponseException\n\ndef is_nvidia_embed_error(e: BaseException) -> bool:\n    return isinstance(e, ServiceResponseException) and 'failed to generate embeddings' in str(e)","tryCatchPattern":"import asyncio\nfrom semantic_kernel.exceptions import ServiceResponseException\nasync def embed_retry(svc, texts, attempts=3):\n    for i in range(attempts):\n        try:\n            return await svc.generate_embeddings(texts)\n        except ServiceResponseException as e:\n            if getattr(e.__cause__, 'status_code', None) in (429, 503):\n                await asyncio.sleep(2 ** i); continue\n            raise\n    raise RuntimeError('embeddings failed after retries')","preventionTips":["Filter empty inputs before embedding.","Use a real NVIDIA embedding model id.","Move unsupported params into extra_body.","Retry on 429/503/timeout."],"tags":["nvidia","embeddings","network","api-key","service-response-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}