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: ${OPENAI_EMBEDDING_DIMENSION_SIZE} What it means
MariaDBVectorStore.embeddingDimensions() asks the configured EmbeddingModel for its vector dimension; if that call throws (or returns <= 0) the store logs a warning and falls back to OPENAI_EMBEDDING_DIMENSION_SIZE (1536). The table is then created with the default dimension, which will break inserts for non-OpenAI models whose dimensions differ.
Solutions
- Explicitly set the dimension in the builder (withDimensions / vectorTableName config) instead of relying on auto-detection
- Verify the embedding model bean is properly configured (API key, base URL) before the store initializes
- Check why embeddingModel.dimensions() returns <= 0 for your model and upgrade the model integration
- If the fallback already happened, drop/recreate the table with the correct vector column dimension
Example fix
// before
MariaDbVectorStore.builder(jdbcTemplate, embeddingModel).build();
// after
MariaDbVectorStore.builder(jdbcTemplate, embeddingModel)
.withDimensions(768) // match your embedding model
.build(); Defensive patterns
Strategy: validation
Validate before calling
int dims = embeddingModel.dimensions();
if (dims <= 0) {
throw new IllegalStateException("Embedding model did not report a positive dimension; set it explicitly in the builder");
} Try / catch
try {
store.afterPropertiesSet();
} catch (Exception e) {
logger.error("MariaDB vector store init fell back to default dimensions", e);
} Prevention
- Always set withDimensions(n) for non-OpenAI models
- Warm up the embedding client before store initialization
- Check API key/base URL config in integration tests
- Assert the vector column dimension matches model output in schema migration
When it happens
Trigger: Calling afterPropertiesSet / builder / dim while the embeddingModel.dimensions() call throws — e.g. embeddingModel is null, remote embedding endpoint unreachable, API key missing, or a custom model returns 0.
Common situations: Using a non-OpenAI embedding model (e.g. Ollama, Azure, HuggingFace) whose dimensions() call fails or needs network access at startup; missing API key during schema initialization.
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/f0338f1446499973.
Report an issue: GitHub.
Appendix: source
Thrown at vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java:446
return this.schemaName + "." + this.vectorTableName;
}
return this.vectorTableName;
}
int embeddingDimensions() {
// The manually set dimensions have precedence over the computed one.
if (this.dimensions > 0) {
return this.dimensions;
}
try {
int embeddingDimensions = this.embeddingModel.dimensions();
if (embeddingDimensions > 0) {
return embeddingDimensions;
}
}
catch (Exception e) {
logger.warn("Failed to obtain the embedding dimensions from the embedding model and fall backs to"
+ " default:" + OPENAI_EMBEDDING_DIMENSION_SIZE, e);
}
return OPENAI_EMBEDDING_DIMENSION_SIZE;
}
@Override
public VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName) {
VectorStoreObservationContext.Builder builder = VectorStoreObservationContext
.builder(VectorStoreProvider.MARIADB.value(), operationName)
.collectionName(this.vectorTableName)
.dimensions(this.embeddingDimensions())
.similarityMetric(getSimilarityMetric());
if (this.schemaName != null) {
builder.namespace(this.schemaName);
}
return builder;
}View on GitHub (pinned to 98a7beda4f)