spring-projects/spring-ai · error · IllegalStateException
EmbeddingModel must be provided
Error message
EmbeddingModel must be provided
What it means
When the builder has no vectorStore, it constructs one from jedisClient + embeddingModel; a null embeddingModel makes construction impossible, so build() throws IllegalStateException 'EmbeddingModel must be provided'. The embedding model is required to vectorize queries for semantic cache lookup.
Source
Thrown at vector-stores/spring-ai-redis-semantic-cache/src/main/java/org/springframework/ai/vectorstore/redis/cache/semantic/DefaultSemanticCache.java:536
}
public Builder prefix(String prefix) {
this.prefix = prefix;
return this;
}
public Builder jedisClient(RedisClient jedisClient) {
this.jedisClient = jedisClient;
return this;
}
public DefaultSemanticCache build() {
if (this.vectorStore == null) {
if (this.jedisClient == null) {
throw new IllegalStateException("Either vectorStore or jedisClient must be provided");
}
if (this.embeddingModel == null) {
throw new IllegalStateException("EmbeddingModel must be provided");
}
this.vectorStore = RedisVectorStore.builder(this.jedisClient, this.embeddingModel)
.indexName(this.indexName)
.prefix(this.prefix)
.metadataFields(MetadataField.text("response"), MetadataField.text("response_text"),
MetadataField.numeric("ttl"), MetadataField.tag("context_hash"))
.initializeSchema(true)
.build();
if (this.vectorStore instanceof RedisVectorStore redisStore) {
redisStore.afterPropertiesSet();
}
}
return new DefaultSemanticCache(this.vectorStore, this.similarityThreshold, this.indexName, this.prefix,
this.useDistanceThreshold);
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Add .embeddingModel(embeddingModel) to the builder chain
- Ensure an EmbeddingModel bean exists and is injected (e.g. OpenAiEmbeddingModel with an API key)
- Alternatively supply a fully built vectorStore (which still needs a model elsewhere, but satisfies this check)
- Fail fast at startup by validating the model bean with an @PostConstruct or configuration check
Example fix
// before DefaultSemanticCache.builder().jedisClient(jedis).build(); // after DefaultSemanticCache.builder().jedisClient(jedis).embeddingModel(new OpenAiEmbeddingModel(api)).build();
Defensive patterns
Strategy: validation
Validate before calling
if (embeddingModel == null) throw new IllegalStateException("EmbeddingModel must be provided to DefaultSemanticCache.builder()"); Type guard
static boolean hasEmbeddingModel(EmbeddingModel m) { return m != null; } Try / catch
try { cache = DefaultSemanticCache.builder().jedisClient(jedis).embeddingModel(model).build(); } catch (IllegalStateException e) { /* check bean wiring */ } Prevention
- Define a single EmbeddingModel bean and inject it explicitly
- Use constructor injection so a missing bean fails at startup, not at build()
- Validate API-key config for the backing embedding provider
When it happens
Trigger: DefaultSemanticCache.builder().jedisClient(jedis).build() without .embeddingModel(...), or passing a null EmbeddingModel bean.
Common situations: Forgetting to wire the EmbeddingModel bean (e.g. OpenAiEmbeddingModel) in Spring config; building the cache in non-Spring code without supplying a model; an optional-injection (@Autowired(required=false)) returning null.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Either vectorStore or jedisClient must be provided
- model cannot be null or empty
- At most one ToolAdvisor is allowed in the advisor chain, but
- Only outputType or outputJsonSchema can be set, not both.
- Multiple tools with the same name (%s) found in ToolCallingC
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/0a42ef64f42329ff.
Report an issue: GitHub.