{"record":{"id":"b168adc60e671d8e","repo":"spring-projects/spring-ai","slug":"failed-to-create-index-b168ad","errorCode":null,"errorMessage":"Failed to create Index","messagePattern":"Failed to create Index","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":568,"sourceCode":"\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());\n\t\t}\n\t}\n\n\tint embeddingDimensions() {\n\t\tif (this.embeddingDimension != INVALID_EMBEDDING_DIMENSION) {\n\t\t\treturn this.embeddingDimension;\n\t\t}\n\t\ttry {\n\t\t\tint embeddingDimensions = this.embeddingModel.dimensions();\n\t\t\tif (embeddingDimensions > 0) {\n\t\t\t\treturn embeddingDimensions;\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\"Failed to obtain the embedding dimensions from the embedding model and fall backs to default: \"\n\t\t\t\t\t\t\t\t+ this.embeddingDimension,","sourceCodeStart":550,"sourceCodeEnd":586,"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#L550-L586","documentation":"createIndex builds a vector index on the embedding field and throws a plain RuntimeException(\"Failed to create Index\") when the createIndex RPC returns an exception. Without the index, similarity search cannot run efficiently or at all.","triggerScenarios":"Called by createCollection during initialization when milvusClient.createIndex fails: invalid indexParameters JSON, unsupported IndexType/MetricType combination for the Milvus version, or wrong embedding field name.","commonSituations":"Index parameters JSON (e.g. {\"nlist\":16384}) malformed; HNSW/IVF metric type not supported by the deployed Milvus; custom metricType/indexType config values invalid.","solutions":["Read the cause exception for the Milvus status message.","Validate the indexParameters JSON string is well-formed and matches the index type.","Ensure the configured IndexType/MetricType combination is supported by your Milvus server version.","Confirm the embedding field name matches the schema created in createCollection.","Retry index creation after collection state settles (SyncMode is false, creation is async)."],"exampleFix":"// before\n.indexParameters(\"{ 'nlist': }\") // malformed JSON\n// after\n.indexParameters(\"{ 'nlist': 16384 }\")","handlingStrategy":"validation","validationCode":"// validate index parameters JSON before configuring the store\nString params = \"{ \\\"nlist\\\": 16384 }\";\ntry {\n    new ObjectMapper().readTree(params); // throws if malformed\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Invalid indexParameters JSON\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    MilvusVectorStore store = MilvusVectorStore.builder(milvusClient)\n        .indexType(IndexType.IVF_FLAT).metricType(MetricType.COSINE)\n        .indexParameters(\"{ \\\"nlist\\\": 16384 }\").build();\n} catch (RuntimeException e) {\n    logger.error(\"Index creation failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());\n}","preventionTips":["Validate indexParameters JSON syntax before startup.","Confirm IndexType/MetricType combination is supported by your Milvus version.","Keep embedding field name consistent between schema and index creation.","Remember SyncMode is false; allow time for async index build before searching."],"tags":["milvus","index","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"}