{"record":{"id":"a85ad81e60c59fd1","repo":"mem0ai/mem0","slug":"vector-dimension-mismatch-expected-this-dimensi-a85ad8","errorCode":null,"errorMessage":"Vector dimension mismatch. Expected ${this.dimension}, got ${vector.length}","messagePattern":"Vector dimension mismatch\\. Expected (.+?), got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/memory.ts","lineNumber":412,"sourceCode":"    const row = this.db\n      .prepare(`SELECT * FROM vectors WHERE id = ?`)\n      .get(vectorId) as any;\n    if (!row) return null;\n\n    const payload = this.normalizePayload(JSON.parse(row.payload));\n    return {\n      id: row.id,\n      payload,\n    };\n  }\n\n  async update(\n    vectorId: string,\n    vector: number[],\n    payload: Record<string, any>,\n  ): Promise<void> {\n    if (vector.length !== this.dimension) {\n      throw new Error(\n        `Vector dimension mismatch. Expected ${this.dimension}, got ${vector.length}`,\n      );\n    }\n    const vectorBuffer = Buffer.from(new Float32Array(vector).buffer);\n    this.db\n      .prepare(`UPDATE vectors SET vector = ?, payload = ? WHERE id = ?`)\n      .run(vectorBuffer, JSON.stringify(payload), vectorId);\n  }\n\n  async delete(vectorId: string): Promise<void> {\n    this.db.prepare(`DELETE FROM vectors WHERE id = ?`).run(vectorId);\n  }\n\n  async deleteCol(): Promise<void> {\n    this.db.exec(`DROP TABLE IF EXISTS vectors`);\n    this.init();\n  }\n","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/memory.ts#L394-L430","documentation":"update() rewrites a row's vector blob and payload, and first checks that the new vector's length equals the store's fixed dimension. Since every stored vector must remain comparable, an update with a differently-sized vector (typically from a changed embedding model) is rejected before the UPDATE statement runs.","triggerScenarios":"Calling update(vectorId, newVector, payload) where newVector comes from a different embedding model than the collection's dimension; memory-update flows (memory.update()) after the embedder config changed; passing a truncated or padded vector.","commonSituations":"Migrating embedding providers mid-life of a SQLite memory DB and updating old memories with new-model vectors; tests with synthetic vectors of arbitrary length.","solutions":["Embed the updated text with the same model used at collection creation, then call update().","If migrating embedders, delete and re-add the memory (fresh vector + new id) instead of update().","Recreate the store with the new dimension if all data will be re-embedded."],"exampleFix":"// before\nawait store.update(memoryId, wrongDimVector, payload); // throws\n\n// after\nconst vec = await sameModelAsInsert.embed newText;\nawait store.update(memoryId, vec, payload);","handlingStrategy":"validation","validationCode":"if (vector.length !== store.dimension) {\n  throw new Error(`update(): vector is ${vector.length}-dim, store expects ${store.dimension}`);\n}","typeGuard":"const isValidUpdateVector = (v: unknown, dim: number): v is number[] => Array.isArray(v) && v.length === dim && v.every((n) => typeof n === 'number');","tryCatchPattern":"try { await store.update(id, vector, payload); }\ncatch (e) {\n  if (e instanceof Error && e.message.startsWith('Vector dimension mismatch')) {\n    // re-embed the new text with the original model, or delete+re-add the memory\n  } else throw e;\n}","preventionTips":["Update with vectors from the same embedder that created the collection.","On embedder migration, delete + re-add memories instead of updating in place.","Recreate the store with the new dimension before re-embedding everything."],"tags":["dimension-mismatch","embeddings","sqlite","vector-store","update"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}