{"record":{"id":"2b0874deb3d16674","repo":"spring-projects/spring-ai","slug":"failed-to-delete-documents-by-filter-2b0874","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-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java","lineNumber":222,"sourceCode":"\t\t\tString filterStr = this.filterExpressionConverter.convertExpression(filterExpression);\n\t\t\tDeleteDocumentsParameters deleteDocumentsParameters = new DeleteDocumentsParameters();\n\t\t\tdeleteDocumentsParameters.filterBy(filterStr);\n\n\t\t\tMap<String, Object> response = this.client.collections(this.collectionName)\n\t\t\t\t.documents()\n\t\t\t\t.delete(deleteDocumentsParameters);\n\n\t\t\tint deletedDocs = (Integer) response.getOrDefault(\"num_deleted\", 0);\n\t\t\tif (deletedDocs == 0) {\n\t\t\t\tlogger.warn(\"No documents were deleted matching filter expression\");\n\t\t\t}\n\t\t\telse if (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Deleted \" + deletedDocs + \" documents matching filter expression\");\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\tAssert.notNull(request.getQuery(), \"Query string must not be null\");\n\n\t\tString nativeFilterExpressions = (request.getFilterExpression() != null)\n\t\t\t\t? this.filterExpressionConverter.convertExpression(request.getFilterExpression()) : \"\";\n\n\t\tif (logger.isInfoEnabled()) {\n\t\t\tlogger.info(\"Filter expression: \" + nativeFilterExpressions);\n\t\t}\n\n\t\tfloat[] embedding = this.embeddingModel.embed(request.getQuery());\n\n\t\tMultiSearchCollectionParameters multiSearchCollectionParameters = new MultiSearchCollectionParameters();\n\t\tmultiSearchCollectionParameters.collection(this.collectionName);","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java#L204-L240","documentation":"TypesenseVectorStore.doDelete wraps any exception thrown while deleting documents matching a filter expression (search + delete via the Typesense client) into an IllegalStateException with this message, after logging the original error. It indicates the delete-by-filter operation failed at the client/HTTP level, not that the filter was invalid.","triggerScenarios":"Calling vectorStore.delete(filterExpression) when the Typesense collection is unreachable, the collection doesn't exist, the filter converts to invalid filter_by syntax, or the client throws any Exception during the delete flow.","commonSituations":"Typesense server down or wrong host/port; API key lacking delete permissions; collection deleted or renamed while the store is in use; a filter that serializes to filter_by syntax Typesense rejects.","solutions":["Inspect the logged cause (logger.error prints the root exception) and fix the underlying Typesense connectivity/permission/collection issue.","Verify the Typesense client configuration (host, port, API key) and that the target collection exists.","Retry the delete; if transient network errors are common, wrap with retry/backoff.","Convert the filter to filter_by syntax manually and test it with curl against the collection's documents endpoint to find syntax problems."],"exampleFix":"// before\nvectorStore.delete(new Filter.Expression(GT, new Key(\"year\"), new Value(2000))); // fails silently root-caused\n// after: ensure collection & connectivity\nCollectionsOperations coll = typesenseClient.collections(\"my_collection\");\ncoll.retrieve(); // verify reachable before delete\nvectorStore.delete(filterExpr);","handlingStrategy":"try-catch","validationCode":"// pre-check connectivity\ntypesenseClient.collections(collectionName).retrieve();","typeGuard":null,"tryCatchPattern":"try { vectorStore.delete(filterExpr); } catch (IllegalStateException e) { logger.error(\"Delete-by-filter failed; cause:\", e.getCause()); /* inspect Typesense host/port/key/collection */ }","preventionTips":["Verify Typesense host, port, and API key in configuration before deploy","Confirm the target collection exists and the API key has delete scope","Watch store logs — the root cause is logged via logger.error before rethrow","Test converted filter_by syntax directly against the Typesense API"],"tags":["vector-store","typesense","delete","database-query-failed"],"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"}