{"record":{"id":"21052894b4236539","repo":"spring-projects/spring-ai","slug":"either-vectorstore-or-jedisclient-must-be-provided","errorCode":null,"errorMessage":"Either vectorStore or jedisClient must be provided","messagePattern":"Either vectorStore or jedisClient 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":533,"sourceCode":"\t\tpublic Builder indexName(String indexName) {\n\t\t\tthis.indexName = indexName;\n\t\t\treturn this;\n\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}","sourceCodeStart":515,"sourceCodeEnd":551,"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#L515-L551","documentation":"DefaultSemanticCache.Builder.build() requires at least one of a pre-built vectorStore or a raw jedisClient. If neither is set, it cannot construct the backing RedisVectorStore and throws IllegalStateException 'Either vectorStore or jedisClient must be provided'. This is builder-time configuration validation, failing fast before the cache is used.","triggerScenarios":"Calling DefaultSemanticCache.builder().build() without ever calling .vectorStore(...) or .jedisClient(...) on the builder.","commonSituations":"Copy-pasting builder code and omitting the Redis connection; constructing the cache in a context where the Jedis bean was not injected (null dependency).","solutions":["Provide a JedisClient: DefaultSemanticCache.builder().jedisClient(jedis)...","Or provide an already-configured RedisVectorStore via .vectorStore(redisVectorStore)","Ensure the Jedis bean is injected and non-null where the builder is invoked","Fail fast in your own config with a clear message if the connection bean is missing"],"exampleFix":"// before\nDefaultSemanticCache.builder().build();\n// after\nDefaultSemanticCache.builder().jedisClient(jedisPooled).embeddingModel(model).build();","handlingStrategy":"validation","validationCode":"if (jedisClient == null && vectorStore == null) throw new IllegalStateException(\"Provide either jedisClient or vectorStore to DefaultSemanticCache.builder()\");","typeGuard":"static boolean canBuild(DefaultSemanticCache.Builder b) { return b != null; } // ensure dependencies injected before building","tryCatchPattern":"try { cache = DefaultSemanticCache.builder().build(); } catch (IllegalStateException e) { /* fail startup with actionable message */ }","preventionTips":["Always chain .jedisClient(...) or .vectorStore(...) before build()","Assert required beans are non-null in your Spring @Configuration","Build the cache in one well-tested factory method"],"tags":["redis","semantic-cache","builder","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"}