{"record":{"id":"be7271e242e980b2","repo":"spring-projects/spring-ai","slug":"failed-to-obtain-the-embedding-dimensions-from-the-be7271","errorCode":null,"errorMessage":"Failed to obtain the embedding dimensions from the embedding model and fall backs to default: ","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-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java","lineNumber":301,"sourceCode":"\t\tcatch (Exception e) {\n\t\t\tlogger.error(\"Failed to search documents\", e);\n\t\t\treturn List.of();\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// ---------------------------------------------------------------------------------\n\t// Initialization\n\t// ---------------------------------------------------------------------------------\n\t@Override\n\tpublic void afterPropertiesSet() {\n\t\tif (this.initializeSchema) {\n\t\t\tthis.createCollection();\n\t\t}\n\t}\n","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java#L283-L319","documentation":"This is a warning log (not a thrown exception) emitted by TypesenseVectorStore.embeddingDimensions() when it cannot determine the embedding model's vector dimensionality. The store first checks a configured embeddingDimension; if unset, it calls embeddingModel.dimensions(). If that call throws or returns <= 0, the store logs this warning and falls back to OPENAI_EMBEDDING_DIMENSION_SIZE (1536), which may not match the actual embedding model.","triggerScenarios":"Calling createCollection (via afterPropertiesSet when initializeSchema=true) while the configured EmbeddingModel.dimensions() throws — e.g. the embedding provider is unreachable, the API key is missing/invalid, the remote dimensions endpoint fails — or dimensions() returns 0 or a negative value because the model does not report its dimensionality.","commonSituations":"Misconfigured or missing embedding API key (e.g. OpenAI key not set), network/auth failure to the embedding provider at startup, using an embedding model whose dimensions() implementation is not supported/returns 0, or building the vector store with initializeSchema enabled before the embedding client is reachable. The collection is then created with 1536 dimensions, causing later insert failures if the real model has a different size (e.g. 384, 768, 3072).","solutions":["Set the embedding dimension explicitly via TypesenseVectorStore.builder().embeddingDimension(<n>) so no remote lookup is needed.","Fix the root cause in the embedding model: verify API key/credentials and network access so embeddingModel.dimensions() succeeds.","Ensure the EmbeddingModel implementation actually reports dimensions (> 0); upgrade spring-ai or the model integration if it returns 0.","If the fallback 1536 already matches your model, you can ignore the warning, but verify the Typesense collection schema dimension matches your vectors.","Disable auto schema creation (initializeSchema=false) and create the collection yourself with the correct dimensions."],"exampleFix":"// before\nTypesenseVectorStore store = TypesenseVectorStore.builder(client, embeddingModel)\n    .initializeSchema(true)\n    .build(); // dimensions() fails at startup -> warning + fallback to 1536\n\n// after\nTypesenseVectorStore store = TypesenseVectorStore.builder(client, embeddingModel)\n    .embeddingDimension(768) // explicit, matches your embedding model\n    .initializeSchema(true)\n    .build();","handlingStrategy":"fallback","validationCode":"// before building the store, verify dimensions() works and is positive\nint dims;\ntry { dims = embeddingModel.dimensions(); }\ncatch (Exception e) { dims = -1; }\nif (dims <= 0) {\n    throw new IllegalStateException(\"Embedding model does not report dimensions; set embeddingDimension explicitly\");\n}","typeGuard":"boolean hasUsableDimensions(EmbeddingModel model) {\n    try {\n        return model.dimensions() > 0;\n    } catch (Exception e) {\n        return false;\n    }\n}","tryCatchPattern":"// the store itself already try-catches; wrap store init if you create collections eagerly\ntry {\n    vectorStore.afterPropertiesSet(); // triggers createCollection -> embeddingDimensions()\n}\ncatch (Exception e) {\n    logger.warn(\"Typesense collection creation failed; check embedding model availability\", e);\n}","preventionTips":["Always pass an explicit embeddingDimension matching your embedding model instead of relying on runtime discovery.","Keep initializeSchema=false in production and manage the Typesense collection schema in deployment tooling.","Verify embedding provider credentials/connectivity during a startup health check before constructing the vector store.","Confirm the fallback (1536) matches your model's output size; if not, treat this warning as actionable.","After startup, check the created collection's vector field dimension against embeddingModel.dimensions()."],"tags":["java","spring-ai","vector-store","typesense","embedding-model","configuration"],"backgroundTag":"missing-config-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}