{"record":{"id":"f368795701c9dc93","repo":"mem0ai/mem0","slug":"baidu-insert-requires-vectors-ids-and-payloads-o","errorCode":null,"errorMessage":"Baidu insert requires vectors, ids, and payloads of equal length (got ${vectors.length}/${ids.length}/${payloads.length}).","messagePattern":"Baidu insert requires vectors, ids, and payloads of equal length \\(got (.+?)/(.+?)/(.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/baidu.ts","lineNumber":412,"sourceCode":"    if (!this._initPromise) {\n      this._initPromise = this.ensureTable().catch((error) => {\n        this._initPromise = undefined;\n        throw error;\n      });\n    }\n\n    return this._initPromise;\n  }\n\n  async insert(\n    vectors: number[][],\n    ids: string[],\n    payloads: Record<string, any>[],\n  ): Promise<void> {\n    const { client } = await this.ready();\n\n    if (vectors.length !== ids.length || vectors.length !== payloads.length) {\n      throw new Error(\n        `Baidu insert requires vectors, ids, and payloads of equal length (got ${vectors.length}/${ids.length}/${payloads.length}).`,\n      );\n    }\n\n    const rows = vectors.map((vector, index) => ({\n      id: ids[index],\n      data: memoryData(payloads[index] || {}),\n      vector,\n      textLemmatized: lemmatizedText(payloads[index] || {}),\n      metadata: metadataPayload(payloads[index] || {}),\n    }));\n\n    check(await client.upsert({ ...this.ns, rows }), \"upsert\");\n  }\n\n  async search(\n    query: number[],\n    topK = 5,","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/baidu.ts#L394-L430","documentation":"The Baidu insert() requires the vectors, ids, and payloads arrays to have identical length because rows are built by zipping them index-by-index. A length mismatch means the caller's data is inconsistent (an id or payload missing for some vector), so it throws with all three lengths rather than producing corrupt rows. This is a precondition check at the store boundary.","triggerScenarios":"Calling insert() (or a bulk add path feeding it) with ids shorter than vectors; defaulting payloads to [] when it should be an array of empty objects; upstream code filtering one array but not the others.","commonSituations":"Custom orchestration code building the three arrays separately; batch generation that skips failed embeddings but keeps all ids; off-by-one bugs in slicing batches.","solutions":["Build the three arrays from a single source list so lengths cannot diverge.","When an embedding fails, remove the corresponding id and payload too (or abort the batch).","Add an assertion before the call: vectors.length === ids.length === payloads.length."],"exampleFix":"// before\nconst ids = all.map(m => m.id);\nconst vectors = embeddings.filter(Boolean); // silently drops failures\n// after\nconst ok = all.filter((_, i) => embeddings[i] != null);\nconst ids = ok.map(m => m.id);\nconst vectors = ok.map((_, i) => embeddings[i]);","handlingStrategy":"validation","validationCode":"function assertInsertArgs(vectors: unknown[][], ids: string[], payloads: Record<string, any>[]) {\n  if (vectors.length !== ids.length || vectors.length !== payloads.length)\n    throw new Error(`Length mismatch: ${vectors.length}/${ids.length}/${payloads.length}`);\n}","typeGuard":"const isAlignedInsert = (v: unknown[][], ids: string[], p: Record<string, any>[]): boolean =>\n  v.length === ids.length && v.length === p.length;","tryCatchPattern":"try { await store.insert(vectors, ids, payloads) } catch (e) { if (e instanceof Error && /requires vectors, ids, and payloads of equal length/.test(e.message)) { /* rebuild arrays from one source list and retry */ } throw e; }","preventionTips":["Derive ids, vectors, and payloads by mapping a single array of items so lengths stay in lockstep.","Never filter one array independently of the others after generation.","Add a length assertion in test coverage for batch-building code."],"tags":["baidu","input-validation","bulk-insert","array-mismatch"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}