{"record":{"id":"68c7741881a1c293","repo":"spring-projects/spring-ai","slug":"failed-to-delete-documents-by-filter-68c774","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-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java","lineNumber":202,"sourceCode":"\t\ttry {\n\t\t\tChromaFilterExpressionConverter converter = new ChromaFilterExpressionConverter();\n\t\t\tString whereClauseStr = converter.convertExpression(expression);\n\n\t\t\tMap<String, Object> whereClause = this.chromaApi.where(whereClauseStr);\n\n\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\tlogger.debug(\"Deleting with where clause: \" + whereClause);\n\t\t\t}\n\n\t\t\tDeleteEmbeddingsRequest deleteRequest = new DeleteEmbeddingsRequest(null, whereClause);\n\t\t\tthis.chromaApi.deleteEmbeddings(this.tenantName, this.databaseName, this.requireCollectionId(),\n\t\t\t\t\tdeleteRequest);\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 query = request.getQuery();\n\t\tAssert.notNull(query, \"Query string must not be null\");\n\n\t\tfloat[] embedding = this.embeddingModel.embed(query);\n\n\t\tMap<String, Object> where = (request.getFilterExpression() != null)\n\t\t\t\t? jsonToMap(this.filterExpressionConverter.convertExpression(request.getFilterExpression())) : null;\n\n\t\tvar queryRequest = new ChromaApi.QueryRequest(embedding, request.getTopK(), where);\n\t\tvar queryResponse = this.chromaApi.queryCollection(this.tenantName, this.databaseName,\n\t\t\t\tthis.requireCollectionId(), queryRequest);\n\t\tvar embeddings = this.chromaApi.toEmbeddingResponseList(queryResponse);","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java#L184-L220","documentation":"ChromaVectorStore.doDelete wraps filter-based deletion in a try/catch and rethrows any exception as IllegalStateException(\"Failed to delete documents by filter\", e). The underlying Chroma delete request (converting the filter and calling the delete API) failed.","triggerScenarios":"Calling vectorStore.delete(Filter) when the Chroma server returns an error (connection failure, HTTP error, invalid filter payload, unknown collection id) during the delete request.","commonSituations":"Chroma server restarted or unreachable; the collection ID cached at initialization no longer exists; a filter expression that the converter translated into something Chroma's where-clause rejects; auth failure.","solutions":["Inspect the cause/cause message logged with the error to find the actual Chroma API failure.","Verify Chroma server availability and authentication; re-run initialization to refresh the collection ID.","Simplify the filter to a plain equality where-clause to rule out converter output problems.","Retry the delete once connectivity is restored — the failure aborts before data is deleted only if the request failed."],"exampleFix":"// before: filter referencing a metadata key with a type Chroma rejects\nvectorStore.delete(Filter.expr(\"score\").gt(\"high\"));\n// after: use correct value type for the metadata\nvectorStore.delete(Filter.expr(\"score\").gt(0.5));","handlingStrategy":"try-catch","validationCode":"// ensure collection id is still valid before delete\ntry { chromaApi.count(collectionId, null); } catch (Exception e) { reinitializeStore(); }","typeGuard":"null","tryCatchPattern":"try {\n  vectorStore.delete(filterExpression);\n} catch (IllegalStateException e) {\n  logger.error(\"Chroma delete failed\", e.getCause());\n  // optionally rebuild the store to refresh collectionId, then retry once\n}","preventionTips":["Use correctly typed values in filters (Chroma where-clauses are type-sensitive).","Monitor Chroma server health; rebuild the store after server restarts.","Catch and inspect the cause — the IllegalStateException is just a wrapper.","Test filter conversion output for your metadata schema in unit tests."],"tags":["chroma","delete","database","vector-store","http"],"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"}