{"record":{"id":"ade546b2f310fc95","repo":"spring-projects/spring-ai","slug":"failed-to-obtain-the-embedding-dimensions-from-the-ade546","errorCode":null,"errorMessage":"Failed to obtain the embedding dimensions from the embedding model and fall backs to default: ${embeddingDimension}","messagePattern":"Failed to obtain the embedding dimensions from the embedding model and fall backs to default: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java","lineNumber":584,"sourceCode":"\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,\n\t\t\t\t\t\te);\n\t\t\t}\n\t\t}\n\t\treturn OPENAI_EMBEDDING_DIMENSION_SIZE;\n\t}\n\n\t// used by the test as well\n\tvoid dropCollection() {\n\n\t\tR<RpcStatus> status = this.milvusClient\n\t\t\t.releaseCollection(ReleaseCollectionParam.newBuilder().withCollectionName(this.collectionName).build());\n\n\t\tif (status.getException() != null) {\n\t\t\tthrow new RuntimeException(\"Release collection failed!\", status.getException());\n\t\t}\n","sourceCodeStart":566,"sourceCodeEnd":602,"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#L566-L602","documentation":"MilvusVectorStore.embeddingDimensions() attempts embeddingModel.dimensions(); on exception or a non-positive value it warns and falls back to the OPENAI_EMBEDDING_DIMENSION_SIZE (1536) constant rather than the configured embeddingDimension shown in the message text. The collection schema may then be created with the wrong vector field dimension.","triggerScenarios":"Creating/initializing the Milvus store (embeddingFieldType or dim call paths) when embeddingModel.dimensions() throws — remote embedding service unavailable, model misconfigured, or returns <= 0.","commonSituations":"Startup without network access to the embedding provider; using a local model (Ollama, transformers) that lacks a dimensions() implementation; wrong API key configured.","solutions":["Set the dimension explicitly via MilvusVectorStore.builder(...).withDimension(n) so no detection is attempted","Ensure the embedding service is reachable and credentials valid before store initialization","Check that your EmbeddingModel implementation returns a positive dimension","If the collection was created with the wrong dimension, drop it and re-create after fixing configuration"],"exampleFix":"// before\nMilvusVectorStore.builder(milvusServiceClient, embeddingModel).build();\n\n// after\nMilvusVectorStore.builder(milvusServiceClient, embeddingModel)\n    .withDimension(384) // e.g. all-MiniLM-L6-v2\n    .build();","handlingStrategy":"validation","validationCode":"int dims = embeddingModel.dimensions();\nif (dims <= 0) {\n    throw new IllegalStateException(\"Set Milvus withDimension(n) explicitly; model reported \" + dims);\n}","typeGuard":null,"tryCatchPattern":"try {\n    milvusVectorStore.afterPropertiesSet();\n} catch (Exception e) {\n    logger.error(\"Milvus store init used fallback dimension\", e);\n}","preventionTips":["Always pass withDimension(n) in MilvusVectorStore.builder","Ensure embedding provider is reachable before collection creation","Test EmbeddingModel.dimensions() in unit tests with a stub","Drop and recreate the collection if it was created with the fallback dimension"],"tags":["embedding","dimensions","fallback","schema"],"backgroundTag":"unexpected-response-shape","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}