chroma-core/chroma · error · Error

Failed to fetch ${input} with status ${resp.status}: ${resp.

Error message

Failed to fetch ${input} with status ${resp.status}: ${resp.statusText}

What it means

_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.

Source

Thrown at clients/js/packages/chromadb-core/src/ChromaFetch.ts:97

          if (
            respBody?.message &&
            (respBody?.message.startsWith("Quota exceeded") ||
              respBody?.message.startsWith("Billing limit exceeded"))
          ) {
            throw new ChromaQuotaExceededError(respBody?.message);
          }
          break;
        case 500:
          throw parseServerError(respBody?.error);
        case 502:
        case 503:
        case 504:
          throw new ChromaConnectionError(
            `Unable to connect to the chromadb server. Please try again later.`,
          );
      }

      throw new Error(
        `Failed to fetch ${input} with status ${resp.status}: ${resp.statusText}`,
      );
    }

    if (respBody?.error) {
      throw parseServerError(respBody.error);
    }

    return resp;
  } catch (error) {
    if (isOfflineError(error)) {
      throw new ChromaConnectionError(
        "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.",
        error,
      );
    }
    throw error;
  }

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Set k to a positive integer (1 or more): {"$min_k": {"keys": ["#score"], "k": 3}}.
  2. To disable grouping entirely, omit group_by (None / empty dict) rather than using k=0 as a sentinel.
  3. Clamp computed k: k = max(1, computed_k), or fail fast in your config layer when the computed value is < 1.
  4. Treat k=0/-1 inputs from users as validation errors at your API boundary, not values forwarded to Chroma.

Example fix

// before
aggregate = {"$min_k": {"keys": ["#score"], "k": 0}}   # ValueError: $min_k k must be positive, got 0

# after
aggregate = {"$min_k": {"keys": ["#score"], "k": 3}}
Defensive patterns

Strategy: validation

Validate before calling

def agg_k_positive(payload: dict) -> bool:
    op = next(iter(payload))
    k = payload.get(op, {}).get("k")
    return isinstance(k, int) and not isinstance(k, bool) and k > 0

Type guard

def is_valid_k(v: Any) -> TypeGuard[int]:
    return isinstance(v, int) and not isinstance(v, bool) and v > 0

Try / catch

try:
    Aggregate.from_dict(agg)
except ValueError as e:
    if "k must be positive" in str(e):
        raise ValueError("k must be >= 1; to disable grouping omit group_by "
                         "instead of using k=0/-1 sentinels") from e
    raise

Prevention

When it happens

Trigger: {"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.

Common situations: 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.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/98fe6e448b2e8d50. Report an issue: GitHub.