mem0ai/mem0 · error · Error

Vector at index ${index} is null or undefined.

Error message

Vector at index ${index} is null or undefined.

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/opensearch.ts:213

  private async ensureMigrationIndex(): Promise<void> {
    if (await this.indexExists("memory_migrations")) return;

    await this.client.indices.create({
      index: "memory_migrations",
      body: {
        mappings: {
          properties: {
            user_id: { type: "keyword" },
          },
        },
      },
    });
  }

  private validateVector(vector: number[], index: number): void {
    if (!vector) {
      throw new Error(`Vector at index ${index} is null or undefined.`);
    }
    if (vector.length === 0) {
      throw new Error(
        `Vector at index ${index} is empty. Expected dimension ${this.embeddingModelDims}.`,
      );
    }
    if (vector.length !== this.embeddingModelDims) {
      throw new Error(
        `Vector at index ${index} has dimension ${vector.length}, but index ` +
          `'${this.collectionName}' expects dimension ${this.embeddingModelDims}.`,
      );
    }
  }

  async insert(
    vectors: number[][],
    ids: string[],
    payloads: Record<string, any>[],

View on GitHub (pinned to 001c235229)

Solutions

  1. Inspect the reported index in the vectors array and fix or remove that entry before insert.
  2. Filter out nullish embeddings before calling insert: vectors.map(...).filter(v => Array.isArray(v) && v.length > 0).
  3. Make the embedding step fail loudly instead of returning null on bad input.

Example fix

// before
await store.insert([emb0, null, emb2], ids, payloads);

// after
const rows = embeddings.map((v, i) => ({ v, i })).filter(r => Array.isArray(r.v));
await store.insert(rows.map(r => r.v), rows.map(r => ids[r.i]), rows.map(r => payloads[r.i]));
Defensive patterns

Strategy: validation

Validate before calling

const bad = vectors.findIndex((v) => v == null);
if (bad !== -1) throw new Error(`Embedding at position ${bad} is missing`);

Type guard

const isDenseVector = (v: unknown): v is number[] => Array.isArray(v) && v.length > 0 && v.every((n) => typeof n === 'number');

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/9e84e528941a8550. Report an issue: GitHub.