{"record":{"id":"21572aef65ceb75f","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-complete-the-embedd","errorCode":null,"errorMessage":"{type(self)} service failed to complete the embedding request.","messagePattern":"(.+?) service failed to complete the embedding request\\.","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_text_embedding.py","lineNumber":102,"sourceCode":"        texts: list[str],\n        settings: \"PromptExecutionSettings | None\" = None,\n        **kwargs: Any,\n    ) -> ndarray:\n        embedding_response = await self.generate_raw_embeddings(texts, settings, **kwargs)\n        return array(embedding_response)\n\n    @override\n    async def generate_raw_embeddings(\n        self,\n        texts: list[str],\n        settings: \"PromptExecutionSettings | None\" = None,\n        **kwargs: Any,\n    ) -> Any:\n        \"\"\"Generate embeddings from the Mistral AI service.\"\"\"\n        try:\n            embedding_response = await self.async_client.embeddings.create_async(model=self.ai_model_id, inputs=texts)\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the embedding request.\",\n                ex,\n            ) from ex\n        if isinstance(embedding_response, EmbeddingResponse):\n            return [item.embedding for item in embedding_response.data]\n        return []\n","sourceCodeStart":84,"sourceCodeEnd":109,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_text_embedding.py#L84-L109","documentation":"Raised as ServiceResponseException (chaining `ex`) when `self.async_client.embeddings.create_async(model=..., inputs=texts)` throws any exception during `generate_raw_embeddings`. Like the chat variant it is a catch-all; the actual HTTP/SDK error is in the cause. Unlike initialization errors, this means the client built fine and the request was attempted.","triggerScenarios":"Calling `generate_embeddings`/`generate_raw_embeddings` on MistralAITextEmbedding where the Mistral embeddings endpoint returns an error: 401 auth, 404 unknown embedding model, 422 bad inputs (empty list, too-long text), 429 rate limit, or network/timeout.","commonSituations":"ai_model_id points to a chat model instead of an embedding model (e.g. 'mistral-large-latest' passed to embeddings), inputs contain empty strings or exceed Mistral's token cap, transient rate limits during batch embedding.","solutions":["Inspect `e.__cause__` for the upstream status/message.","Ensure ai_model_id is an embedding model (e.g. 'mistral-embed'), not a chat model.","Filter empty/whitespace strings from `texts` before calling; chunk very long inputs.","Retry with backoff on 429/timeout."],"exampleFix":"# before\nvecs = await svc.generate_embeddings(texts)\n\n# after\ntexts = [t for t in texts if t and t.strip()]\ntry:\n    vecs = await svc.generate_embeddings(texts)\nexcept ServiceResponseException as e:\n    raise RuntimeError(f\"Mistral embedding upstream error: {e.__cause__!r}\") from e","handlingStrategy":"retry","validationCode":"texts = [t for t in texts if t and t.strip()]\nassert texts, 'no non-empty texts to embed'\nassert svc.ai_model_id and 'embed' in svc.ai_model_id.lower(), 'use an embedding model id'","typeGuard":"from semantic_kernel.exceptions import ServiceResponseException\n\ndef is_mistral_embed_error(e: BaseException) -> bool:\n    return isinstance(e, ServiceResponseException) and 'failed to complete the embedding request' in str(e)","tryCatchPattern":"import asyncio\nfrom semantic_kernel.exceptions import ServiceResponseException\nasync def embed_with_retry(svc, texts, attempts=3):\n    last = None\n    for i in range(attempts):\n        try:\n            return await svc.generate_embeddings(texts)\n        except ServiceResponseException as e:\n            last = e\n            if e.__cause__ and getattr(e.__cause__, 'status_code', None) == 429:\n                await asyncio.sleep(2 ** i)\n                continue\n            raise\n    raise last","preventionTips":["Filter empty/whitespace strings before embedding.","Use an embedding model id, not a chat model id.","Retry transient 429/timeout; surface __cause__ for hard errors.","Batch large inputs to stay under Mistral limits."],"tags":["mistral-ai","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"}