{"record":{"id":"0fc314a262366e3c","repo":"spring-projects/spring-ai","slug":"failed-to-delete-documents-by-filter-0fc314","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":354,"sourceCode":"\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 = \"\";\n\t\tString searchParamsJson = null;\n\t\tif (request instanceof MilvusSearchRequest milvusReq) {\n\t\t\tnativeFilterExpressions = StringUtils.hasText(milvusReq.getNativeExpression())\n\t\t\t\t\t? milvusReq.getNativeExpression() : getConvertedFilterExpression(request);\n\n\t\t\tsearchParamsJson = StringUtils.hasText(milvusReq.getSearchParamsJson()) ? milvusReq.getSearchParamsJson()\n\t\t\t\t\t: null;\n\t\t}\n\t\telse {\n\t\t\tnativeFilterExpressions = getConvertedFilterExpression(request);\n\t\t}\n","sourceCodeStart":336,"sourceCodeEnd":372,"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#L336-L372","documentation":"MilvusVectorStore.doDelete wraps any exception raised while deleting documents matching a Filter expression into an IllegalStateException. The Milvus client delete call or the filter-expression conversion failed, so the delete could not be completed. The original exception is attached as the cause and logged.","triggerScenarios":"Calling vectorStore.delete(String filterExpression) or delete(Filter...) when the Milvus client deleteByFilter RPC fails (connection loss, collection not loaded, malformed filter expression, embedding/metadata field name mismatch).","commonSituations":"Milvus server unreachable or restarted; collection not loaded into memory; filter expression referencing a metadata field that is not the configured metadataFieldName; invalid filter syntax produced by the expression converter.","solutions":["Inspect the cause exception in the IllegalStateException to identify the underlying Milvus client failure.","Verify the Milvus server is running and reachable (host/port/credentials in MilvusServiceClient builder).","Ensure the collection is loaded (LoadCollection) before deleting.","Validate the filter expression syntax and that field names match the store's configured content/metadata field names.","Retry the delete once connectivity is restored."],"exampleFix":"// before\nvectorStore.delete(\"country == 'Bulagaria'\");\n// after\nvectorStore.delete(\"country == 'Bulgaria'\"); // fix typo in filter expression","handlingStrategy":"try-catch","validationCode":"// before deleting, check server reachability and collection existence\nif (!milvusClient.hasCollection(HasCollectionParam.newBuilder()\n        .withCollectionName(collectionName).build()).getData(Boolean.FALSE)) {\n    throw new IllegalStateException(\"Collection \" + collectionName + \" does not exist\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.delete(\"country == 'Bulgaria'\");\n} catch (IllegalStateException e) {\n    logger.error(\"Milvus delete failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());\n    // inspect e.getCause() for the Milvus RPC status before retrying\n}","preventionTips":["Test filter expressions against a small dataset before production deletes.","Keep Milvus server health checks in place before batch delete operations.","Ensure metadata field names in filters match the store's metadataFieldName configuration."],"tags":["milvus","vector-store","delete","filter-expression"],"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-14T11:17:12.474Z"}