{"record":{"id":"0c5745f5e9e496c1","repo":"mem0ai/mem0","slug":"and-filter-value-must-be-a-list-of-filter-dicts-g-0c5745","errorCode":null,"errorMessage":"AND filter value must be a list of filter dicts, got ${typeof value}","messagePattern":"AND filter value must be a list of filter dicts, got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/databricks.ts","lineNumber":1583,"sourceCode":"    }\n\n    const keyMap: Record<string, string> = {\n      $and: \"AND\",\n      $or: \"OR\",\n      $not: \"NOT\",\n    };\n    const normalized: Record<string, any> = {};\n    for (const [key, value] of Object.entries(filters)) {\n      const normalizedKey = keyMap[key] || key;\n      if (!(normalizedKey in normalized)) {\n        normalized[normalizedKey] = value;\n      }\n    }\n\n    for (const [key, value] of Object.entries(normalized)) {\n      if (key === \"AND\") {\n        if (!Array.isArray(value)) {\n          throw new Error(\n            `AND filter value must be a list of filter dicts, got ${typeof value}`,\n          );\n        }\n        if (\n          !value.every((entry: SearchFilters) =>\n            this.filterVector(vector, entry),\n          )\n        ) {\n          return false;\n        }\n      } else if (key === \"OR\") {\n        if (!Array.isArray(value)) {\n          throw new Error(\n            `OR filter value must be a list of filter dicts, got ${typeof value}`,\n          );\n        }\n        if (\n          !value.some((entry: SearchFilters) =>","sourceCodeStart":1565,"sourceCodeEnd":1601,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/databricks.ts#L1565-L1601","documentation":"filterVector() throws when a filters object contains an AND key whose value is not an array. After key normalization ($and maps to AND), the compound AND filter is expected to be a list of sub-filter dicts applied with .every(); a non-array value cannot be evaluated, so the provider fails fast rather than silently skipping the filter.","triggerScenarios":"Calling search()/list() with filters like { AND: { user_id: 'u1' } } (object instead of array), or { $and: 'user_id' } (string). Correct shape is { AND: [{ user_id: 'u1' }, { run_id: 'r1' }] }.","commonSituations":"Translating Qdrant-style or Python-dict filter syntax into the TS SDK and forgetting the list wrapper around $and branches; building filters dynamically where an empty/single condition collapses to a bare object.","solutions":["Wrap AND branches in an array: { AND: [ {...}, {...} ] }.","When building filters programmatically, always push sub-filters into an array even for a single condition.","If the filter came from JSON config, validate its shape before passing it to search()."],"exampleFix":"// before\nstore.search(query, 5, { $and: { user_id: 'u1', run_id: 'r2' } });\n\n// after\nstore.search(query, 5, { $and: [{ user_id: 'u1' }, { run_id: 'r2' }] });","handlingStrategy":"type-guard","validationCode":"const isCompoundList = (f: Record<string, unknown>) =>\n  (['AND', 'OR', 'NOT'] as const).every((k) => !(k in f) || Array.isArray(f[k]));\nif (!isCompoundList(filters)) throw new Error('AND/OR/NOT branches must be arrays');","typeGuard":"type Branch = Record<string, string | number | boolean>;\ninterface SafeFilters {\n  AND?: Branch[];\n  OR?: Branch[];\n  NOT?: Branch[];\n  [k: string]: unknown;\n}\nconst isSafeFilters = (f: unknown): f is SafeFilters =>\n  typeof f === 'object' && f !== null &&\n  Object.entries(f).every(([k, v]) =>\n    ['AND', 'OR', 'NOT'].includes(k) ? Array.isArray(v) : true,\n  );","tryCatchPattern":"try {\n  await store.search(q, k, filters);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('AND filter value must be a list')) {\n    // rewrite { AND: {...} } to { AND: [{...}] } and retry\n  }\n  throw e;\n}","preventionTips":["Always author compound branches as arrays of single-key objects, even with one condition.","Centralize filter construction in one typed helper.","Add unit tests asserting the array shape for AND/OR/NOT."],"tags":["databricks","filters","validation","vector-store","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}