{"record":{"id":"dc3b75b5f93e45dc","repo":"chroma-core/chroma","slug":"unable-to-connect-to-the-chromadb-server-please-t","errorCode":null,"errorMessage":"Unable to connect to the chromadb server. Please try again later.","messagePattern":"Unable to connect to the chromadb server\\. Please try again later\\.","errorType":"http","errorClass":"ChromaConnectionError","httpStatus":502,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/ChromaFetch.ts","lineNumber":92,"sourceCode":"            `The requested resource could not be found: ${input}`,\n          );\n        case 409:\n          throw new ChromaUniqueError(\"The resource already exists\");\n        case 422:\n          if (\n            respBody?.message &&\n            (respBody?.message.startsWith(\"Quota exceeded\") ||\n              respBody?.message.startsWith(\"Billing limit exceeded\"))\n          ) {\n            throw new ChromaQuotaExceededError(respBody?.message);\n          }\n          break;\n        case 500:\n          throw parseServerError(respBody?.error);\n        case 502:\n        case 503:\n        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.\",","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/ChromaFetch.ts#L74-L110","documentation":"_parse_k_aggregate() (operator.py:1369-1371) requires the 'k' of a '$min_k'/'$max_k' aggregation to be a Python int and raises TypeError otherwise. k is the per-group record count kept by the aggregation, used directly as MinK(k=...)/MaxK(k=...) (operator.py:1422-1427). Floats (3.0), numeric strings (\"3\"), and None all fail isinstance(k, int); the check is strict because a non-int k could not bound group sizes reliably. Note the parser checks keys before k, so reaching this error means keys already validated.","triggerScenarios":"{\"k\": 3.0} from JSON/YAML where the author wrote a float; {\"k\": \"3\"} — quoted number from a config or HTML form; {\"k\": null} — unfilled template placeholder; {\"k\": [3]} — over-eager wrapping into a list; values arriving via pydantic/YAML typed as float or str.","commonSituations":"YAML configs where k: 3.0 or k is parsed as float by a loader; strings from env vars or HTTP query params pasted into payloads; jq-based payload builders leaving numbers quoted; NumPy integer scalars from data pipelines (np.int64 is not a Python int and fails the isinstance check in CPython).","solutions":["Write k as a plain integer literal: {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 3}}.","Coerce untyped input before building the payload: k_int = int(k) (or reject non-integer values) — but never send the raw string/float.","For NumPy scalars convert explicitly: int(np.int64(n)).","Keep k >= 1 — k must also be positive (checked next at operator.py:1372-1373)."],"exampleFix":"// before\naggregate = {\"$min_k\": {\"keys\": [\"#score\"], \"k\": \"3\"}}   # TypeError: $min_k k must be an integer, got str\n\n# after\naggregate = {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 3}}","handlingStrategy":"validation","validationCode":"def agg_k_is_int(payload: dict) -> bool:\n    op = next(iter(payload))\n    body = payload.get(op, {})\n    k = body.get(\"k\")\n    return isinstance(k, int) and not isinstance(k, bool)","typeGuard":"def is_int_k(v: Any) -> TypeGuard[int]:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":"try:\n    Aggregate.from_dict(agg)\nexcept TypeError as e:\n    if \"k must be an integer\" in str(e):\n        op = next(iter(agg))\n        try:\n            agg[op][\"k\"] = int(agg[op][\"k\"])\n        except (TypeError, ValueError):\n            raise ValueError(f\"Unusable k value: {agg[op]['k']!r}\") from e\n    else:\n        raise","preventionTips":["Write k as a bare integer in JSON/YAML (no quotes, no decimal point).","Coerce once at the boundary: int(k) for strings/floats, int(np.int64(n)) for NumPy scalars.","Reject bools explicitly if you sanitize k — isinstance(True, int) is True in Python."],"tags":["chromadb","aggregate","typeerror","k","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"}