{"record":{"id":"d751ff7ed42902d5","repo":"chroma-core/chroma","slug":"non-empty-lists-are-required-for-zero-lengths","errorCode":null,"errorMessage":"Non-empty lists are required for {zero_lengths}","messagePattern":"Non-empty lists are required for (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":465,"sourceCode":"        validate_metadatas(record_set[\"metadatas\"])\n\n\ndef _validate_record_set_length_consistency(record_set: BaseRecordSet) -> None:\n    lengths = [len(lst) for lst in record_set.values() if lst is not None]  # type: ignore[arg-type]\n\n    if not lengths:\n        raise ValueError(\n            f\"At least one of one of {', '.join(record_set.keys())} must be provided\"\n        )\n\n    zero_lengths = [\n        key\n        for key, lst in record_set.items()\n        if lst is not None and len(lst) == 0  # type: ignore[arg-type]\n    ]\n\n    if zero_lengths:\n        raise ValueError(f\"Non-empty lists are required for {zero_lengths}\")\n\n    if len(set(lengths)) > 1:\n        error_str = \", \".join(\n            f\"{key}: {len(lst)}\"\n            for key, lst in record_set.items()\n            if lst is not None  # type: ignore[arg-type]\n        )\n        raise ValueError(f\"Unequal lengths for fields: {error_str}\")\n\n\ndef validate_record_set_for_embedding(\n    record_set: BaseRecordSet, embeddable_fields: Optional[Set[str]] = None\n) -> None:\n    \"\"\"\n    Validates that the Record is ready to be embedded, i.e. that it contains exactly one of the embeddable fields.\n    \"\"\"\n    if record_set[\"embeddings\"] is not None:\n        raise ValueError(\"Attempting to embed a record that already has embeddings.\")","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L447-L483","documentation":"The same record-set validation that requires at least one field also rejects provided-but-empty lists: any non-None field with length 0 — e.g. ids=[] alongside metadatas=[{'a': 1}] — raises ValueError('Non-empty lists are required for {zero_lengths}') naming each offending field. It is the companion guard to the all-None and unequal-length checks.","triggerScenarios":"coll.add(ids=[], metadatas=[{'a': 1}]), coll.upsert(documents=[]), or any add/update/upsert where at least one supplied list is empty (usually alongside other non-empty fields).","commonSituations":"Empty trailing batches where one field list is empty but others still hold values; dict construction defaulting a missing field to [] instead of None; zip-based field building that truncates to zero unevenly.","solutions":["Skip empty batches entirely: bail out if any provided list has length 0","Use None (or omit the kwarg) for fields you don't have — never []","Ensure producers emit all field lists with the same non-zero length"],"exampleFix":"// before\ncoll.add(ids=[], metadatas=[{'a': 1}])  # ValueError: non-empty lists required\n\n// after\nif ids and metadatas:\n    coll.add(ids=ids, metadatas=metadatas)","handlingStrategy":"validation","validationCode":"def validate_batch(record: dict) -> dict:\n    provided = {k: v for k, v in record.items() if v is not None}\n    if not provided:\n        raise ValueError('at least one field must be provided')\n    empty = [k for k, v in provided.items() if len(v) == 0]\n    if empty:\n        raise ValueError(f'non-empty lists required for {empty}')\n    lengths = {k: len(v) for k, v in provided.items()}\n    if len(set(lengths.values())) > 1:\n        raise ValueError(f'unequal lengths: {lengths}')\n    return provided\n\ncoll.add(**validate_batch(batch))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit fields you don't have (None) instead of passing []","Skip empty batches in loops rather than letting a trailing empty list through","Build all field lists from the same source (e.g. zip over one row list) so lengths cannot diverge"],"tags":["chroma","record-set","validation","empty-list","add"],"backgroundTag":"empty-input-list","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}