{"record":{"id":"9d5d22b7065cdc09","repo":"spring-projects/spring-ai","slug":"could-not-initialize-redis-schema","errorCode":null,"errorMessage":"Could not initialize Redis schema","messagePattern":"Could not initialize Redis schema","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"memory-repositories/spring-ai-model-chat-memory-repository-redis/src/main/java/org/springframework/ai/chat/memory/repository/redis/RedisChatMemoryRepository.java","lineNumber":462,"sourceCode":"\t\t\t\t}\n\n\t\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\t\tlogger.debug(\"Created Redis search index '\" + this.config.getIndexName() + \"' with \"\n\t\t\t\t\t\t\t+ schemaFields.size() + \" schema fields\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telse if (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Redis search index '\" + this.config.getIndexName() + \"' already exists\");\n\t\t\t}\n\t\t}\n\n\t\tcatch (Exception e) {\n\t\t\tif (logger.isErrorEnabled()) {\n\t\t\t\tlogger.error(\"Failed to initialize Redis schema: \" + e.getMessage());\n\t\t\t}\n\t\t\tlogger.debug(\"Error details\", e);\n\t\t\tthrow new IllegalStateException(\"Could not initialize Redis schema\", e);\n\t\t}\n\t}\n\n\tprivate String createKey(String conversationId, long timestamp) {\n\t\treturn String.format(\"%s%s:%d\", this.config.getKeyPrefix(), escapeKey(conversationId), timestamp);\n\t}\n\n\tprivate Map<String, Object> createMessageDocument(String conversationId, Message message) {\n\t\tMap<String, Object> documentMap = new HashMap<>();\n\t\tdocumentMap.put(\"type\", message.getMessageType().toString());\n\t\tdocumentMap.put(\"content\", message.getText());\n\t\tdocumentMap.put(\"conversation_id\", conversationId);\n\t\tdocumentMap.put(\"timestamp\", Instant.now().toEpochMilli());\n\n\t\t// Store metadata/properties\n\t\tif (message.getMetadata() != null && !message.getMetadata().isEmpty()) {\n\t\t\tdocumentMap.put(\"metadata\", message.getMetadata());\n\t\t}","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/memory-repositories/spring-ai-model-chat-memory-repository-redis/src/main/java/org/springframework/ai/chat/memory/repository/redis/RedisChatMemoryRepository.java#L444-L480","documentation":"RedisChatMemoryRepository.initializeSchema() wraps any exception raised during schema initialization (ftCreate, index drops, schema setup) and rethrows it as IllegalStateException with the cause attached. It signals the Redis search index could not be set up, so the repository cannot function.","triggerScenarios":"Any Exception during init: connection failures to Redis, missing RediSearch module (unknown command FT.CREATE), auth failures, or the inner 'Failed to create index' IllegalStateException from the ftCreate response check.","commonSituations":"Connecting to vanilla Redis without RediSearch; wrong host/port/password; network/firewall blocking the connection; managed Redis that doesn't support FT commands.","solutions":["Inspect the logged cause ('Failed to initialize Redis schema: ...') for the root error","Verify the Redis instance has the RediSearch module (run MODULE LIST or FT._LIST)","Check host, port, password and TLS settings in the Redis connection config","Restart the application after fixing connectivity — init runs at repository construction"],"exampleFix":"// before\nJedisPooled jedis = new JedisPooled(\"localhost\", 6379); // vanilla Redis, no RediSearch\n// after\n// use redis-stack or a RediSearch-enabled endpoint\nJedisPooled jedis = new JedisPooled(\"redis-stack-host\", 6379);","handlingStrategy":"try-catch","validationCode":"try { jedis.ft._list(); } catch (JedisDataException e) { throw new IllegalStateException(\"RediSearch module not available\", e); }","typeGuard":null,"tryCatchPattern":"try { repo = RedisChatMemoryRepository.builder()...build(); }\ncatch (IllegalStateException e) {\n    logger.error(\"Redis schema init failed; check RediSearch module and connectivity\", e);\n    throw e;\n}","preventionTips":["Deploy with Redis Stack or a RediSearch-enabled managed instance","Verify host/port/password/TLS in a health check before app startup","Pin and test module availability in CI integration tests"],"tags":["redis","schema-initialization","connection","redisearch"],"backgroundTag":"module-init-failed","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"}