{"record":{"id":"ccf898ff84132587","repo":"spring-projects/spring-ai","slug":"failed-to-create-collection","errorCode":null,"errorMessage":"Failed to create collection","messagePattern":"Failed to create collection","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java","lineNumber":550,"sourceCode":"\t\t\t.build();\n\n\t\tCreateCollectionParam createCollectionReq = CreateCollectionParam.newBuilder()\n\t\t\t.withDatabaseName(databaseName)\n\t\t\t.withCollectionName(collectionName)\n\t\t\t.withDescription(\"Spring AI Vector Store\")\n\t\t\t.withConsistencyLevel(ConsistencyLevelEnum.STRONG)\n\t\t\t.withShardsNum(2)\n\t\t\t.withSchema(CollectionSchemaParam.newBuilder()\n\t\t\t\t.addFieldType(docIdFieldType)\n\t\t\t\t.addFieldType(contentFieldType)\n\t\t\t\t.addFieldType(metadataFieldType)\n\t\t\t\t.addFieldType(embeddingFieldType)\n\t\t\t\t.build())\n\t\t\t.build();\n\n\t\tR<RpcStatus> collectionStatus = this.milvusClient.createCollection(createCollectionReq);\n\t\tif (collectionStatus.getException() != null) {\n\t\t\tthrow new RuntimeException(\"Failed to create collection\", collectionStatus.getException());\n\t\t}\n\n\t}\n\n\tvoid createIndex(String databaseName, String collectionName, String embeddingFieldName, IndexType indexType,\n\t\t\tMetricType metricType, String indexParameters) {\n\t\tR<RpcStatus> indexStatus = this.milvusClient.createIndex(CreateIndexParam.newBuilder()\n\t\t\t.withDatabaseName(databaseName)\n\t\t\t.withCollectionName(collectionName)\n\t\t\t.withFieldName(embeddingFieldName)\n\t\t\t.withIndexType(indexType)\n\t\t\t.withMetricType(metricType)\n\t\t\t.withExtraParam(indexParameters)\n\t\t\t.withSyncMode(Boolean.FALSE)\n\t\t\t.build());\n\n\t\tif (indexStatus.getException() != null) {\n\t\t\tthrow new RuntimeException(\"Failed to create Index\", indexStatus.getException());","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java#L532-L568","documentation":"createCollection calls milvusClient.createCollection and throws a plain RuntimeException(\"Failed to create collection\") when the RPC response carries an exception. The collection schema (ID, content, metadata, embedding fields) could not be created on the Milvus server.","triggerScenarios":"Called from afterPropertiesSet (initializeSchema) or shouldFilterWithCustomMetadataFieldName when creating the collection fails: collection already exists with a different schema, invalid field types, reserved/illegal collection name, or server-side error.","commonSituations":"Collection already exists from a prior run with an incompatible schema; illegal characters in collection name; Milvus server version mismatch on supported field types.","solutions":["Read the cause exception for the exact Milvus error status.","Check whether the collection already exists with a conflicting schema — drop it or reuse it.","Verify the collection name is valid (letters, digits, underscores).","Confirm field types (JSON metadata field support) match your Milvus server version.","Ensure the target database exists."],"exampleFix":"// before\n// initializeSchema(true) fails because collection exists with old schema\n// after\n// drop the outdated collection once, then let the store recreate it\nmilvusClient.dropCollection(DropCollectionParam.newBuilder().withCollectionName(\"vector_store\").build());\nMilvusVectorStore.builder(milvusClient).initializeSchema(true).build();","handlingStrategy":"validation","validationCode":"// detect a pre-existing collection with a conflicting schema before initializeSchema runs\nboolean exists = milvusClient.hasCollection(HasCollectionParam.newBuilder()\n        .withCollectionName(collectionName).build()).getData(Boolean.FALSE);\nif (exists) {\n    // describe and compare schema fields, or drop if incompatible\n    milvusClient.describeCollection(DescribeCollectionParam.newBuilder().withCollectionName(collectionName).build());\n}","typeGuard":null,"tryCatchPattern":"try {\n    MilvusVectorStore store = MilvusVectorStore.builder(milvusClient).initializeSchema(true).build();\n} catch (RuntimeException e) {\n    logger.error(\"Collection creation failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());\n}","preventionTips":["Drop stale collections from prior schema versions before re-initializing.","Use valid collection names (letters, digits, underscores only).","Confirm your Milvus server version supports the JSON metadata field type.","Ensure the target database exists before initialization."],"tags":["milvus","collection","schema","initialization"],"backgroundTag":"database-write-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}