spring-projects/spring-ai · error · IllegalStateException

Could not initialize Redis schema

Error message

Could not initialize Redis schema

What it means

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.

Source

Thrown at memory-repositories/spring-ai-model-chat-memory-repository-redis/src/main/java/org/springframework/ai/chat/memory/repository/redis/RedisChatMemoryRepository.java:462

				}

				if (logger.isDebugEnabled()) {
					logger.debug("Created Redis search index '" + this.config.getIndexName() + "' with "
							+ schemaFields.size() + " schema fields");
				}
			}

			else if (logger.isDebugEnabled()) {
				logger.debug("Redis search index '" + this.config.getIndexName() + "' already exists");
			}
		}

		catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Failed to initialize Redis schema: " + e.getMessage());
			}
			logger.debug("Error details", e);
			throw new IllegalStateException("Could not initialize Redis schema", e);
		}
	}

	private String createKey(String conversationId, long timestamp) {
		return String.format("%s%s:%d", this.config.getKeyPrefix(), escapeKey(conversationId), timestamp);
	}

	private Map<String, Object> createMessageDocument(String conversationId, Message message) {
		Map<String, Object> documentMap = new HashMap<>();
		documentMap.put("type", message.getMessageType().toString());
		documentMap.put("content", message.getText());
		documentMap.put("conversation_id", conversationId);
		documentMap.put("timestamp", Instant.now().toEpochMilli());

		// Store metadata/properties
		if (message.getMetadata() != null && !message.getMetadata().isEmpty()) {
			documentMap.put("metadata", message.getMetadata());
		}

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Inspect the logged cause ('Failed to initialize Redis schema: ...') for the root error
  2. Verify the Redis instance has the RediSearch module (run MODULE LIST or FT._LIST)
  3. Check host, port, password and TLS settings in the Redis connection config
  4. Restart the application after fixing connectivity — init runs at repository construction

Example fix

// before
JedisPooled jedis = new JedisPooled("localhost", 6379); // vanilla Redis, no RediSearch
// after
// use redis-stack or a RediSearch-enabled endpoint
JedisPooled jedis = new JedisPooled("redis-stack-host", 6379);
Defensive patterns

Strategy: try-catch

Validate before calling

try { jedis.ft._list(); } catch (JedisDataException e) { throw new IllegalStateException("RediSearch module not available", e); }

Try / catch

try { repo = RedisChatMemoryRepository.builder()...build(); }
catch (IllegalStateException e) {
    logger.error("Redis schema init failed; check RediSearch module and connectivity", e);
    throw e;
}

Prevention

When it happens

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

Common situations: Connecting to vanilla Redis without RediSearch; wrong host/port/password; network/firewall blocking the connection; managed Redis that doesn't support FT commands.

Related errors


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