{"record":{"id":"c5c165c1c6863cdb","repo":"mem0ai/mem0","slug":"the-zilliz-milvus2-sdk-node-package-is-required","errorCode":null,"errorMessage":"The '@zilliz/milvus2-sdk-node' package is required to use the Milvus vector store. Install it with: npm install @zilliz/milvus2-sdk-node","messagePattern":"The '@zilliz/milvus2-sdk-node' package is required to use the Milvus vector store\\. Install it with: npm install @zilliz/milvus2-sdk-node","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/milvus.ts","lineNumber":90,"sourceCode":"        const sdk = require(\"@zilliz/milvus2-sdk-node\");\n        this.DataType = sdk.DataType;\n        this.FunctionType = sdk.FunctionType;\n      } catch (_) {\n        this.DataType = undefined;\n        this.FunctionType = undefined;\n      }\n    } else {\n      let MilvusClient: any;\n      let DataType: any;\n      let FunctionType: any;\n      try {\n        // eslint-disable-next-line @typescript-eslint/no-var-requires\n        const sdk = require(\"@zilliz/milvus2-sdk-node\");\n        MilvusClient = sdk.MilvusClient;\n        DataType = sdk.DataType;\n        FunctionType = sdk.FunctionType;\n      } catch (_) {\n        throw new Error(\n          \"The '@zilliz/milvus2-sdk-node' package is required to use the Milvus vector store. \" +\n            \"Install it with: npm install @zilliz/milvus2-sdk-node\",\n        );\n      }\n      this.DataType = DataType;\n      this.FunctionType = FunctionType;\n      this.client = new MilvusClient({\n        address: config.url || \"http://localhost:19530\",\n        token: config.token,\n        database: config.dbName || undefined,\n      });\n    }\n\n    this.initialize().catch((err) =>\n      console.error(\"Error initializing Milvus:\", err),\n    );\n  }\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/milvus.ts#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the SDK in the project that runs mem0: npm install @zilliz/milvus2-sdk-node (or pnpm add).","If installed but still failing under a bundler, mark it external (tsup: { external: ['@zilliz/milvus2-sdk-node'] }) or switch the build output to CJS.","Verify resolution with node -e \"require('@zilliz/milvus2-sdk-node')\" in the same working directory/package manager context.","Alternatively construct a MilvusClient yourself and pass it via config.client to bypass the lazy require."],"exampleFix":"// before\nnew Memory({ vectorStore: { provider: 'milvus', config: { url: 'http://localhost:19530' } } }); // throws\n\n// after\n// package.json: dependencies { \"@zilliz/milvus2-sdk-node\": \"^2.x\" }\n// then same config works","handlingStrategy":"validation","validationCode":"function milvusSdkAvailable(): boolean {\n  try { require.resolve('@zilliz/milvus2-sdk-node'); return true; } catch { return false; }\n}\nif (!milvusSdkAvailable()) throw new Error('Run: npm install @zilliz/milvus2-sdk-node');","typeGuard":null,"tryCatchPattern":"try {\n  memory = new Memory({ vectorStore: { provider: 'milvus', config } });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('@zilliz/milvus2-sdk-node')) {\n    // surface install instructions to the operator; fail startup cleanly\n  } else throw e;\n}","preventionTips":["Declare @zilliz/milvus2-sdk-node in dependencies of the app using provider 'milvus'.","For bundlers, mark the SDK external so the runtime require resolves in node_modules.","Smoke-test require.resolve() during boot in environments that prune dev deps."],"tags":["milvus","dependency","installation","optional-peer","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}