microsoft/semantic-kernel · error · ServiceResponseException
Upsert failed due to: {e}
Error message
Upsert failed due to: {e} What it means
Raised as a ServiceResponseException in MilvusMemoryStore.upsert_batch when the underlying self.collections[collection_name].upsert() or .flush() call throws any Exception. The original exception is chained via 'from e' and its message is interpolated, so the wrapped text reveals the real Milvus SDK error.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py:299
Exception: Collection doesnt exist.
e: Failed to upsert a record.
Returns:
List[str]: A list of inserted ID's.
"""
# Check if the collection exists.
if collection_name not in utility.list_collections():
logger.debug(f"Collection {collection_name} does not exist, cannot insert.")
raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist, cannot insert.")
# Convert the records to dicts
insert_list = [memoryrecord_to_milvus_dict(record) for record in records]
try:
ids = self.collections[collection_name].upsert(data=insert_list).primary_keys
self.collections[collection_name].flush()
return ids
except Exception as e:
logger.debug(f"Upsert failed due to: {e}")
raise ServiceResponseException(f"Upsert failed due to: {e}") from e
async def get(self, collection_name: str, key: str, with_embedding: bool) -> MemoryRecord:
"""Get the MemoryRecord corresponding to the key.
Args:
collection_name (str): The collection to get from.
key (str): The ID to grab.
with_embedding (bool): Whether to include the embedding in the results.
Returns:
MemoryRecord: The MemoryRecord for the key.
"""
res = await self.get_batch(collection_name=collection_name, keys=[key], with_embeddings=with_embedding)
return res[0]
async def get_batch(self, collection_name: str, keys: list[str], with_embeddings: bool) -> list[MemoryRecord]:
"""Get the MemoryRecords corresponding to the keys.
View on GitHub (pinned to c028a0c7dc)
Solutions
- Read the interpolated {e} message to identify the root cause (dimension mismatch, connection error, etc.).
- Ensure record embeddings match the collection's declared dimension.
- Check Milvus server health and network connectivity; retry on transient connection errors.
- Verify pymilvus version compatibility with the Milvus server version.
Example fix
// before
ids = await store.upsert_batch('docs', records) # ServiceResponseException: Upsert failed due to: ...
// after
try:
ids = await store.upsert_batch('docs', records)
except ServiceResponseException as e:
logging.error('Milvus upsert failed: %s', e)
raise # or handle/retry depending on root cause Defensive patterns
Strategy: try-catch
Validate before calling
def records_match_schema(records, expected_dim: int) -> bool:
return all(r.embedding is not None and len(r.embedding) == expected_dim for r in records)
if not records_match_schema(records, expected_dim=1536):
raise ValueError('Record embedding dimension mismatch') Try / catch
from semantic_kernel.exceptions import ServiceResponseException
try:
ids = await store.upsert_batch('docs', records)
except ServiceResponseException as e:
logging.error('Milvus upsert failed: %s', e)
if 'dimension' in str(e).lower():
# schema mismatch — do not retry blindly
raise
raise # or implement backoff retry for transient errors Prevention
- Ensure record embedding dimensions match the collection schema.
- Check Milvus server health and network before bulk upserts.
- Verify pymilvus version compatibility with the server.
- Read the chained exception message to classify transient vs permanent failures.
When it happens
Trigger: Milvus upsert fails due to: schema/field mismatch (e.g. embedding dimension differs from collection schema), data type errors, connection drops during flush, server-side errors, or SDK version incompatibilities. The broad 'except Exception' captures all of these.
Common situations: Embedding dimension mismatch between the record and the collection schema. Milvus server timeout or network interruption during flush. pymilvus version upgrade changing the upsert() return shape. Passing records with None/null required fields.
Related errors
- Get failed due to: {e}
- Remove failed due to: {e}
- Search failed: {e}
- Collection {collection_name} does not exist, cannot insert.
- Python nodes are not supported in the dotnet runtime.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/1c0a664dda83ac46.
Report an issue: GitHub.