{"record":{"id":"d056b8f60b100947","repo":"mem0ai/mem0","slug":"vector-at-index-index-has-dimension-vector-le","errorCode":null,"errorMessage":"Vector at index ${index} has dimension ${vector.length}, but index '${this.collectionName}' expects dimension ${this.embeddingModelDims}.","messagePattern":"Vector at index (.+?) has dimension (.+?), but index '(.+?)' expects dimension (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/vector_stores/opensearch.ts","lineNumber":221,"sourceCode":"          properties: {\n            user_id: { type: \"keyword\" },\n          },\n        },\n      },\n    });\n  }\n\n  private validateVector(vector: number[], index: number): void {\n    if (!vector) {\n      throw new Error(`Vector at index ${index} is null or undefined.`);\n    }\n    if (vector.length === 0) {\n      throw new Error(\n        `Vector at index ${index} is empty. Expected dimension ${this.embeddingModelDims}.`,\n      );\n    }\n    if (vector.length !== this.embeddingModelDims) {\n      throw new Error(\n        `Vector at index ${index} has dimension ${vector.length}, but index ` +\n          `'${this.collectionName}' expects dimension ${this.embeddingModelDims}.`,\n      );\n    }\n  }\n\n  async insert(\n    vectors: number[][],\n    ids: string[],\n    payloads: Record<string, any>[],\n  ): Promise<void> {\n    await this.initialize();\n    vectors.forEach((vector, index) => this.validateVector(vector, index));\n\n    const operations = vectors.flatMap((vector, index) => {\n      const id = ids[index] || String(index);\n      return [\n        { index: { _index: this.collectionName, _id: id } },","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/opensearch.ts#L203-L239","documentation":"The OpenSearch index was created with a dense_vector field of fixed dimension this.embeddingModelDims. Inserting a vector whose length differs would fail OpenSearch's mapping check with an opaque server error, so the store pre-validates every vector and reports the vector's length, the collection name, and the expected dimension.","triggerScenarios":"Embedding with a model of a different dimension than configured (e.g. 3072-dim text-embedding-3-large vectors into an index built for 1536); mixing embedding providers between write and read; manually constructed vectors of wrong size.","commonSituations":"Changing the embedding model without recreating the OpenSearch index; per-tenant models with different dims sharing one index; local dev using a small test model against a prod-configured index.","solutions":["Align the embedding model dimension with embeddingModelDims in the store config, then recreate the index.","If the model changed, delete and recreate the OpenSearch index with the new dimension and re-index memories.","Guarantee a single embedding model per index; route different dims to different collections."],"exampleFix":"// before\n// index created with embeddingModelDims: 1536\nconst vec = await embed('text', 'text-embedding-3-large'); // 3072\nawait store.insert([vec], ids, payloads);\n\n// after\nconst store = new OpenSearch({ embeddingModelDims: 3072 }); // recreate index\nawait store.insert([vec], ids, payloads);","handlingStrategy":"validation","validationCode":"const expected = storeConfig.embeddingModelDims;\nif (vectors.some((v) => v.length !== expected)) {\n  throw new Error(`Vector dims do not match configured ${expected}`);\n}","typeGuard":"const matchesDims = (v: number[], dims: number): boolean => Array.isArray(v) && v.length === dims;","tryCatchPattern":"catch (e) { if (e.message.includes('expects dimension')) { /* rebuild index with new dims and re-embed */ } }","preventionTips":["One embedding model per OpenSearch index","Recreate the index when the model changes","Set embeddingModelDims from the live model config"],"tags":["opensearch","dimension-mismatch","embeddings","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}