{"record":{"id":"d98fecd0344a667d","repo":"spring-projects/spring-ai","slug":"could-not-create-index-0","errorCode":null,"errorMessage":"Could not create index: {0}","messagePattern":"Could not create index: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-redis-store/src/main/java/org/springframework/ai/vectorstore/redis/RedisVectorStore.java","lineNumber":657,"sourceCode":"\t}\n\n\t@Override\n\tpublic void afterPropertiesSet() {\n\n\t\tif (!this.initializeSchema) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If index already exists don't do anything\n\t\tif (this.jedisClient.ftList().contains(this.indexName)) {\n\t\t\treturn;\n\t\t}\n\n\t\tString response = this.jedisClient.ftCreate(this.indexName,\n\t\t\t\tFTCreateParams.createParams().on(IndexDataType.JSON).addPrefix(this.prefix), schemaFields());\n\t\tif (!RESPONSE_OK.test(response)) {\n\t\t\tString message = MessageFormat.format(\"Could not create index: {0}\", response);\n\t\t\tthrow new RuntimeException(message);\n\t\t}\n\t}\n\n\tprivate Iterable<SchemaField> schemaFields() {\n\t\tMap<String, Object> vectorAttrs = new HashMap<>();\n\t\tvectorAttrs.put(\"DIM\", this.embeddingModel.dimensions());\n\t\tvectorAttrs.put(\"DISTANCE_METRIC\", this.distanceMetric.getRedisName());\n\t\tvectorAttrs.put(\"TYPE\", VECTOR_TYPE_FLOAT32);\n\n\t\t// Add HNSW algorithm configuration parameters when using HNSW algorithm\n\t\tif (this.vectorAlgorithm == Algorithm.HNSW) {\n\t\t\t// M parameter: maximum number of connections per node in the graph (default:\n\t\t\t// 16)\n\t\t\tif (this.hnswM != null) {\n\t\t\t\tvectorAttrs.put(\"M\", this.hnswM);\n\t\t\t}\n\n\t\t\t// EF_CONSTRUCTION parameter: size of dynamic candidate list during index","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-redis-store/src/main/java/org/springframework/ai/vectorstore/redis/RedisVectorStore.java#L639-L675","documentation":"RedisVectorStore.afterPropertiesSet() creates the RediSearch index via jedisClient.ftCreate(...) with an FTCreateParams (JSON type + key prefix) and the computed schema. If the server's reply is not 'OK', it throws a RuntimeException 'Could not create index: {response}'. This typically means Redis rejected the FT.CREATE command.","triggerScenarios":"Initializing the RedisVectorStore bean (afterPropertiesSet) when the index already exists with different parameters, RediSearch module is missing/outdated, the schema is invalid (e.g. bad DIM), or the server replies with an error string.","commonSituations":"Application restart against a Redis where the index exists (older RediSearch versions error on duplicate index); Redis Stack not installed so ftCreate is unsupported; embedding dimensions changed while an old index with a different DIM exists; insufficient permissions.","solutions":["Check the response text in the message: 'Index already exists' is usually benign on restart — pre-check with ftInfo or drop the stale index","If DIM mismatch: drop the old index (FT.DROPINDEX) and let the store recreate it with the current embeddingModel.dimensions()","Ensure Redis Stack (RediSearch + RedisJSON modules) is installed and the module version supports FT.CREATE with JSON","Verify the Redis user has permissions to create indexes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check before creating the store\ntry { jedisClient.ftInfo(indexName); /* exists -> drop or reuse */ } catch (JedisDataException e) { /* 'Unknown Index name' -> safe to create */ }\nString modules = jedisClient.info(\"modules\"); if (!modules.contains(\"search\")) throw new IllegalStateException(\"RediSearch not loaded\");","typeGuard":null,"tryCatchPattern":"try { new RedisVectorStore(...).afterPropertiesSet(); } catch (RuntimeException e) { if (e.getMessage().contains(\"Could not create index\") && e.getMessage().contains(\"already exists\")) { /* reuse or FT.DROPINDEX then retry */ } }","preventionTips":["Install Redis Stack with RediSearch and RedisJSON","Drop stale indexes when embedding dimensions change","Make index creation idempotent: check FT.INFO first","Grant the Redis user index-creation permissions"],"tags":["redis","vector-store","index-creation","redismodule"],"backgroundTag":"api-error-response","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"}