{"record":{"id":"6eaf3134f6ac0a36","repo":"spring-projects/spring-ai","slug":"failed-to-delete-documents-by-filter","errorCode":null,"errorMessage":"Failed to delete documents by filter","messagePattern":"Failed to delete documents by filter","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java","lineNumber":348,"sourceCode":"\t\t\t\t.filterExpression(filterExpression)\n\t\t\t\t.topK(1000) // large enough to get all matches\n\t\t\t\t.similarityThresholdAll()\n\t\t\t\t.build();\n\n\t\t\tList<Document> matchingDocs = similaritySearch(searchRequest);\n\n\t\t\tif (!matchingDocs.isEmpty()) {\n\t\t\t\t// Then delete those documents by ID\n\t\t\t\tList<String> idsToDelete = matchingDocs.stream().map(Document::getId).toList();\n\t\t\t\tdelete(idsToDelete);\n\t\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\t\tlogger.debug(\"Deleted \" + idsToDelete.size() + \" documents matching filter expression\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tlogger.error(\"Failed to delete documents by filter\", e);\n\t\t\tthrow new IllegalStateException(\"Failed to delete documents by filter\", e);\n\t\t}\n\t}\n\n\t@Override\n\tpublic List<Document> doSimilaritySearch(SearchRequest request) {\n\t\tPreconditions.checkArgument(request.getTopK() <= 1000);\n\t\tvar embedding = toFloatArray(this.embeddingModel.embed(request.getQuery()));\n\t\tCqlVector<Float> cqlVector = CqlVector.newInstance(embedding);\n\t\tString cql = createSimilaritySearchCql(request, cqlVector, request.getTopK());\n\n\t\tList<Document> documents = new ArrayList<>();\n\t\tResultSet result = this.session\n\t\t\t.execute(SimpleStatement.newInstance(cql).setExecutionProfileName(DRIVER_PROFILE_SEARCH));\n\n\t\tfor (Row row : result) {\n\t\t\tfloat score = row.getFloat(0);\n\t\t\tif (score < request.getSimilarityThreshold()) {\n\t\t\t\tbreak;","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java#L330-L366","documentation":"CassandraVectorStore.doDelete wraps the whole filter-based document deletion (building the CQL DELETE, executing it) in a try/catch and rethrows any failure as IllegalStateException with this message, preserving the cause. It means the delete statement or session interaction failed, not that zero documents matched.","triggerScenarios":"Executing vectorStore.delete(filterExpression) where the CQL statement fails: invalid filter-to-CQL conversion output, table/index mismatch, session/connection error, or permission denied on the keyspace/table.","commonSituations":"Wrong keyspace or table configured in the schema; the driver session is closed or unreachable; insufficient CQL permissions (no MODIFY on the table); a filter expression that compiled to invalid CQL.","solutions":["Inspect the cause attached to the IllegalStateException; fix the underlying CQL/driver error it reports.","Verify the schema config (keyspace, table, index) matches the actual Cassandra schema and that the session is connected.","Check Cassandra role permissions: the configured user needs MODIFY on the target table.","Confirm the filter expression renders valid CQL by simplifying it to a basic equality filter and retrying."],"exampleFix":"// before: filter referencing a non-existent metadata column\nvectorStore.delete(new FilterExpressionBuilder().eq(\"meta.tag\", \"x\").build());\n// after: ensure the column exists in the table / schema metadata columns\nvectorStore.delete(new FilterExpressionBuilder().eq(\"metadata_tag\", \"x\").build());","handlingStrategy":"try-catch","validationCode":"// Pre-check: cluster reachable and role can modify\nCqlSession s = ...;\nRow r = s.execute(\"SELECT count(*) FROM system_schema.tables WHERE keyspace_name=? AND table_name=?\", ks, tbl).one();\nif (r == null || r.getLong(0) == 0) throw new IllegalStateException(\"Table missing before delete\");","typeGuard":"null","tryCatchPattern":"try {\n  vectorStore.delete(filterExpression);\n} catch (IllegalStateException e) {\n  Throwable root = ExceptionUtils.getRootCause(e);\n  logger.error(\"Cassandra delete failed: {}\", root.getMessage(), root);\n}","preventionTips":["Always log/read the wrapped cause — this exception is only a wrapper.","Validate keyspace/table config against system_schema at startup.","Grant MODIFY on the target table to the store's Cassandra role.","Test filter expressions against a local Cassandra before production deletes."],"tags":["cassandra","delete","database","vector-store","state-exception"],"backgroundTag":"database-query-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"}