{"record":{"id":"82c05f008c175aa9","repo":"spring-projects/spring-ai","slug":"failed-to-delete-documents-by-filter-82c05f","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-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java","lineNumber":344,"sourceCode":"\tprotected void doDelete(Filter.Expression filterExpression) {\n\t\tAssert.notNull(filterExpression, \"Filter expression must not be null\");\n\n\t\ttry {\n\t\t\tString nativeFilterExpression = this.filterExpressionConverter.convertExpression(filterExpression);\n\n\t\t\tString sql = String.format(\"DELETE FROM %s WHERE %s\", getFullyQualifiedTableName(), nativeFilterExpression);\n\n\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Executing delete with filter: \" + sql);\n\t\t\t}\n\n\t\t\tthis.jdbcTemplate.update(sql);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tif (logger.isErrorEnabled()) {\n\t\t\t\tlogger.error(\"Failed to delete documents by filter: \" + e.getMessage(), e);\n\t\t\t}\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\n\t\tString nativeFilterExpression = (request.getFilterExpression() != null)\n\t\t\t\t? this.filterExpressionConverter.convertExpression(request.getFilterExpression()) : \"\";\n\t\tfloat[] embedding = this.embeddingModel.embed(request.getQuery());\n\t\tString jsonPathFilter = \"\";\n\n\t\tif (StringUtils.hasText(nativeFilterExpression)) {\n\t\t\tjsonPathFilter = \"and \" + nativeFilterExpression + \" \";\n\t\t}\n\t\tString distanceType = this.distanceType.name().toLowerCase(Locale.ROOT);\n\n\t\tdouble distance = 1 - request.getSimilarityThreshold();\n\t\tfinal String sql = String.format(","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java#L326-L362","documentation":"MariaDBVectorStore.doDelete builds a DELETE statement with a filter expression and executes it via JdbcTemplate. Any exception during SQL construction or execution is caught, logged, and rethrown as an IllegalStateException('Failed to delete documents by filter', cause). The original cause is preserved as the root exception.","triggerScenarios":"Calling vectorStore.delete(filterExpression) when the generated SQL is invalid (unsupported filter expression type, bad identifier), the connection fails, or the table/columns are missing — any SQLException or DataAccessException from jdbcTemplate.update.","commonSituations":"Complex FilterExpressions translated to invalid MariaDB SQL, JSON_VALUE-based metadata filters failing on malformed metadata, DB connection drops mid-transaction, table schema drift after upgrades.","solutions":["Inspect the chained cause (e.getCause()) for the underlying SQLException and fix that first.","Simplify or correct the FilterExpression to operators the MariaDB converter supports.","Verify the table schema matches the expected columns via MariaDBSchemaValidator.","Check database connectivity and retry the delete."],"exampleFix":"// before\nvectorStore.delete(\"year > 2020 and genre nin ['news']\"); // assume NOT/NIN support\n// after\nvectorStore.delete(new FilterExpressionBuilder().gt(\"year\", 2020).build());","handlingStrategy":"try-catch","validationCode":"// Validate filter is translatable and table exists before deleting:\nInteger n = jdbc.queryForObject(\n    \"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=?\",\n    Integer.class, tableName);\nif (n == null || n == 0) throw new IllegalStateException(\"Table missing: \" + tableName);","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.delete(filterExpression);\n} catch (IllegalStateException e) {\n    Throwable root = e.getCause();\n    logger.error(\"delete failed: {}\", root == null ? e : root.getMessage(), root);\n    // rollback/compensate or retry after fixing the SQL-level cause\n}","preventionTips":["Inspect e.getCause() — the IllegalStateException always wraps the real SQL error.","Test delete filter expressions against a staging table before production use.","Keep the table schema validated at startup so column drift is caught early.","Use only converter-supported operators in filter expressions."],"tags":["mariadb","delete","sql","vector-store"],"backgroundTag":"sql-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"}