{"record":{"id":"3a6f6e53e9c45b4c","repo":"chroma-core/chroma","slug":"failed-to-connect-to-chromadb-make-sure-your-serv","errorCode":null,"errorMessage":"Failed to connect to chromadb. Make sure your server is running and try again. If you are running from a browser, make sure that your chromadb instance is configured to allow requests from the current origin using the CHROMA_SERVER_CORS_ALLOW_ORIGINS environment variable.","messagePattern":"Failed to connect to chromadb\\. Make sure your server is running and try again\\. If you are running from a browser, make sure that your chromadb instance is configured to allow requests from the current origin using the CHROMA_SERVER_CORS_ALLOW_ORIGINS environment variable\\.","errorType":"exception","errorClass":"ChromaConnectionError","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/ChromaFetch.ts","lineNumber":109,"sourceCode":"        case 504:\n          throw new ChromaConnectionError(\n            `Unable to connect to the chromadb server. Please try again later.`,\n          );\n      }\n\n      throw new Error(\n        `Failed to fetch ${input} with status ${resp.status}: ${resp.statusText}`,\n      );\n    }\n\n    if (respBody?.error) {\n      throw parseServerError(respBody.error);\n    }\n\n    return resp;\n  } catch (error) {\n    if (isOfflineError(error)) {\n      throw new ChromaConnectionError(\n        \"Failed to connect to chromadb. Make sure your server is running and try again. If you are running from a browser, make sure that your chromadb instance is configured to allow requests from the current origin using the CHROMA_SERVER_CORS_ALLOW_ORIGINS environment variable.\",\n        error,\n      );\n    }\n    throw error;\n  }\n};\n","sourceCodeStart":91,"sourceCodeEnd":117,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/ChromaFetch.ts#L91-L117","documentation":"Aggregate.from_dict() (operator.py:1409-1410) rejects any payload that is not a dict with a TypeError. Aggregate is the base of MinK/MaxK, the per-group 'keep k records' expressions, and its dict form is a single-entry mapping like {\"$min_k\": {\"keys\": [...], \"k\": n}} — mirroring what MinK.to_dict()/MaxK.to_dict() emit (operator.py:1440,1449). A list, string, or None cannot name an operator, so decoding aborts immediately. In normal use this is reached through GroupBy.from_dict, which validates that the group_by 'aggregate' field is a dict first (operator.py:1530-1533), so a direct Aggregate.from_dict call on bad input is the usual trigger.","triggerScenarios":"GroupBy.from_dict({\"keys\": [...], \"aggregate\": [...]}) is intercepted one step earlier by the aggregate-is-dict check; this specific error fires on direct calls like Aggregate.from_dict([\"$min_k\", {...}]) — a positional pair instead of a mapping; Aggregate.from_dict(MinK(...)) — passing the typed object itself; Aggregate.from_dict(None) or a JSON string body that was not json.loads-ed.","commonSituations":"Wrappers that accept 'aggregate' params of several shapes and forward them unconverted; double-encoded JSON payloads; refactoring from typed MinK(...) constructors to dict payloads and forwarding the old object; config systems delivering a list of operator/args pairs.","solutions":["Use the nested single-operator mapping: {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 3}}.","If you have a typed object already, pass it through — GroupBy accepts MinK/MaxK instances directly; from_dict is only for dicts.","json.loads the payload string before decoding.","Inside group_by, nest aggregate as a dict value: {\"keys\": [...], \"aggregate\": {\"$min_k\": {...}}}."],"exampleFix":"// before\nagg = Aggregate.from_dict([\"$min_k\", {\"keys\": [\"#score\"], \"k\": 3}])\n# TypeError: Expected dict for Aggregate, got list\n\n# after\nagg = Aggregate.from_dict({\"$min_k\": {\"keys\": [\"#score\"], \"k\": 3}})","handlingStrategy":"type-guard","validationCode":"def is_aggregate_payload(v: Any) -> bool:\n    return isinstance(v, dict) and len(v) > 0","typeGuard":"def is_aggregate_dict(v: Any) -> TypeGuard[Dict[str, Any]]:\n    return isinstance(v, dict) and len(v) == 1 and next(iter(v)) in {\"$min_k\", \"$max_k\"}","tryCatchPattern":"try:\n    Aggregate.from_dict(payload)\nexcept TypeError as e:\n    raise ValueError(\n        f\"Aggregate must be a dict like {{'$min_k': {{'keys': [...], 'k': n}}}}, got {payload!r}\"\n    ) from e","preventionTips":["Forward MinK/MaxK objects as-is; call from_dict only on dict payloads.","json.loads JSON strings before decoding.","Keep the operator->body nesting: never a positional list [op, body]."],"tags":["chromadb","aggregate","typeerror","deserialization","min-k","max-k"],"backgroundTag":"dict-schema-validation-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}