{"record":{"id":"9e84e528941a8550","repo":"mem0ai/mem0","slug":"vector-at-index-index-is-null-or-undefined","errorCode":null,"errorMessage":"Vector at index ${index} is null or undefined.","messagePattern":"Vector at index (.+?) is null or undefined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/opensearch.ts","lineNumber":213,"sourceCode":"\n  private async ensureMigrationIndex(): Promise<void> {\n    if (await this.indexExists(\"memory_migrations\")) return;\n\n    await this.client.indices.create({\n      index: \"memory_migrations\",\n      body: {\n        mappings: {\n          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>[],","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/opensearch.ts#L195-L231","documentation":"OpenSearch insert validates each vector before bulking it into the index. A null/undefined entry in the vectors array (as opposed to an empty or wrong-length array) indicates the embedding step produced nothing for that record, which would produce a corrupt bulk item, so it fails fast with the offending index.","triggerScenarios":"Calling insert/add with a vectors array where one element is null or undefined — typically the embedding model returned null for one document, or a .map() overragged data produced a hole.","commonSituations":"Batch embedding where one input was empty or errored and the error was swallowed; async mapping that pushes undefined; API responses deserialized with missing fields.","solutions":["Inspect the reported index in the vectors array and fix or remove that entry before insert.","Filter out nullish embeddings before calling insert: vectors.map(...).filter(v => Array.isArray(v) && v.length > 0).","Make the embedding step fail loudly instead of returning null on bad input."],"exampleFix":"// before\nawait store.insert([emb0, null, emb2], ids, payloads);\n\n// after\nconst rows = embeddings.map((v, i) => ({ v, i })).filter(r => Array.isArray(r.v));\nawait store.insert(rows.map(r => r.v), rows.map(r => ids[r.i]), rows.map(r => payloads[r.i]));","handlingStrategy":"validation","validationCode":"const bad = vectors.findIndex((v) => v == null);\nif (bad !== -1) throw new Error(`Embedding at position ${bad} is missing`);","typeGuard":"const isDenseVector = (v: unknown): v is number[] => Array.isArray(v) && v.length > 0 && v.every((n) => typeof n === 'number');","tryCatchPattern":null,"preventionTips":["Make embedding failures throw instead of returning null","Filter nullish embeddings before insert","Validate embedding provider responses in one place"],"tags":["opensearch","embeddings","validation","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}