{"record":{"id":"8cb9af4499d48a56","repo":"chroma-core/chroma","slug":"invalid-hnsw-config-provided","errorCode":null,"errorMessage":"Invalid HNSW config provided","messagePattern":"Invalid HNSW config provided","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/CollectionConfiguration.ts","lineNumber":205,"sourceCode":"  }\n}\n\nexport function collectionConfigurationToJson(\n  config: CollectionConfiguration,\n): Record<string, any> {\n  if (config.hnsw && config.spann) {\n    throw new InvalidConfigurationError(\n      \"Cannot specify both 'hnsw' and 'spann' configurations.\",\n    );\n  }\n  let hnswConfig = config.hnsw;\n  let spannConfig = config.spann;\n  let ef = config.embedding_function;\n  let efConfig = serializeEmbeddingFunction(ef);\n\n  // Basic validation/casting attempt (already done in create/update, but maybe check types?)\n  if (hnswConfig && typeof hnswConfig !== \"object\") {\n    throw new Error(\"Invalid HNSW config provided\");\n  }\n  if (spannConfig && typeof spannConfig !== \"object\") {\n    throw new Error(\"Invalid SPANN config provided\");\n  }\n\n  // Note: Validation (like validateCreateHnswConfig) is tied to creation/update actions\n  // not necessarily to retrieving/displaying the existing config.\n\n  return {\n    hnsw: hnswConfig,\n    spann: spannConfig,\n    embedding_function: efConfig,\n  };\n}\n\nexport function collectionConfigurationToJsonStr(\n  config: CollectionConfiguration,\n): string {","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/CollectionConfiguration.ts#L187-L223","documentation":"GroupBy.from_dict() (operator.py:1520-1521) raises ValueError when a non-empty group_by dict lacks the 'aggregate' field. Chroma's grouping is always grouping-plus-aggregation: 'keys' partitions rows and 'aggregate' (a '$min_k'/'$max_k' expression) decides which k rows each group contributes — there is no 'just group everything' mode, so a keys-only dict is incomplete and rejected. The check order is keys first (operator.py:1518), so this error means 'keys' was present but 'aggregate' was not; chromadb/test/test_api.py:3219 pins this behavior.","triggerScenarios":"GroupBy.from_dict({\"keys\": [\"category\"]}) — SQL-style GROUP BY with no reduction; authors who want one representative row per group but omit the top-1 spec; 'aggregate' spelled differently ('agg', 'aggregation') in config; builders that omit aggregate when a default was assumed.","commonSituations":"Porting SQL GROUP BY mental models where aggregates are optional; assuming a default of '$min_k on #score, k=1'; config systems abbreviating field names; payloads assembled from partial templates.","solutions":["Add the aggregate, most commonly top-1 per group: {\"keys\": [\"category\"], \"aggregate\": {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 1}}}.","Use the exact field name 'aggregate' holding a single-operator dict ($min_k/$max_k).","For 'best n per group' semantics use $min_k on [\"#score\"] with k=n (lower Chroma score = more similar).","If you actually want all rows ungrouped, omit group_by entirely — there is no group-without-aggregate mode."],"exampleFix":"// before\ngroup_by = {\"keys\": [\"category\"]}\n# ValueError: GroupBy requires 'aggregate' field\n\n# after\ngroup_by = {\"keys\": [\"category\"], \"aggregate\": {\"$min_k\": {\"keys\": [\"#score\"], \"k\": 1}}}","handlingStrategy":"validation","validationCode":"def groupby_has_aggregate(payload: dict) -> bool:\n    return len(payload) == 0 or (\"keys\" in payload and \"aggregate\" in payload)","typeGuard":"def is_complete_groupby(v: Any) -> TypeGuard[Dict[str, Any]]:\n    if not isinstance(v, dict) or not v:\n        return isinstance(v, dict)\n    return (\n        set(v.keys()) == {\"keys\", \"aggregate\"}\n        and isinstance(v[\"keys\"], (list, tuple))\n        and len(v[\"keys\"]) > 0\n        and isinstance(v[\"aggregate\"], dict)\n    )","tryCatchPattern":"try:\n    GroupBy.from_dict(payload)\nexcept ValueError as e:\n    if \"requires 'aggregate' field\" in str(e):\n        raise ValueError(\"Grouping always pairs with an aggregation; add e.g. \"\n                         \"'aggregate': {'$min_k': {'keys': ['#score'], 'k': 1}}\") from e\n    raise","preventionTips":["There is no group-without-aggregate mode — every group_by carries an aggregate.","Best-per-group recipe: {'$min_k': {'keys': ['#score'], 'k': 1}}.","Field name is exactly 'aggregate', not 'agg'."],"tags":["chromadb","groupby","missing-field","valueerror","aggregate"],"backgroundTag":"missing-required-field","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}