{"record":{"id":"d5aa40cfdd1e62d5","repo":"mem0ai/mem0","slug":"context-dimension-mismatch-expected-this-dim","errorCode":null,"errorMessage":"${context} dimension mismatch. Expected ${this.dimension}, got ${vector.length}","messagePattern":"(.+?) dimension mismatch\\. Expected (.+?), got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/vector_stores/neptune_analytics.ts","lineNumber":949,"sourceCode":"        .join(\", \")} }`;\n    }\n\n    throw new Error(\n      `Unsupported Neptune Analytics algorithm value type: ${typeof value}`,\n    );\n  }\n\n  private serializeAlgorithmKey(key: string): string {\n    if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {\n      return key;\n    }\n\n    return JSON.stringify(key);\n  }\n\n  private assertVectorDimension(vector: number[], context: string): void {\n    if (vector.length !== this.dimension) {\n      throw new Error(\n        `${context} dimension mismatch. Expected ${this.dimension}, got ${vector.length}`,\n      );\n    }\n  }\n\n  private assertBatchDimensions(vectors: number[][], context: string): void {\n    for (const vector of vectors) {\n      this.assertVectorDimension(vector, context);\n    }\n  }\n\n  private normalizeNodeResult(record: NeptuneQueryRecord): VectorStoreResult {\n    const node = this.extractNode(record);\n    const payload = this.normalizePayload(this.extractPayload(node));\n\n    return {\n      id: this.extractId(node, record),\n      payload,","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/neptune_analytics.ts#L931-L967","documentation":"The Neptune Analytics store validates every vector's length against the configured dimension (set at construction from the embedding config) before writing or querying. Neptune vectors are fixed-dimension; a mismatch would produce a hard AWS-side failure, so the client fails fast with the expected/got lengths.","triggerScenarios":"Calling add/insert/update with vectors from an embedding model whose dimension differs from the store's configured dimension (e.g. 384-dim MiniLM vectors into a 1536-dim store), or searching with a query embedded by a different model.","commonSituations":"Switching embedding providers (OpenAI ada-002 1536 -> text-embedding-3-small also 1536 vs 3-large 3072, or to a local model) without recreating the Neptune vector index; mixing models between write and search paths; stale config after model upgrade.","solutions":["Use the same embedding model (and thus dimension) for writes and searches, and set that dimension in the vector store config.","If you changed embedding models, create a new Neptune graph/index sized for the new dimension and re-embed existing memories.","Verify with vector.length before insert when ingesting pre-computed embeddings."],"exampleFix":"// before\nconst store = new NeptuneAnalytics({ dimension: 1536 });\nawait store.insert([vec386dims], ...); // 384-dim model output\n\n// after\nconst store = new NeptuneAnalytics({ dimension: 384 });\nawait store.insert([vec384dims], ...);","handlingStrategy":"validation","validationCode":"if (vector.length !== store.dimension) {\n  throw new Error(`Embedding dim ${vector.length} != store dim ${store.dimension}`);\n}","typeGuard":"const hasDim = (v: number[], d: number): v is number[] & { length: d } => v.length === d;","tryCatchPattern":"catch (e) { if (e.message.includes('dimension mismatch')) { /* reconfigure store dimension or re-embed */ } }","preventionTips":["Pin one embedding model per Neptune graph","Set the store dimension from the embedding config, never hardcode","Re-embed memories after any model change"],"tags":["neptune-analytics","embeddings","dimension-mismatch","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}