mem0ai/mem0 · error · Error

Baidu Mochow ${action} failed (code ${response.code}): ${res

Error message

Baidu Mochow ${action} failed (code ${response.code}): ${response.msg}

What it means

The Baidu Mochow SDK resolves calls with a {code, msg} envelope instead of rejecting, so mem0 wraps every operation in check(), which throws this error when code !== 0 and the code is not in the caller's tolerated list (idempotent outcomes like 'database already exists' are tolerated). The message includes the action name (e.g. createDatabase, dropTable), the numeric code, and Mochow's msg.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/baidu.ts:69

function escapeFilterString(value: string): string {
  return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
}

function sleep(ms: number): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

// Mochow resolves with a {code, msg} envelope instead of rejecting, so every call site
// has to inspect the code. `tolerated` lets callers accept the idempotent outcomes
// (database/table already exists, table already dropped).
function check(
  response: CommonResponse,
  action: string,
  ...tolerated: number[]
): number {
  if (response.code !== 0 && !tolerated.includes(response.code)) {
    throw new Error(
      `Baidu Mochow ${action} failed (code ${response.code}): ${response.msg}`,
    );
  }
  return response.code;
}

function lemmatizedText(payload: Record<string, any>): string {
  const data = typeof payload.data === "string" ? payload.data : "";
  return typeof payload.textLemmatized === "string" &&
    payload.textLemmatized.length > 0
    ? payload.textLemmatized
    : data;
}

function memoryData(payload: Record<string, any>): string {
  return typeof payload.data === "string" ? payload.data : "";
}

View on GitHub (pinned to 001c235229)

Solutions

  1. Decode the code/msg pair against Baidu Mochow docs: permission issues mean fix account/API key; 'already exists' variants are usually tolerated automatically, other codes are real failures.
  2. Verify endpoint/account/apiKey in the vector store config are for the same Baidu project and region.
  3. Retry initialization after transient codes; if racing instances created the database concurrently, restart one after the other is settled.
Defensive patterns

Strategy: try-catch

Try / catch

try { await memory.add(text) }
catch (e) {
  if (e instanceof Error && /Baidu Mochow .* failed \(code \d+\)/.test(e.message)) {
    const code = Number(/code (\d+)/.exec(e.message)?.[1]);
    if (isTransientMochowCode(code)) await backoffRetry(() => memory.add(text), 3);
    else throw new Error(`Baidu setup/permission failure: ${e.message}`);
  } else throw e;
}

Prevention

When it happens

Trigger: createTable failing because the account has no permission on the database; a network/SDK error code returned by Mochow; dropping a table that is in a transitioning state; any Mochow RPC whose code is non-zero and not idempotent-tolerated.

Common situations: Wrong Baidu account/apiKey; quota or region limits; running two Memory instances concurrently so createDatabase races past tolerated codes; SDK version returning new error codes.

Related errors


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