[Bug]: delete(ids=...) returns the number of IDs passed, not the number actually deleted
What happened?
I ran into this while checking the return value of delete(). When I call collection.delete(ids=[...]), the deleted count I get back is just the number of IDs I passed in, even when some (or all) of them aren't actually in the collection. The docstring says the result is "the number of records deleted", so I expected it to only count the ones that were really there.
Small repro:
import chromadb
client = chromadb.Client()
col = client.create_collection("repro")
col.add(documents=["alpha", "beta"], ids=["a", "b"])
print("count before:", col.count()) # 2
# "b" exists, "ghost" does not
print(col.delete(ids=["b", "ghost"])) # {'deleted': 2} -> only 1 was actually deleted
print("count after:", col.count()) # 1
# nothing matches this id
print(col.delete(ids=["ghost-again"])) # {'deleted': 1} -> 0 were deleted
print("count after:", col.count()) # 1 (unchanged)
# the where-filter path, for comparison, is correct:
print(col.delete(where={"missing_key": "x"})) # {'deleted': 0}I'd expect deleted to be 1 for the first call and 0 for the second. What's a bit odd is that deleting by a where filter returns the right number (it gives 0 when nothing matches), so the ids path and the where path don't behave the same way.
Looking at the code, both delete paths seem to count the requested IDs rather than what actually got removed — segment.py does deleted_count = len(ids_to_delete), and the rust path returns the same requested count straight from the bindings. The where path is accurate because it resolves the matching records first. This count also feeds the delete_amount telemetry event, so that would be inflated too.
Not OS-specific as far as I can tell — the count comes from the shared code path, I just happened to hit it on Windows.
Versions
chromadb 1.5.9 Python 3.14.7 Windows-11-10.0.26200-SP0
Relevant log output
count before: 2
delete(ids=['b','ghost']) -> {'deleted': 2}
count after: 1
delete(ids=['ghost-again']) -> {'deleted': 1}
count after: 1Source: chroma-core/chroma