{"record":{"id":"ae1b82c6ed076048","repo":"chroma-core/chroma","slug":"aggregate-dict-cannot-be-empty","errorCode":null,"errorMessage":"Aggregate dict cannot be empty","messagePattern":"Aggregate dict cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/execution/expression/operator.py","lineNumber":1413,"sourceCode":"    \"\"\"\n\n    def to_dict(self) -> Dict[str, Any]:\n        \"\"\"Convert the Aggregate expression to a dictionary for JSON serialization\"\"\"\n        raise NotImplementedError(\"Subclasses must implement to_dict()\")\n\n    @staticmethod\n    def from_dict(data: Dict[str, Any]) -> \"Aggregate\":\n        \"\"\"Create Aggregate expression from dictionary.\n\n        Supports:\n        - {\"$min_k\": {\"keys\": [...], \"k\": n}} -> MinK(keys=[...], k=n)\n        - {\"$max_k\": {\"keys\": [...], \"k\": n}} -> MaxK(keys=[...], k=n)\n        \"\"\"\n        if not isinstance(data, dict):\n            raise TypeError(f\"Expected dict for Aggregate, got {type(data).__name__}\")\n\n        if not data:\n            raise ValueError(\"Aggregate dict cannot be empty\")\n\n        if len(data) != 1:\n            raise ValueError(\n                f\"Aggregate dict must contain exactly one operator, got {len(data)}\"\n            )\n\n        op = next(iter(data.keys()))\n\n        if op == \"$min_k\":\n            keys, k = _parse_k_aggregate(op, data)\n            return MinK(keys=keys, k=k)\n        elif op == \"$max_k\":\n            keys, k = _parse_k_aggregate(op, data)\n            return MaxK(keys=keys, k=k)\n        else:\n            raise ValueError(f\"Unknown aggregate operator: {op}\")\n\n","sourceCodeStart":1395,"sourceCodeEnd":1431,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/execution/expression/operator.py#L1395-L1431","documentation":"Raised by Aggregate.from_dict when the aggregate dict is empty ({}). At least one operator ($min_k or $max_k) with its parameters must be present to form a valid aggregation.","triggerScenarios":"Thrown at chromadb/execution/expression/operator.py:1413 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Include exactly one operator key in the dict, e.g. {\"$max_k\": {\"keys\": [\"#score\"], \"k\": 2}}","If no aggregation is needed, omit the aggregate field instead of sending an empty dict"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","contentChangedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}