{"record":{"id":"1c0a664dda83ac46","repo":"microsoft/semantic-kernel","slug":"upsert-failed-due-to-e","errorCode":null,"errorMessage":"Upsert failed due to: {e}","messagePattern":"Upsert failed due to: (.+?)","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py","lineNumber":299,"sourceCode":"            Exception: Collection doesnt exist.\n            e: Failed to upsert a record.\n\n        Returns:\n            List[str]: A list of inserted ID's.\n        \"\"\"\n        # Check if the collection exists.\n        if collection_name not in utility.list_collections():\n            logger.debug(f\"Collection {collection_name} does not exist, cannot insert.\")\n            raise ServiceResourceNotFoundError(f\"Collection {collection_name} does not exist, cannot insert.\")\n        # Convert the records to dicts\n        insert_list = [memoryrecord_to_milvus_dict(record) for record in records]\n        try:\n            ids = self.collections[collection_name].upsert(data=insert_list).primary_keys\n            self.collections[collection_name].flush()\n            return ids\n        except Exception as e:\n            logger.debug(f\"Upsert failed due to: {e}\")\n            raise ServiceResponseException(f\"Upsert failed due to: {e}\") from e\n\n    async def get(self, collection_name: str, key: str, with_embedding: bool) -> MemoryRecord:\n        \"\"\"Get the MemoryRecord corresponding to the key.\n\n        Args:\n            collection_name (str): The collection to get from.\n            key (str): The ID to grab.\n            with_embedding (bool): Whether to include the embedding in the results.\n\n        Returns:\n            MemoryRecord: The MemoryRecord for the key.\n        \"\"\"\n        res = await self.get_batch(collection_name=collection_name, keys=[key], with_embeddings=with_embedding)\n        return res[0]\n\n    async def get_batch(self, collection_name: str, keys: list[str], with_embeddings: bool) -> list[MemoryRecord]:\n        \"\"\"Get the MemoryRecords corresponding to the keys.\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py#L281-L317","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nids = await store.upsert_batch('docs', records)  # ServiceResponseException: Upsert failed due to: ...\n// after\ntry:\n    ids = await store.upsert_batch('docs', records)\nexcept ServiceResponseException as e:\n    logging.error('Milvus upsert failed: %s', e)\n    raise  # or handle/retry depending on root cause","handlingStrategy":"try-catch","validationCode":"def records_match_schema(records, expected_dim: int) -> bool:\n    return all(r.embedding is not None and len(r.embedding) == expected_dim for r in records)\n\nif not records_match_schema(records, expected_dim=1536):\n    raise ValueError('Record embedding dimension mismatch')","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResponseException\n\ntry:\n    ids = await store.upsert_batch('docs', records)\nexcept ServiceResponseException as e:\n    logging.error('Milvus upsert failed: %s', e)\n    if 'dimension' in str(e).lower():\n        # schema mismatch — do not retry blindly\n        raise\n    raise  # or implement backoff retry for transient errors","preventionTips":["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."],"tags":["milvus","upsert","service-response","runtime","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}