{"record":{"id":"f7b216727986fc46","repo":"chroma-core/chroma","slug":"item-is-not-allowed-for-this-operation","errorCode":null,"errorMessage":"${item} is not allowed for this operation","messagePattern":"(.+?) is not allowed for this operation","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":742,"sourceCode":"    throw new ChromaValueError(\"Expected 'include' to be a non-empty array\");\n  }\n\n  const validValues = Object.keys(IncludeEnum);\n  include.forEach((item) => {\n    if (typeof (item as any) !== \"string\") {\n      throw new ChromaValueError(\"Expected 'include' items to be strings\");\n    }\n\n    if (!validValues.includes(item)) {\n      throw new ChromaValueError(\n        `Expected 'include' items to be one of ${validValues.join(\n          \", \",\n        )}, but got ${item}`,\n      );\n    }\n\n    if (exclude?.includes(item)) {\n      throw new ChromaValueError(`${item} is not allowed for this operation`);\n    }\n  });\n};\n\n/**\n * Validates the number of results parameter for queries.\n * @param nResults - Number of results to validate\n * @throws ChromaValueError if nResults is not a positive number\n */\nexport const validateNResults = (nResults: number) => {\n  if (typeof (nResults as any) !== \"number\") {\n    throw new ChromaValueError(\n      `Expected 'nResults' to be a number, but got ${typeof nResults}`,\n    );\n  }\n\n  if (nResults <= 0) {\n    throw new ChromaValueError(\"Number of requested results has to positive\");","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L724-L760","documentation":"validateInclude takes an optional exclude list, and collection.get() calls it with exclude: ['distances'] (collection.ts:809) because similarity distances only exist for vector queries. Requesting 'distances' in a get() therefore throws '`distances` is not allowed for this operation' (utils.ts:741-743). query() passes no exclude, so all five include values are legal there.","triggerScenarios":"collection.get({ include: ['documents', 'distances'] }); a shared include constant reused by both a query() code path and a get() code path.","commonSituations":"A generic fetch helper that always requests every field; refactoring a query() call into get() without trimming the include list.","solutions":["Remove 'distances' from include when calling get()","Use collection.query() with queryTexts/queryEmbeddings when you need distances","Derive get's include from a shared list: sharedInclude.filter(f => f !== 'distances')"],"exampleFix":"// before\nawait col.get({ include: ['documents', 'metadatas', 'distances'] });\n\n// after\nawait col.get({ include: ['documents', 'metadatas'] });\n// distances are only available via col.query(...)","handlingStrategy":"validation","validationCode":"const ALL = ['documents', 'embeddings', 'metadatas', 'uris'];\nconst getInclude = wantsDistances => (wantsDistances ? [...ALL, 'distances'] : ALL);\n// get(): getInclude(false) — never contains 'distances'\n// query(): getInclude(true)","typeGuard":"const isGetSafeInclude = (v: unknown): v is string[] =>\n  Array.isArray(v) && v.every(i => i !== 'distances');","tryCatchPattern":"try {\n  await col.get({ include });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('not allowed for this operation')) {\n    await col.get({ include: include.filter(i => i !== 'distances') });\n  } else throw e;\n}","preventionTips":["Keep separate include lists for get() and query()","Filter 'distances' out of any shared include constant before calling get()","Remember distances are meaningful only for vector similarity queries"],"tags":["javascript","validation","include","get-vs-query"],"backgroundTag":"invalid-include-parameter","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}