{"record":{"id":"98fe6e448b2e8d50","repo":"chroma-core/chroma","slug":"failed-to-fetch-input-with-status-resp-status","errorCode":null,"errorMessage":"Failed to fetch ${input} with status ${resp.status}: ${resp.statusText}","messagePattern":"Failed to fetch (.+?) with status (.+?): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/ChromaFetch.ts","lineNumber":97,"sourceCode":"          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.\",\n        error,\n      );\n    }\n    throw error;\n  }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/ChromaFetch.ts#L79-L115","documentation":"_parse_k_aggregate() (operator.py:1372-1373) raises ValueError when the 'k' of a '$min_k'/'$max_k' aggregation is an int but is zero or negative. Keeping fewer than one record per group makes the aggregation a no-op that would drop every row, so k must satisfy k > 0. This is the last field check before the parser returns (_strings_to_keys(keys), k) at operator.py:1375, so hitting it means keys and k's type already passed.","triggerScenarios":"{\"k\": 0} — assuming 0 means 'no limit' or 'default'; {\"k\": -1} — using the common '-1 means all' API convention; k computed as len(something) that evaluated to 0 (empty request); config defaulting to 0 before user input arrives.","commonSituations":"Porting conventions from other APIs (SQL LIMIT -1, HTTP page_size=0) where 0/-1 are sentinels; zero-initialized variables used before being set; template defaults of 0; math that can go negative (k = limit - offset) without a lower clamp.","solutions":["Set k to a positive integer (1 or more): {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 3}}.","To disable grouping entirely, omit group_by (None / empty dict) rather than using k=0 as a sentinel.","Clamp computed k: k = max(1, computed_k), or fail fast in your config layer when the computed value is < 1.","Treat k=0/-1 inputs from users as validation errors at your API boundary, not values forwarded to Chroma."],"exampleFix":"// before\naggregate = {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 0}}   # ValueError: $min_k k must be positive, got 0\n\n# after\naggregate = {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 3}}","handlingStrategy":"validation","validationCode":"def agg_k_positive(payload: dict) -> bool:\n    op = next(iter(payload))\n    k = payload.get(op, {}).get(\"k\")\n    return isinstance(k, int) and not isinstance(k, bool) and k > 0","typeGuard":"def is_valid_k(v: Any) -> TypeGuard[int]:\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":"try:\n    Aggregate.from_dict(agg)\nexcept ValueError as e:\n    if \"k must be positive\" in str(e):\n        raise ValueError(\"k must be >= 1; to disable grouping omit group_by \"\n                         \"instead of using k=0/-1 sentinels\") from e\n    raise","preventionTips":["No 0/-1 sentinels exist — k is always >= 1.","Clamp computed k: max(1, computed).","Validate user-supplied k ranges at your API boundary before forwarding."],"tags":["chromadb","aggregate","invalid-value","valueerror","k","min-k","max-k"],"backgroundTag":"invalid-parameter-value","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}