spring-projects/spring-ai · warning

Failed to obtain the embedding dimensions from the embedding

Error message

Failed to obtain the embedding dimensions from the embedding model and fall backs to default: 

What it means

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.

Source

Thrown at vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java:301

		catch (Exception e) {
			logger.error("Failed to search documents", e);
			return List.of();
		}
	}

	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;
	}

	// ---------------------------------------------------------------------------------
	// Initialization
	// ---------------------------------------------------------------------------------
	@Override
	public void afterPropertiesSet() {
		if (this.initializeSchema) {
			this.createCollection();
		}
	}

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Set the embedding dimension explicitly via TypesenseVectorStore.builder().embeddingDimension(<n>) so no remote lookup is needed.
  2. Fix the root cause in the embedding model: verify API key/credentials and network access so embeddingModel.dimensions() succeeds.
  3. Ensure the EmbeddingModel implementation actually reports dimensions (> 0); upgrade spring-ai or the model integration if it returns 0.
  4. If the fallback 1536 already matches your model, you can ignore the warning, but verify the Typesense collection schema dimension matches your vectors.
  5. Disable auto schema creation (initializeSchema=false) and create the collection yourself with the correct dimensions.

Example fix

// before
TypesenseVectorStore store = TypesenseVectorStore.builder(client, embeddingModel)
    .initializeSchema(true)
    .build(); // dimensions() fails at startup -> warning + fallback to 1536

// after
TypesenseVectorStore store = TypesenseVectorStore.builder(client, embeddingModel)
    .embeddingDimension(768) // explicit, matches your embedding model
    .initializeSchema(true)
    .build();
Defensive patterns

Strategy: fallback

Validate before calling

// before building the store, verify dimensions() works and is positive
int dims;
try { dims = embeddingModel.dimensions(); }
catch (Exception e) { dims = -1; }
if (dims <= 0) {
    throw new IllegalStateException("Embedding model does not report dimensions; set embeddingDimension explicitly");
}

Type guard

boolean hasUsableDimensions(EmbeddingModel model) {
    try {
        return model.dimensions() > 0;
    } catch (Exception e) {
        return false;
    }
}

Try / catch

// the store itself already try-catches; wrap store init if you create collections eagerly
try {
    vectorStore.afterPropertiesSet(); // triggers createCollection -> embeddingDimensions()
}
catch (Exception e) {
    logger.warn("Typesense collection creation failed; check embedding model availability", e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/be7271e242e980b2. Report an issue: GitHub.