{"record":{"id":"0a42ef64f42329ff","repo":"spring-projects/spring-ai","slug":"embeddingmodel-must-be-provided","errorCode":null,"errorMessage":"EmbeddingModel must be provided","messagePattern":"EmbeddingModel must be provided","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-redis-semantic-cache/src/main/java/org/springframework/ai/vectorstore/redis/cache/semantic/DefaultSemanticCache.java","lineNumber":536,"sourceCode":"\t\t}\n\n\t\tpublic Builder prefix(String prefix) {\n\t\t\tthis.prefix = prefix;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder jedisClient(RedisClient jedisClient) {\n\t\t\tthis.jedisClient = jedisClient;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic DefaultSemanticCache build() {\n\t\t\tif (this.vectorStore == null) {\n\t\t\t\tif (this.jedisClient == null) {\n\t\t\t\t\tthrow new IllegalStateException(\"Either vectorStore or jedisClient must be provided\");\n\t\t\t\t}\n\t\t\t\tif (this.embeddingModel == null) {\n\t\t\t\t\tthrow new IllegalStateException(\"EmbeddingModel must be provided\");\n\t\t\t\t}\n\t\t\t\tthis.vectorStore = RedisVectorStore.builder(this.jedisClient, this.embeddingModel)\n\t\t\t\t\t.indexName(this.indexName)\n\t\t\t\t\t.prefix(this.prefix)\n\t\t\t\t\t.metadataFields(MetadataField.text(\"response\"), MetadataField.text(\"response_text\"),\n\t\t\t\t\t\t\tMetadataField.numeric(\"ttl\"), MetadataField.tag(\"context_hash\"))\n\t\t\t\t\t.initializeSchema(true)\n\t\t\t\t\t.build();\n\t\t\t\tif (this.vectorStore instanceof RedisVectorStore redisStore) {\n\t\t\t\t\tredisStore.afterPropertiesSet();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new DefaultSemanticCache(this.vectorStore, this.similarityThreshold, this.indexName, this.prefix,\n\t\t\t\t\tthis.useDistanceThreshold);\n\t\t}\n\n\t}\n","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-redis-semantic-cache/src/main/java/org/springframework/ai/vectorstore/redis/cache/semantic/DefaultSemanticCache.java#L518-L554","documentation":"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.","triggerScenarios":"DefaultSemanticCache.builder().jedisClient(jedis).build() without .embeddingModel(...), or passing a null EmbeddingModel bean.","commonSituations":"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.","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"],"exampleFix":"// before\nDefaultSemanticCache.builder().jedisClient(jedis).build();\n// after\nDefaultSemanticCache.builder().jedisClient(jedis).embeddingModel(new OpenAiEmbeddingModel(api)).build();","handlingStrategy":"validation","validationCode":"if (embeddingModel == null) throw new IllegalStateException(\"EmbeddingModel must be provided to DefaultSemanticCache.builder()\");","typeGuard":"static boolean hasEmbeddingModel(EmbeddingModel m) { return m != null; }","tryCatchPattern":"try { cache = DefaultSemanticCache.builder().jedisClient(jedis).embeddingModel(model).build(); } catch (IllegalStateException e) { /* check bean wiring */ }","preventionTips":["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"],"tags":["redis","semantic-cache","embedding","configuration","spring-ai"],"backgroundTag":"missing-required-argument","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}