{"record":{"id":"c0da84ff33faa537","repo":"mem0ai/mem0","slug":"label-dimension-mismatch-expected-this-dimen-c0da84","errorCode":null,"errorMessage":"${label} dimension mismatch. Expected ${this.dimension}, got ${vector.length}","messagePattern":"(.+?) dimension mismatch\\. Expected (.+?), got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/databricks.ts","lineNumber":1456,"sourceCode":"\n    return {};\n  }\n\n  private extractSessionValues(payload: Record<string, any>): {\n    user_id: any;\n    agent_id: any;\n    run_id: any;\n  } {\n    return {\n      user_id: payload.user_id,\n      agent_id: payload.agent_id,\n      run_id: payload.run_id,\n    };\n  }\n\n  private assertVectorDimension(vector: number[], label: string): void {\n    if (vector.length !== this.dimension) {\n      throw new Error(\n        `${label} dimension mismatch. Expected ${this.dimension}, got ${vector.length}`,\n      );\n    }\n    for (const value of vector) {\n      if (!Number.isFinite(value)) {\n        throw new Error(\n          `${label} values must be finite numbers for Databricks vector search.`,\n        );\n      }\n    }\n  }\n\n  private matchFieldCondition(\n    vector: DatabricksVector,\n    key: string,\n    value: any,\n  ): boolean {\n    const fieldValue = key === \"memory_id\" ? vector.id : vector.payload[key];","sourceCodeStart":1438,"sourceCodeEnd":1474,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/databricks.ts#L1438-L1474","documentation":"assertVectorDimension() throws when a vector passed for insert/update does not match this.dimension, the configured embedding dimension. Databricks Vector Search indexes have a fixed embedding column width; a mismatched vector would be rejected server-side, so the provider validates client-side first with a clearer message.","triggerScenarios":"Calling insert() or update() with vectors produced by a different embedding model than the one whose dimension the store was configured with (e.g. 1536-dim OpenAI vectors sent to a 768-dim index), or mixing embedding providers between memory add and store config.","commonSituations":"Switching the embedding provider (e.g. from OpenAI text-embedding-3-small to a local 384-dim model) without recreating the Databricks index; sharing one store across two memory instances with different embedders; a custom embedding function returning padded/truncated vectors.","solutions":["Make the embedding model used by Memory match the dimension the Databricks index was created with, and pass that same dimension in the store config.","If you intentionally changed embedding models, create a new Databricks Vector Search index with the new dimension and point config at it.","Log vector.length at the call site to identify which embedder produced the mismatched vector.","Verify config.dimension matches the index's embedding column length in Databricks."],"exampleFix":"// before\nconst store = new DatabricksDB({ ...opts, dimension: 1536 });\nconst memory = new Memory({ vectorStore: store, embedder: new OllamaEmbedder() }); // 768-dim\n\n// after\nconst memory = new Memory({\n  vectorStore: new DatabricksDB({ ...opts, dimension: 768 }), // matches embedder\n  embedder: new OllamaEmbedder(),\n});","handlingStrategy":"validation","validationCode":"const dim = await embedder.embed('probe');\nif (dim.embedding.length !== storeConfig.dimension) {\n  throw new Error(`Embedder emits ${dim.embedding.length}-d vectors but store configured for ${storeConfig.dimension}`);\n}","typeGuard":"const isDimensionOk = (v: number[], expected: number) =>\n  Array.isArray(v) && v.length === expected;","tryCatchPattern":"try {\n  await store.insert(vectors, ids, payloads);\n} catch (e) {\n  if (e instanceof Error && /dimension mismatch/i.test(e.message)) {\n    // align embedder and index dimension, recreate index if the model changed\n  }\n  throw e;\n}","preventionTips":["Derive config.dimension from a probe embedding at startup instead of hardcoding it.","Use a single embedding model across memory add/search/store paths.","Recreate the Databricks index when switching embedding models."],"tags":["databricks","dimension-mismatch","embeddings","validation","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}