{"record":{"id":"f0338f1446499973","repo":"spring-projects/spring-ai","slug":"failed-to-obtain-the-embedding-dimensions-from-the","errorCode":null,"errorMessage":"Failed to obtain the embedding dimensions from the embedding model and fall backs to default: ${OPENAI_EMBEDDING_DIMENSION_SIZE}","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-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java","lineNumber":446,"sourceCode":"\t\t\treturn this.schemaName + \".\" + this.vectorTableName;\n\t\t}\n\t\treturn this.vectorTableName;\n\t}\n\n\tint embeddingDimensions() {\n\t\t// The manually set dimensions have precedence over the computed one.\n\t\tif (this.dimensions > 0) {\n\t\t\treturn this.dimensions;\n\t\t}\n\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\tlogger.warn(\"Failed to obtain the embedding dimensions from the embedding model and fall backs to\"\n\t\t\t\t\t+ \" default:\" + OPENAI_EMBEDDING_DIMENSION_SIZE, e);\n\t\t}\n\t\treturn OPENAI_EMBEDDING_DIMENSION_SIZE;\n\t}\n\n\t@Override\n\tpublic VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName) {\n\n\t\tVectorStoreObservationContext.Builder builder = VectorStoreObservationContext\n\t\t\t.builder(VectorStoreProvider.MARIADB.value(), operationName)\n\t\t\t.collectionName(this.vectorTableName)\n\t\t\t.dimensions(this.embeddingDimensions())\n\t\t\t.similarityMetric(getSimilarityMetric());\n\t\tif (this.schemaName != null) {\n\t\t\tbuilder.namespace(this.schemaName);\n\t\t}\n\t\treturn builder;\n\t}","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java#L428-L464","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nMariaDbVectorStore.builder(jdbcTemplate, embeddingModel).build();\n\n// after\nMariaDbVectorStore.builder(jdbcTemplate, embeddingModel)\n    .withDimensions(768) // match your embedding model\n    .build();","handlingStrategy":"validation","validationCode":"int dims = embeddingModel.dimensions();\nif (dims <= 0) {\n    throw new IllegalStateException(\"Embedding model did not report a positive dimension; set it explicitly in the builder\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    store.afterPropertiesSet();\n} catch (Exception e) {\n    logger.error(\"MariaDB vector store init fell back to default dimensions\", e);\n}","preventionTips":["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"],"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"}