mem0ai/mem0 · error · Error

payloads and vectors must have the same length

Error message

payloads and vectors must have the same length

What it means

The second arity guard in insert(): the payloads array must also be exactly as long as vectors, since each INSERT row binds one payload JSON per vector. As with ids, a mismatch means some rows would get undefined payloads, so it is rejected before touching the database.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/oracledb.ts:580

      type: this.oracledb.DB_TYPE_VECTOR,
      val: new Float32Array(vector),
    };
  }

  private payloadBind(payload: Record<string, any>) {
    return { type: this.oracledb.DB_TYPE_JSON, val: payload };
  }

  async insert(
    vectors: number[][],
    ids: string[],
    payloads: Record<string, any>[],
  ): Promise<void> {
    if (ids.length !== vectors.length) {
      throw new Error("ids and vectors must have the same length");
    }
    if (payloads.length !== vectors.length) {
      throw new Error("payloads and vectors must have the same length");
    }

    if (vectors.length === 0) return;

    await this.initialize();

    await this.withConnection(async (connection) => {
      await connection.executeMany(
        `INSERT INTO ${this.collectionName} (id, vector, payload) VALUES (:id, :vector, :payload)`,
        vectors.map((vector, i) => ({
          id: ids[i],
          vector: new Float32Array(vector),
          payload: payloads[i] ?? {},
        })) as BindParameters[],
        {
          bindDefs: {
            id: { type: this.oracledb.DB_TYPE_VARCHAR, maxSize: 36 },
            vector: { type: this.oracledb.DB_TYPE_VECTOR },

View on GitHub (pinned to 001c235229)

Solutions

  1. Construct payloads with a default ({}) for every item: items.map((i) => i.metadata ?? {}).
  2. Keep id/vector/payload as row tuples through the whole pipeline and unzip only at insert time.
  3. Add a pre-insert assertion covering all three arrays: equal lengths, non-zero unless intentionally empty.
  4. Audit ingestion loops for pushes into one array inside conditionals that skip the others.

Example fix

// before
const payloads = items.filter((i) => i.metadata).map((i) => i.metadata); // shorter than vectors
await store.insert(vectors, ids, payloads);

// after
await store.insert(vectors, ids, items.map((i) => i.metadata ?? {}));
Defensive patterns

Strategy: validation

Validate before calling

const payloads = items.map((i) => i.payload ?? {}); // guaranteed 1:1 with vectors
if (payloads.length !== vectors.length) throw new RangeError('payload/vector mismatch');

Try / catch

try { await store.insert(vectors, ids, payloads); } catch (e) { if (e instanceof Error && e.message.includes('payloads and vectors')) { /* default missing payloads to {} and re-align arrays */ } else throw e; }

Prevention

When it happens

Trigger: Calling insert(vectors, ids, payloads) where payloads were built per successfully-embedded item but vectors include failures, or vice versa; memory.add() paths that build payloads from metadata where some items lacked metadata and were skipped.

Common situations: Partial-failure ingestion loops that push to vectors on success but push to payloads only when metadata exists (or the reverse); mapping/filter steps applied to only one of the arrays; defaulting payloads to [] thinking it will be filled in.

Related errors


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