mem0ai/mem0 · error

AND operator requires a list of conditions

Error message

AND operator requires a list of conditions

What it means

Thrown during metadata filter preprocessing when the AND key's value is not an array. AND in this filter DSL is a list of condition objects, each processed via processCondition; a single object or a scalar cannot be combined. It fires before any vector store call.

Source

Thrown at mem0-ts/src/oss/src/memory/index.ts:2151

      for (const [operator, value] of Object.entries(condition)) {
        if (operator in operatorMap) {
          if (!result[key]) {
            result[key] = {};
          }
          result[key][operatorMap[operator]] = value;
        } else {
          throw new Error(`Unsupported metadata filter operator: ${operator}`);
        }
      }
      return result;
    };

    for (const [key, value] of Object.entries(metadataFilters)) {
      if (key === "AND") {
        // Logical AND: combine multiple conditions
        if (!Array.isArray(value)) {
          throw new Error("AND operator requires a list of conditions");
        }
        for (const condition of value) {
          for (const [subKey, subValue] of Object.entries(condition)) {
            Object.assign(processedFilters, processCondition(subKey, subValue));
          }
        }
      } else if (key === "OR") {
        // Logical OR: Pass through to vector store for implementation-specific handling
        if (!Array.isArray(value) || value.length === 0) {
          throw new Error(
            "OR operator requires a non-empty list of conditions",
          );
        }
        processedFilters["$or"] = [];
        for (const condition of value) {
          const orCondition: Record<string, any> = {};
          for (const [subKey, subValue] of Object.entries(
            condition as Record<string, any>,

View on GitHub (pinned to 001c235229)

Solutions

  1. Wrap AND conditions in an array: AND: [{ category: { equals: 'pref' } }]
  2. Even a single condition must be inside the list
  3. Type your filter objects against the SDK's filter types so the compiler catches this

Example fix

// before
{ user_id: 'u1', AND: { category: { equals: 'pref' } } }

// after
{ user_id: 'u1', AND: [{ category: { equals: 'pref' } }] }
Defensive patterns

Strategy: type-guard

Validate before calling

function validAnd(v: unknown): boolean { return Array.isArray(v) && v.length > 0 && v.every(c => typeof c === 'object' && c !== null); }

Type guard

const isConditionList = (v: unknown): v is Record<string, Record<string, unknown>>[] =>
  Array.isArray(v) && v.every((c) => typeof c === 'object' && c !== null);

Prevention

When it happens

Trigger: Writing filters: { user_id: 'u1', AND: { category: { equals: 'pref' } } } — an object instead of a list; or AND: 'category' (scalar).

Common situations: Copying a Mongo-style nested object (no array wrapper) from other query DSLs; forgetting the array brackets when there is only one condition.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/61deb5a16ff9adc9. Report an issue: GitHub.