spring-projects/spring-ai · warning
Failed to obtain the embedding dimensions from the…
Error message
Failed to obtain the embedding dimensions from the embedding model and fall backs to default: ${embeddingDimension} What it means
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.
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
Example fix
// before
MilvusVectorStore.builder(milvusServiceClient, embeddingModel).build();
// after
MilvusVectorStore.builder(milvusServiceClient, embeddingModel)
.withDimension(384) // e.g. all-MiniLM-L6-v2
.build(); Defensive patterns
Strategy: validation
Validate before calling
int dims = embeddingModel.dimensions();
if (dims <= 0) {
throw new IllegalStateException("Set Milvus withDimension(n) explicitly; model reported " + dims);
} Try / catch
try {
milvusVectorStore.afterPropertiesSet();
} catch (Exception e) {
logger.error("Milvus store init used fallback dimension", e);
} Prevention
- 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
When it happens
Trigger: Creating/initializing the Milvus store (embeddingFieldType or dim call paths) when embeddingModel.dimensions() throws — remote embedding service unavailable, model misconfigured, or returns <= 0.
Common situations: Startup without network access to the embedding provider; using a local model (Ollama, transformers) that lacks a dimensions() implementation; wrong API key configured.
Related errors
- Failed to obtain the embedding dimensions from the…
- Failed to obtain the embedding dimensions from the…
- ai.onnxruntime.OrtException
- Could not parse text search score
- Database product name is null or empty, defaulting to…
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/ade546b2f310fc95.
Report an issue: GitHub.
Appendix: source
Thrown at vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java:584
if (indexStatus.getException() != null) {
throw new RuntimeException("Failed to create Index", indexStatus.getException());
}
}
int embeddingDimensions() {
if (this.embeddingDimension != INVALID_EMBEDDING_DIMENSION) {
return this.embeddingDimension;
}
try {
int embeddingDimensions = this.embeddingModel.dimensions();
if (embeddingDimensions > 0) {
return embeddingDimensions;
}
}
catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn(
"Failed to obtain the embedding dimensions from the embedding model and fall backs to default: "
+ this.embeddingDimension,
e);
}
}
return OPENAI_EMBEDDING_DIMENSION_SIZE;
}
// used by the test as well
void dropCollection() {
R<RpcStatus> status = this.milvusClient
.releaseCollection(ReleaseCollectionParam.newBuilder().withCollectionName(this.collectionName).build());
if (status.getException() != null) {
throw new RuntimeException("Release collection failed!", status.getException());
}
View on GitHub (pinned to 98a7beda4f)