Skip to content
MilvusNode SDK
Sections

Deploy Applications with the Milvus SDK

Markdown

Copy for agent

Use MilvusClient on Node.js servers with gRPC support. Choose HttpClient for HTTP-only environments such as Cloudflare Workers and Vercel Edge, or when a proxy requires REST.

Decision MilvusClient (gRPC) HttpClient (REST)
Protocol gRPC over HTTP/2 Milvus REST v2 over HTTP with JSON
Request field casing snake_case, such as collection_name camelCase, such as collectionName
Serverless and edge support Use in Node.js runtimes that support gRPC connections Use in Fetch-capable runtimes, including HTTP-only serverless and edge environments
Streaming and gRPC-only admin RPCs Supports replication and WAL streams, plus proxy and telemetry administration Supports REST management operations and returns JSON responses
Response and error handling Inspect error_code on a status or status.error_code on a result. Transport failures can reject. Inspect code where the REST response provides it. Non-2xx responses throw HttpError.

Set the REST client’s endpoint to your cluster origin. The SDK appends /v2. For a custom baseURL, include the full versioned URL ending in /v2.

Deploy to Vercel serverless functions with minimal configuration.

Quick Start:

api/search.js
import { HttpClient } from '@zilliz/milvus2-sdk-node';
let client;
function getClient() {
if (!client) {
client = new HttpClient({
endpoint: process.env.MILVUS_ENDPOINT,
token: process.env.MILVUS_TOKEN,
timeout: 10000,
});
}
return client;
}
export default async function handler(req, res) {
const milvusClient = getClient();
const results = await milvusClient.search({
collectionName: 'my_collection',
data: req.body.vectors,
limit: 10,
outputFields: [],
});
res.status(200).json({ results });
}

Learn more: Vercel Deployment Guide

Deploy to Cloudflare Workers for edge computing.

Quick Start:

worker.js
import { HttpClient } from '@zilliz/milvus2-sdk-node/dist/milvus/HttpClient.js';
export default {
async fetch(request, env) {
const { vector } = await request.json();
const client = new HttpClient({
endpoint: env.MILVUS_ENDPOINT,
token: env.MILVUS_TOKEN,
timeout: 25000,
});
const results = await client.search({
collectionName: 'my_collection',
data: [vector],
limit: 10,
outputFields: [],
});
return new Response(JSON.stringify({ results }), {
headers: { 'Content-Type': 'application/json' },
});
},
};

Learn more: Cloudflare Workers Deployment Guide

Deploy to AWS Lambda for scalable serverless functions.

Quick Start:

index.js
import { HttpClient } from '@zilliz/milvus2-sdk-node';
let client;
function getClient() {
if (!client) {
client = new HttpClient({
endpoint: process.env.MILVUS_ENDPOINT,
token: process.env.MILVUS_TOKEN,
timeout: 25000,
});
}
return client;
}
export const handler = async (event) => {
const milvusClient = getClient();
const results = await milvusClient.search({
collectionName: 'my_collection',
data: JSON.parse(event.body).vectors,
limit: 10,
outputFields: [],
});
return {
statusCode: 200,
body: JSON.stringify({ results }),
};
};

Learn more: AWS Lambda Deployment Guide

For traditional Node.js servers, you can use either client:

// Using gRPC Client (Recommended)
import { MilvusClient } from '@zilliz/milvus2-sdk-node';
const client = new MilvusClient({
address: 'localhost:19530',
token: 'your-token',
});
await client.connectPromise;
// Using HTTP Client
import { HttpClient } from '@zilliz/milvus2-sdk-node';
const client = new HttpClient({
endpoint: 'http://localhost:19530',
token: 'your-token',
});

Deploy in Docker containers:

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]

Always use environment variables for sensitive configuration:

.env
MILVUS_ENDPOINT=https://your-instance.zillizcloud.com
MILVUS_TOKEN=your-api-token
const client = new HttpClient({
endpoint: process.env.MILVUS_ENDPOINT,
token: process.env.MILVUS_TOKEN,
});
Platform Client Type Timeout Limit Best For
Vercel HTTP 10s (Hobby), 60s (Pro) Next.js apps, static sites
Cloudflare Workers HTTP 30s (free), 15min (paid) Edge computing, global distribution
AWS Lambda HTTP Up to 15 minutes Enterprise serverless
Traditional Server gRPC or HTTP No limit Long-lived applications

Reuse client instances to improve performance:

let client;
function getClient() {
if (!client) {
client = new HttpClient({
endpoint: process.env.MILVUS_ENDPOINT,
token: process.env.MILVUS_TOKEN,
});
}
return client;
}

Reuse the HTTP client from the previous example. Inspect the Milvus response code and catch errors from the HTTP request:

async function searchCollection(queryVector) {
try {
const results = await getClient().search({
collectionName: 'my_collection',
data: [queryVector],
limit: 10,
outputFields: [],
});
if (results.code !== 0) {
return { success: false, error: results.message, status: 502 };
}
return { success: true, results };
} catch (error) {
console.error('Milvus error:', error);
return {
success: false,
error: error.message,
status: error.status || 500,
};
}
}

Set timeouts based on platform limits:

const client = new HttpClient({
endpoint: process.env.MILVUS_ENDPOINT,
token: process.env.MILVUS_TOKEN,
timeout: 10000, // Adjust based on platform
});