mem0ai/mem0 · error · Error

OpenSearch bulk insert failed: ${JSON.stringify(failedItem)}

Error message

OpenSearch bulk insert failed: ${JSON.stringify(failedItem)}

What it means

OpenSearch bulk insert returns per-item results; when response.errors is true the store finds the first item whose action (index/create/update/delete) carries an error object and throws it as JSON. This surfaces the server-side reason — mapping conflict, dimension mismatch at the server, parser failures, or index closed — instead of pretending the batch succeeded.

Source

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

      ];
    });

    if (operations.length === 0) return;

    const response = responseBody<{ errors?: boolean; items?: any[] }>(
      await this.client.bulk({
        refresh: this.autoRefresh,
        body: operations,
      }),
    );

    if (response.errors) {
      const failedItem = response.items?.find((item) => {
        const action = item.index || item.create || item.update || item.delete;
        return action?.error;
      });

      throw new Error(
        `OpenSearch bulk insert failed: ${JSON.stringify(failedItem)}`,
      );
    }
  }

  async keywordSearch(
    query: string,
    topK: number = 5,
    filters?: SearchFilters,
  ): Promise<VectorStoreResult[] | null> {
    await this.initialize();
    const boolQuery: Record<string, any> = {
      should: [
        { match: { "payload.data": query } },
        { match: { "payload.text_lemmatized": query } },
        { match: { "payload.textLemmatized": query } },
      ],
      minimum_should_match: 1,

View on GitHub (pinned to 001c235229)

Solutions

  1. Read the error field inside the reported item JSON (e.g. mapper_parsing_exception, illegal_argument_exception) — it names the real cause.
  2. If the index is readonly (disk watermark): free disk space or adjust cluster.routing.allocation.disk.watermark settings, then retry.
  3. If it is a vector dimension/mapping issue, recreate the index with the correct dimension and re-embed.
  4. Retry only failed items rather than the whole batch to avoid duplicate work.
Defensive patterns

Strategy: retry

Try / catch

try {
  await store.insert(vectors, ids, payloads);
} catch (e) {
  if (e instanceof Error && e.message.startsWith('OpenSearch bulk insert failed:')) {
    const item = JSON.parse(e.message.slice('OpenSearch bulk insert failed: '.length));
    const err = item?.index?.error ?? item?.create?.error;
    if (err?.type === 'cluster_block_exception') { /* free disk / clear readonly, then retry */ }
    else throw e;
  } else throw e;
}

Prevention

When it happens

Trigger: A bulk insert where at least one document fails server-side: dense_vector of wrong dimension at the mapping level, malformed JSON payload fields, index readonly (disk watermark exceeded), or mapper_parsing_exception.

Common situations: Disk-full or watermark-triggered readonly index in self-hosted OpenSearch; mixed payload shapes in one batch; version upgrade of OpenSearch changing mapping strictness; partial failures hidden because only the first failed item is reported.

Related errors


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