{"record":{"id":"0e051496b3319a5e","repo":"chroma-core/chroma","slug":"limit-can-only-be-specified-when-a-where-or-where-0e0514","errorCode":null,"errorMessage":"limit can only be specified when a where or where_document clause is provided","messagePattern":"limit can only be specified when a where or where_document clause is provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/segment.py","lineNumber":809,"sourceCode":"            where=where,\n            where_document=where_document,\n        )\n\n        self._manager.hint_use_collection(collection_id, t.Operation.DELETE)\n\n        if (where or where_document) or not ids:\n            ids_to_delete = self._executor.get(\n                GetPlan(scan, Filter(ids, where, where_document))\n            )[\"ids\"]\n        else:\n            ids_to_delete = ids\n\n        # Apply limit if specified (validated upstream, but enforce defensively)\n        if limit is not None:\n            if not isinstance(limit, int) or isinstance(limit, bool) or limit < 0:\n                raise ValueError(\"limit must be a non-negative integer\")\n            if where is None and where_document is None:\n                raise ValueError(\n                    \"limit can only be specified when a where or where_document clause is provided\"\n                )\n            ids_to_delete = ids_to_delete[:limit]\n\n        if len(ids_to_delete) == 0:\n            return DeleteResult(deleted=0)\n\n        records_to_submit = list(\n            _records(operation=t.Operation.DELETE, ids=ids_to_delete)\n        )\n        self._validate_embedding_record_set(scan.collection, records_to_submit)\n        self._producer.submit_embeddings(collection_id, records_to_submit)\n\n        deleted_count = len(ids_to_delete)\n\n        self._product_telemetry_client.capture(\n            CollectionDeleteEvent(\n                collection_uuid=str(collection_id), delete_amount=deleted_count","sourceCodeStart":791,"sourceCodeEnd":827,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/segment.py#L791-L827","documentation":"A delete limit only makes sense as a cap on a filtered match set. SegmentAPI rejects limit when the delete is id-based only: if limit is not None while both where and where_document are None, it raises ValueError('limit can only be specified when a where or where_document clause is provided') — with explicit ids the deletion set is already fully determined.","triggerScenarios":"coll.delete(ids=['a','b'], limit=5) — any delete that passes ids and a non-None limit but no where/where_document filter.","commonSituations":"A generic wrapper that always forwards a limit kwarg to delete(); reusing one kwargs dict for both filtered and id-based paths; porting code from APIs where limit truncated id lists.","solutions":["Drop the limit for id-based deletes and slice the ids yourself: coll.delete(ids=ids[:5])","Build kwargs conditionally so limit is only included when where or where_document is set"],"exampleFix":"// before\ncoll.delete(ids=batch, limit=5)  # ValueError\n\n// after\ncoll.delete(ids=batch[:5])","handlingStrategy":"validation","validationCode":"def delete_limited(coll, ids=None, where=None, where_document=None, limit=None):\n    if limit is not None and where is None and where_document is None:\n        ids = (ids or [])[:limit]  # apply cap client-side instead\n        limit = None\n    return coll.delete(ids=ids, where=where, where_document=where_document, limit=limit)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only include limit in kwargs when a where/where_document clause is present","For id-based deletes, slice the ids list yourself","Keep one shared helper for delete() so the combination rules live in one place"],"tags":["chroma","delete","limit","parameter-combination"],"backgroundTag":"invalid-parameter-combination","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}