chroma-core/chroma · error · ChromaValueError
${item} is not allowed for this operation
Error message
${item} is not allowed for this operation What it means
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.
Source
Thrown at clients/new-js/packages/chromadb/src/utils.ts:742
throw new ChromaValueError("Expected 'include' to be a non-empty array");
}
const validValues = Object.keys(IncludeEnum);
include.forEach((item) => {
if (typeof (item as any) !== "string") {
throw new ChromaValueError("Expected 'include' items to be strings");
}
if (!validValues.includes(item)) {
throw new ChromaValueError(
`Expected 'include' items to be one of ${validValues.join(
", ",
)}, but got ${item}`,
);
}
if (exclude?.includes(item)) {
throw new ChromaValueError(`${item} is not allowed for this operation`);
}
});
};
/**
* Validates the number of results parameter for queries.
* @param nResults - Number of results to validate
* @throws ChromaValueError if nResults is not a positive number
*/
export const validateNResults = (nResults: number) => {
if (typeof (nResults as any) !== "number") {
throw new ChromaValueError(
`Expected 'nResults' to be a number, but got ${typeof nResults}`,
);
}
if (nResults <= 0) {
throw new ChromaValueError("Number of requested results has to positive");View on GitHub (pinned to aecdd12c8a)
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')
Example fix
// before
await col.get({ include: ['documents', 'metadatas', 'distances'] });
// after
await col.get({ include: ['documents', 'metadatas'] });
// distances are only available via col.query(...) Defensive patterns
Strategy: validation
Validate before calling
const ALL = ['documents', 'embeddings', 'metadatas', 'uris']; const getInclude = wantsDistances => (wantsDistances ? [...ALL, 'distances'] : ALL); // get(): getInclude(false) — never contains 'distances' // query(): getInclude(true)
Type guard
const isGetSafeInclude = (v: unknown): v is string[] => Array.isArray(v) && v.every(i => i !== 'distances');
Try / catch
try {
await col.get({ include });
} catch (e) {
if (e instanceof Error && e.message.includes('not allowed for this operation')) {
await col.get({ include: include.filter(i => i !== 'distances') });
} else throw e;
} Prevention
- 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
When it happens
Trigger: collection.get({ include: ['documents', 'distances'] }); a shared include constant reused by both a query() code path and a get() code path.
Common situations: A generic fetch helper that always requests every field; refactoring a query() call into get() without trimming the include list.
Related errors
- Expected 'include' to be a non-empty array
- Expected 'include' items to be strings
- Expected 'include' items to be one of ${validValues.join(",
- Expected metadata to be non-empty
- Expected metadata list value for key '${key}' to be non-empt
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/f7b216727986fc46.
Report an issue: GitHub.