microsoft/semantic-kernel · error · ServiceResponseException
{type(self)} service failed to complete the embedding reques
Error message
{type(self)} service failed to complete the embedding request. What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_text_embedding.py:102
texts: list[str],
settings: "PromptExecutionSettings | None" = None,
**kwargs: Any,
) -> ndarray:
embedding_response = await self.generate_raw_embeddings(texts, settings, **kwargs)
return array(embedding_response)
@override
async def generate_raw_embeddings(
self,
texts: list[str],
settings: "PromptExecutionSettings | None" = None,
**kwargs: Any,
) -> Any:
"""Generate embeddings from the Mistral AI service."""
try:
embedding_response = await self.async_client.embeddings.create_async(model=self.ai_model_id, inputs=texts)
except Exception as ex:
raise ServiceResponseException(
f"{type(self)} service failed to complete the embedding request.",
ex,
) from ex
if isinstance(embedding_response, EmbeddingResponse):
return [item.embedding for item in embedding_response.data]
return []
View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
vecs = await svc.generate_embeddings(texts)
# after
texts = [t for t in texts if t and t.strip()]
try:
vecs = await svc.generate_embeddings(texts)
except ServiceResponseException as e:
raise RuntimeError(f"Mistral embedding upstream error: {e.__cause__!r}") from e Defensive patterns
Strategy: retry
Validate before calling
texts = [t for t in texts if t and t.strip()] assert texts, 'no non-empty texts to embed' assert svc.ai_model_id and 'embed' in svc.ai_model_id.lower(), 'use an embedding model id'
Type guard
from semantic_kernel.exceptions import ServiceResponseException
def is_mistral_embed_error(e: BaseException) -> bool:
return isinstance(e, ServiceResponseException) and 'failed to complete the embedding request' in str(e) Try / catch
import asyncio
from semantic_kernel.exceptions import ServiceResponseException
async def embed_with_retry(svc, texts, attempts=3):
last = None
for i in range(attempts):
try:
return await svc.generate_embeddings(texts)
except ServiceResponseException as e:
last = e
if e.__cause__ and getattr(e.__cause__, 'status_code', None) == 429:
await asyncio.sleep(2 ** i)
continue
raise
raise last Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {type(self)} service failed to generate embeddings
- {type(self)} service failed to complete the chat
- The API key is required when use_vertexai is False.
- {type(self)} service failed to complete the prompt
- Failed to validate Mistral AI settings: {e}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/21572aef65ceb75f.
Report an issue: GitHub.