{"record":{"id":"2265939fdd1a6fbc","repo":"spring-projects/spring-ai","slug":"failed-to-delete-documents-by-filter-226593","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-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java","lineNumber":342,"sourceCode":"\n\t@Override\n\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\tDeleteParam.Builder deleteParamBuilder = DeleteParam.newBuilder()\n\t\t\t\t.withDatabaseName(this.databaseName)\n\t\t\t\t.withCollectionName(this.collectionName)\n\t\t\t\t.withExpr(nativeFilterExpression);\n\t\t\tif (StringUtils.hasText(this.partitionName)) {\n\t\t\t\tdeleteParamBuilder.withPartitionName(this.partitionName);\n\t\t\t}\n\t\t\tR<MutationResult> status = this.milvusClient.delete(deleteParamBuilder.build());\n\n\t\t\tif (status.getStatus() != Status.Success.getCode()) {\n\t\t\t\tthrow new IllegalStateException(\"Failed to delete documents by filter: \" + status.getMessage());\n\t\t\t}\n\n\t\t\tlong deleteCount = status.getData().getDeleteCnt();\n\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Deleted \" + deleteCount + \" documents matching filter expression\");\n\t\t\t}\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\t\tString nativeFilterExpressions = \"\";","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java#L324-L360","documentation":"MilvusVectorStore.doDelete issues a delete RPC with a filter expression builder. If the returned R<MutationResult> status code is not Status.Success, it throws an IllegalStateException including the SDK's status message. Unlike the insert path, this surfaces the Milvus error message in the exception text.","triggerScenarios":"Calling vectorStore.delete(List<String> ids) or delete(FilterExpression) when Milvus rejects the delete: invalid filter expression syntax for Milvus boolean grammar, collection not loaded, nonexistent partition, expression referencing fields not in the schema, or connectivity failures.","commonSituations":"Filter expressions using operators Milvus doesn't accept (e.g. unsupported NOT), deleting by metadata field that was never stored, partitionName configured but partition missing, collection in unloaded state after server restart.","solutions":["Read status.getMessage() embedded in the exception for the exact Milvus error.","Verify the filter expression uses valid Milvus boolean syntax and only existing schema fields.","Load the collection (collection.load()) if it is not loaded into memory.","Confirm the partitionName exists or remove it from configuration.","Check Milvus server connectivity and SDK/server version compatibility."],"exampleFix":"// before\nvectorStore.delete(new FilterExpressionBuilder().not(\n    new FilterExpressionBuilder().eq(\"type\", \"tmp\")).build()); // unsupported in Milvus\n// after\nvectorStore.delete(new FilterExpressionBuilder().ne(\"type\", \"tmp\").build());","handlingStrategy":"try-catch","validationCode":"// Validate fields referenced by the delete filter exist in the schema, and\n// confirm the configured partition exists before calling delete.","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.delete(idsOrFilter);\n} catch (IllegalStateException e) {\n    // message contains Milvus status.getMessage(); parse and branch:\n    // - collection not loaded -> load then retry\n    // - invalid expression -> rewrite filter\n    // - transient -> retry with backoff\n}","preventionTips":["Read the Milvus status message embedded in the exception before generic retries.","Use only Milvus-grammar-supported operators in delete filters.","Load the collection before issuing deletes after a server restart.","Verify partitionName configuration against actual partitions.","Test delete filters on staging data to avoid failed destructive operations."],"tags":["milvus","delete","vector-store","filter-expression"],"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-14T11:17:12.474Z"}