{"record":{"id":"4874c079b9041c5d","repo":"chroma-core/chroma","slug":"expected-ids-to-be-a-non-empty-list-got-len-ids","errorCode":null,"errorMessage":"Expected IDs to be a non-empty list, got {len(ids)} IDs","messagePattern":"Expected IDs to be a non-empty list, got (.+?) IDs","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":1019,"sourceCode":"    if not function_signature == protocol_signature:\n        raise ValueError(\n            f\"Expected EmbeddingFunction.__call__ to have the following signature: {protocol_signature}, got {function_signature}\\n\"\n            \"Please see https://docs.trychroma.com/guides/embeddings for details of the EmbeddingFunction interface.\\n\"\n            \"Please note the recent change to the EmbeddingFunction interface: https://docs.trychroma.com/deployment/migration#migration-to-0.4.16---november-7,-2023 \\n\"\n        )\n\n\nclass DataLoader(Protocol[L]):\n    def __call__(self, uris: URIs) -> L:\n        ...\n\n\ndef validate_ids(ids: IDs) -> IDs:\n    \"\"\"Validates ids to ensure it is a list of strings\"\"\"\n    if not isinstance(ids, list):\n        raise ValueError(f\"Expected IDs to be a list, got {type(ids).__name__} as IDs\")\n    if len(ids) == 0:\n        raise ValueError(f\"Expected IDs to be a non-empty list, got {len(ids)} IDs\")\n    seen = set()\n    dups = set()\n    for id_ in ids:\n        if not isinstance(id_, str):\n            raise ValueError(f\"Expected ID to be a str, got {id_}\")\n        if id_ in seen:\n            dups.add(id_)\n        else:\n            seen.add(id_)\n    if dups:\n        n_dups = len(dups)\n        if n_dups < 10:\n            example_string = \", \".join(dups)\n            message = (\n                f\"Expected IDs to be unique, found duplicates of: {example_string}\"\n            )\n        else:\n            examples = []","sourceCodeStart":1001,"sourceCodeEnd":1037,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L1001-L1037","documentation":"validate_ids rejects an empty ids list: adding, upserting or updating zero records is meaningless and almost always signals an upstream bug such as an empty dataframe or a fully filtered-out batch. Note that through collection.add()/upsert()/update() an empty ids list is caught slightly earlier by the record-set length check ('Non-empty lists are required'); the classic 'Expected IDs to be a non-empty list' message appears when validate_ids is invoked directly.","triggerScenarios":"Calling validate_ids([]); collection.add(ids=[], documents=[]) (raises the sibling length-consistency error first); update(ids=[]) with nothing to change; batch loops over query results that returned zero rows.","commonSituations":"Iterating batches from a dataframe or database cursor that produced an empty batch; filter logic that accidentally empties the batch; scheduled ingestion jobs on days with no new data.","solutions":["Skip the call when the batch is empty: 'if not ids: continue' or 'return'","Log a warning or counter when a batch is empty so silent upstream bugs surface","Fix the upstream producer if empty batches are unexpected"],"exampleFix":"# before\ncollection.add(ids=ids, documents=docs)  # ids can be []\n\n# after\nif ids:\n    collection.add(ids=ids, documents=docs)","handlingStrategy":"validation","validationCode":"if not ids:\n    logger.info('empty batch, skipping')\n    return\ncollection.add(ids=ids, documents=docs)","typeGuard":"def is_nonempty_ids(ids) -> bool:\n    return isinstance(ids, list) and len(ids) > 0","tryCatchPattern":"try:\n    collection.add(ids=ids, documents=docs)\nexcept ValueError as e:\n    if 'non-empty list' in str(e) and not ids:\n        return  # nothing to do\n    raise","preventionTips":["Guard every batch loop with 'if not ids: continue'","Count and log batch sizes so zero-size batches stand out","Fail loudly in dev when producers emit empty batches"],"tags":["chromadb","python","ids","empty-input","validation"],"backgroundTag":"empty-list-argument","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}