{"record":{"id":"071fc7d9e5f3f90e","repo":"chroma-core/chroma","slug":"not-regex-requires-a-string-pattern","errorCode":null,"errorMessage":"$not_regex requires a string pattern","messagePattern":"\\$not_regex requires a string pattern","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/execution/expression/key.ts","lineNumber":93,"sourceCode":"   * K(\"tags\").notContains(\"draft\")          // metadata array not-contains\n   */\n  public notContains(value: string | number | boolean): WhereExpression {\n    if (this.name === \"#document\" && typeof value !== \"string\") {\n      throw new TypeError(\"K.DOCUMENT.notContains requires a string value\");\n    }\n    return createComparisonWhere(this.name, \"$not_contains\", value);\n  }\n\n  public regex(pattern: string): WhereExpression {\n    if (typeof pattern !== \"string\") {\n      throw new TypeError(\"$regex requires a string pattern\");\n    }\n    return createComparisonWhere(this.name, \"$regex\", pattern);\n  }\n\n  public notRegex(pattern: string): WhereExpression {\n    if (typeof pattern !== \"string\") {\n      throw new TypeError(\"$not_regex requires a string pattern\");\n    }\n    return createComparisonWhere(this.name, \"$not_regex\", pattern);\n  }\n}\n\nexport interface KeyFactory {\n  (name: string): Key;\n  ID: Key;\n  DOCUMENT: Key;\n  EMBEDDING: Key;\n  METADATA: Key;\n  SCORE: Key;\n}\n\nconst createKeyFactory = (): KeyFactory => {\n  const factory = ((name: string) => new Key(name)) as KeyFactory;\n  factory.ID = Key.ID;\n  factory.DOCUMENT = Key.DOCUMENT;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/execution/expression/key.ts#L75-L111","documentation":"Key.notRegex(pattern) builds a $not_regex where-filter and requires the pattern to be a string at runtime. Non-string patterns — RegExp objects, numbers, null/undefined — raise a TypeError client-side before the filter is serialized.","triggerScenarios":"K(\"title\").notRegex(re) where re is a RegExp instance; .notRegex(undefined) when a configurable exclusion pattern is not set.","commonSituations":"Mirroring a regex filter feature with an exclusion variant and reusing a compiled RegExp. Config-driven exclusion patterns that may be missing (undefined) in some environments. JS callers or any-typed values bypassing the declared string parameter.","solutions":["Pass a string pattern: K(\"title\").notRegex(\"draft|deprecated\")","Use re.source when starting from a RegExp object","Conditionally apply the filter only when the configured pattern is a non-empty string"],"exampleFix":"// before\nK(\"title\").notRegex(cfg.exclusionPattern); // undefined in prod -> TypeError\n\n// after\nconst where = typeof cfg.exclusionPattern === \"string\"\n  ? K(\"title\").notRegex(cfg.exclusionPattern)\n  : undefined;","handlingStrategy":"validation","validationCode":"const pattern = typeof cfg.exclusionPattern === \"string\" ? cfg.exclusionPattern : undefined;\nconst where = pattern ? K(\"title\").notRegex(pattern) : undefined;","typeGuard":"const isPatternString = (v: unknown): v is string => typeof v === \"string\" && v.length > 0;","tryCatchPattern":null,"preventionTips":["Pass re.source, never a RegExp instance, to notRegex","Treat a missing exclusion pattern as 'no filter' and skip the call","Validate optional patterns at config load time"],"tags":["chroma","where-filter","regex","typeerror"],"backgroundTag":"wrong-argument-type","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}