{"record":{"id":"85263c326c13e0b8","repo":"spring-projects/spring-ai","slug":"could-not-add-document-0","errorCode":null,"errorMessage":"Could not add document: {0}","messagePattern":"Could not add document: (.+?)","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":383,"sourceCode":"\t\t\t\tvar fields = new HashMap<String, Object>();\n\t\t\t\tfloat[] embedding = embeddings.get(i);\n\n\t\t\t\t// Normalize embeddings for COSINE distance metric\n\t\t\t\tif (this.distanceMetric == DistanceMetric.COSINE) {\n\t\t\t\t\tembedding = normalize(embedding);\n\t\t\t\t}\n\n\t\t\t\tfields.put(this.embeddingFieldName, embedding);\n\t\t\t\tfields.put(this.contentFieldName, document.getText());\n\t\t\t\tfields.putAll(document.getMetadata());\n\t\t\t\tpipeline.jsonSetWithEscape(key(document.getId()), JSON_SET_PATH, fields);\n\t\t\t}\n\t\t\tList<Object> responses = pipeline.syncAndReturnAll();\n\t\t\tOptional<Object> errResponse = responses.stream().filter(Predicate.not(RESPONSE_OK)).findAny();\n\t\t\tif (errResponse.isPresent()) {\n\t\t\t\tString message = MessageFormat.format(\"Could not add document: {0}\", errResponse.get());\n\t\t\t\tlogger.error(message);\n\t\t\t\tthrow new RuntimeException(message);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate String key(String id) {\n\t\treturn this.prefix + id;\n\t}\n\n\t@Override\n\tpublic void doDelete(List<String> idList) {\n\t\ttry (Pipeline pipeline = this.jedisClient.pipelined()) {\n\t\t\tfor (String id : idList) {\n\t\t\t\tpipeline.jsonDel(key(id));\n\t\t\t}\n\t\t\tList<Object> responses = pipeline.syncAndReturnAll();\n\t\t\tOptional<Object> errResponse = responses.stream().filter(Predicate.not(RESPONSE_DEL_OK)).findAny();\n\t\t\tif (errResponse.isPresent()) {\n\t\t\t\tif (logger.isErrorEnabled()) {","sourceCodeStart":365,"sourceCodeEnd":401,"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#L365-L401","documentation":"RedisVectorStore.doAdd() writes documents through a Jedis pipeline and checks every response against the expected OK reply. If any single document write in the batch returned an error response, it logs the offending reply and throws a RuntimeException with that response embedded in the message. This means at least one document in the add batch failed at the Redis server side (e.g. JSON.SET rejected).","triggerScenarios":"Adding a batch of documents where at least one pipeline response is not 'OK', e.g. RedisJSON module missing, malformed resulting JSON document, key type conflicts, or OOM/replica read-only errors on the server.","commonSituations":"Redis server without the RediSearch/RedisJSON modules loaded; document metadata containing values that cannot serialize to JSON; index/schema mismatch after upgrading Redis; writing to a read-only replica.","solutions":["Check the embedded response in the message to identify the failing command and fix the server-side cause","Verify Redis has RedisJSON and RediSearch modules loaded (redis-modules.json / Redis Stack)","Inspect the documents in the failing batch for values that break JSON serialization","Ensure the target Redis instance is writable and not a read-only replica"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check: ensure modules and writability\nString modules = jedisClient.info(\"modules\"); // expect search & ReJSON\nif (modules == null || !modules.contains(\"search\")) throw new IllegalStateException(\"Redis Stack modules missing\");","typeGuard":null,"tryCatchPattern":"try { store.add(docs); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Could not add document:\")) { /* inspect failing reply, retry batch individually */ } }","preventionTips":["Install Redis Stack (RedisJSON + RediSearch)","Validate document metadata serializes to clean JSON","On batch failure, retry documents one-by-one to isolate the bad one","Avoid writing to read-only replicas"],"tags":["redis","vector-store","write-failure","pipeline"],"backgroundTag":"database-write-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}