{"record":{"id":"368ab5291721e6ec","repo":"mem0ai/mem0","slug":"ids-and-vectors-must-have-the-same-length","errorCode":null,"errorMessage":"ids and vectors must have the same length","messagePattern":"ids and vectors must have the same length","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/oracledb.ts","lineNumber":577,"sourceCode":"\n  private vectorBind(vector: number[]) {\n    return {\n      type: this.oracledb.DB_TYPE_VECTOR,\n      val: new Float32Array(vector),\n    };\n  }\n\n  private payloadBind(payload: Record<string, any>) {\n    return { type: this.oracledb.DB_TYPE_JSON, val: payload };\n  }\n\n  async insert(\n    vectors: number[][],\n    ids: string[],\n    payloads: Record<string, any>[],\n  ): Promise<void> {\n    if (ids.length !== vectors.length) {\n      throw new Error(\"ids and vectors must have the same length\");\n    }\n    if (payloads.length !== vectors.length) {\n      throw new Error(\"payloads and vectors must have the same length\");\n    }\n\n    if (vectors.length === 0) return;\n\n    await this.initialize();\n\n    await this.withConnection(async (connection) => {\n      await connection.executeMany(\n        `INSERT INTO ${this.collectionName} (id, vector, payload) VALUES (:id, :vector, :payload)`,\n        vectors.map((vector, i) => ({\n          id: ids[i],\n          vector: new Float32Array(vector),\n          payload: payloads[i] ?? {},\n        })) as BindParameters[],\n        {","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/oracledb.ts#L559-L595","documentation":"insert() performs an executeMany INSERT of (id, vector, payload) rows and requires the ids array to align one-to-one with the vectors array. A length mismatch means rows would reference undefined ids or vectors, so it fails fast before any SQL runs. Zero-length input is fine (early return).","triggerScenarios":"Direct calls to the vector store's insert(vectors, ids, payloads) where ids were deduplicated, filtered, or chunked independently of vectors; internal Memory.add() flows producing ids via uuid per vector where one array was built in a loop with an off-by-one.","commonSituations":"Custom ingestion scripts batching embeddings then mapping ids with .filter() or .slice() applied to only one array; retry logic that drops failed ids but keeps all vectors; passing ids.length = vectors.length - 1 due to a sparse index skip.","solutions":["Build ids and vectors from the same source loop so lengths match by construction: items.map(i => [i.id, embed(i.text)]).","Add an assert before insert: if (ids.length !== vectors.length) throw new RangeError(...) with context.","Re-derive arrays together after filtering: keep an array of {id, vector} tuples and unzip at the end.","Check for accidental .slice()/.splice() on one array during batching."],"exampleFix":"// before\nconst ids = items.map((i) => i.id).filter(Boolean); // one item had no id\nawait store.insert(vectors, ids, payloads);\n\n// after\nconst rows = items.filter((i) => i.id);\nawait store.insert(rows.map((r) => embed(r.text)), rows.map((r) => r.id), rows.map((r) => r.payload));","handlingStrategy":"validation","validationCode":"function assertInsertArity(ids: string[], vectors: number[][], payloads: Record<string, any>[]): void {\n  if (ids.length !== vectors.length) throw new RangeError(`ids(${ids.length}) != vectors(${vectors.length})`);\n  if (payloads.length !== vectors.length) throw new RangeError(`payloads(${payloads.length}) != vectors(${vectors.length})`);\n}","typeGuard":"type InsertRow = { id: string; vector: number[]; payload: Record<string, any> };\nconst isAlignedRows = (rows: InsertRow[]): boolean =>\n  rows.every((r) => typeof r.id === 'string' && Array.isArray(r.vector) && !!r.payload);","tryCatchPattern":"try { await store.insert(vectors, ids, payloads); } catch (e) { if (e instanceof Error && e.message.includes('same length')) { /* rebuild the three arrays from the same source rows and retry the batch */ } else throw e; }","preventionTips":["Carry {id, vector, payload} tuples through ingestion and unzip only at insert time.","Never filter/slice one array independently of the others.","Assert equal lengths in a wrapper before calling insert."],"tags":["oracle","insert","batching","validation","invariant"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}