mem0ai/mem0 · error · Error

The '@zilliz/milvus2-sdk-node' package is required to use th

Error message

The '@zilliz/milvus2-sdk-node' package is required to use the Milvus vector store. Install it with: npm install @zilliz/milvus2-sdk-node

What it means

When the Milvus provider is not given a pre-built client, it lazily require()s @zilliz/milvus2-sdk-node at construction time. The SDK is an optional peer dependency (not installed with mem0ai), so if Node cannot resolve it the provider throws with install instructions rather than crashing later with an opaque undefined-client error.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/milvus.ts:90

        const sdk = require("@zilliz/milvus2-sdk-node");
        this.DataType = sdk.DataType;
        this.FunctionType = sdk.FunctionType;
      } catch (_) {
        this.DataType = undefined;
        this.FunctionType = undefined;
      }
    } else {
      let MilvusClient: any;
      let DataType: any;
      let FunctionType: any;
      try {
        // eslint-disable-next-line @typescript-eslint/no-var-requires
        const sdk = require("@zilliz/milvus2-sdk-node");
        MilvusClient = sdk.MilvusClient;
        DataType = sdk.DataType;
        FunctionType = sdk.FunctionType;
      } catch (_) {
        throw new Error(
          "The '@zilliz/milvus2-sdk-node' package is required to use the Milvus vector store. " +
            "Install it with: npm install @zilliz/milvus2-sdk-node",
        );
      }
      this.DataType = DataType;
      this.FunctionType = FunctionType;
      this.client = new MilvusClient({
        address: config.url || "http://localhost:19530",
        token: config.token,
        database: config.dbName || undefined,
      });
    }

    this.initialize().catch((err) =>
      console.error("Error initializing Milvus:", err),
    );
  }

View on GitHub (pinned to 001c235229)

Solutions

  1. Install the SDK in the project that runs mem0: npm install @zilliz/milvus2-sdk-node (or pnpm add).
  2. If installed but still failing under a bundler, mark it external (tsup: { external: ['@zilliz/milvus2-sdk-node'] }) or switch the build output to CJS.
  3. Verify resolution with node -e "require('@zilliz/milvus2-sdk-node')" in the same working directory/package manager context.
  4. Alternatively construct a MilvusClient yourself and pass it via config.client to bypass the lazy require.

Example fix

// before
new Memory({ vectorStore: { provider: 'milvus', config: { url: 'http://localhost:19530' } } }); // throws

// after
// package.json: dependencies { "@zilliz/milvus2-sdk-node": "^2.x" }
// then same config works
Defensive patterns

Strategy: validation

Validate before calling

function milvusSdkAvailable(): boolean {
  try { require.resolve('@zilliz/milvus2-sdk-node'); return true; } catch { return false; }
}
if (!milvusSdkAvailable()) throw new Error('Run: npm install @zilliz/milvus2-sdk-node');

Try / catch

try {
  memory = new Memory({ vectorStore: { provider: 'milvus', config } });
} catch (e) {
  if (e instanceof Error && e.message.includes('@zilliz/milvus2-sdk-node')) {
    // surface install instructions to the operator; fail startup cleanly
  } else throw e;
}

Prevention

When it happens

Trigger: Configuring vectorStore.provider = 'milvus' without having run npm/pnpm install @zilliz/milvus2-sdk-node; using a bundler (tsup/webpack) or ESM context where require() of the SDK fails even though it is installed; monorepo hoisting issues where the package is absent from the consuming workspace's node_modules.

Common situations: Fresh clone + minimal install; adding mem0ai to a serverless bundle that tree-shook the dynamic require; pnpm strict node_modules hiding an indirectly-installed SDK.

Related errors


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