Milvus
High-performance, cloud-native vector database for AI applications
Alternative To
- • Pinecone
- • Weaviate Cloud
- • Qdrant
- • Chroma
Difficulty Level
Requires some technical experience. Moderate setup complexity.
Overview
Milvus is a high-performance, cloud-native vector database designed for AI applications and similarity search at scale. Built by experts from the high-performance computing community, Milvus excels at storing, indexing, and querying massive vector datasets efficiently. With its distributed architecture, it can handle billions of vectors while maintaining fast query speeds, making it ideal for retrieval augmented generation (RAG), recommendation systems, image search, and other AI applications that rely on vector embeddings.
System Requirements
- CPU: 4+ cores (8+ recommended for production)
- RAM: 8GB+ (16GB+ recommended for large collections)
- GPU: Optional, supports GPU acceleration for indexing
- Storage: 10GB+ (SSD or NVMe recommended)
- Operating System: Linux, macOS, Windows, or Docker-compatible platforms
Installation Guide
Prerequisites
- Basic knowledge of command line interfaces
- Git installed on your system
- Docker and Docker Compose (recommended for easy setup)
- Python 3.7+ for the Python SDK
- Understanding of vector embeddings and similarity search concepts
Option 1: Docker Installation (Recommended)
Create a docker-compose.yml file:
version: "3.5" services: etcd: container_name: milvus-etcd image: quay.io/coreos/etcd:v3.5.5 environment: - ETCD_AUTO_COMPACTION_MODE=revision - ETCD_AUTO_COMPACTION_RETENTION=1000 - ETCD_QUOTA_BACKEND_BYTES=4294967296 volumes: - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd minio: container_name: milvus-minio image: minio/minio:RELEASE.2023-03-20T20-16-18Z environment: MINIO_ACCESS_KEY: minioadmin MINIO_SECRET_KEY: minioadmin volumes: - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data command: minio server /minio_data healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 standalone: container_name: milvus-standalone image: milvusdb/milvus:v2.3.3 command: ["milvus", "run", "standalone"] environment: ETCD_ENDPOINTS: etcd:2379 MINIO_ADDRESS: minio:9000 volumes: - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus ports: - "19530:19530" - "9091:9091" depends_on: - "etcd" - "minio" networks: default: name: milvusStart the Docker containers:
docker-compose up -dVerify the installation:
docker psMilvus will be available at:
- API:
localhost:19530 - Monitoring:
localhost:9091
- API:
Option 2: Using Milvus Lite (Python)
Milvus Lite is a lightweight, standalone version that’s great for quick experimentation:
Install the pymilvus package:
pip install pymilvusCreate a simple Python script to use Milvus Lite:
from pymilvus import MilvusClient # Initialize a Milvus Lite client with a local database file client = MilvusClient("milvus.db") # Create a collection for vectors client.create_collection( collection_name="example_collection", dimension=128 # Set to your vector dimension ) print("Milvus Lite initialized successfully!")
Option 3: Kubernetes Deployment
For production deployments, Milvus can be installed on Kubernetes using Helm:
Add the Milvus Helm repository:
helm repo add milvus https://milvus-io.github.io/milvus-helm/Update the repository:
helm repo updateInstall Milvus:
helm install my-release milvus/milvusFor more detailed configuration options, refer to the official Kubernetes deployment guide.
Note: For detailed installation instructions specific to your operating system and environment, please refer to the official documentation on the project’s GitHub repository.
Practical Exercise: Building a Document Search System with Milvus
Let’s build a simple document retrieval system using Milvus and OpenAI embeddings.
Step 1: Install Required Packages
pip install pymilvus openai numpy pandas
Step 2: Connect to Milvus and Create a Collection
from pymilvus import MilvusClient
import openai
import numpy as np
import pandas as pd
import os
# Configure OpenAI API key
openai.api_key = "your-openai-api-key"
# Connect to Milvus
client = MilvusClient("localhost:19530") # Or use Milvus Lite with "milvus.db"
# Create a collection for document embeddings
try:
client.drop_collection("documents") # Drop if exists
except:
pass
# Create collection for document embeddings
# Using OpenAI's text-embedding-3-small which produces 1536-dimensional vectors
client.create_collection(
collection_name="documents",
dimension=1536
)
print("Collection created successfully!")
Step 3: Add Sample Documents and Generate Embeddings
# Sample documents
documents = [
"Milvus is a vector database built for AI applications and similarity search",
"Vector databases store and query vector embeddings efficiently",
"Large language models use vector representations for semantic understanding",
"Retrieval augmented generation helps improve LLM accuracy with external knowledge",
"Milvus supports multiple index types including HNSW, IVF, and FLAT"
]
# Function to generate embeddings using OpenAI
def get_embedding(text):
response = openai.Embedding.create(
model="text-embedding-3-small",
input=text
)
return response["data"][0]["embedding"]
# Insert documents into Milvus
for i, doc in enumerate(documents):
# Generate embedding
embedding = get_embedding(doc)
# Insert into Milvus
client.insert(
collection_name="documents",
data=[
{"id": i, "vector": embedding, "text": doc}
]
)
print(f"Inserted document {i}: {doc[:30]}...")
# Create an index for faster search
client.create_index(
collection_name="documents",
field_name="vector",
index_type="HNSW",
metric_type="COSINE",
params={"M": 8, "efConstruction": 64}
)
print("Documents indexed successfully!")
Step 4: Perform Vector Similarity Search
# Search function
def search_documents(query, limit=3):
# Generate embedding for the query
query_embedding = get_embedding(query)
# Search in Milvus
results = client.search(
collection_name="documents",
data=[query_embedding],
limit=limit,
output_fields=["text"]
)
# Format and return results
search_results = []
for hit in results[0]:
search_results.append({
"text": hit["entity"]["text"],
"similarity": hit["distance"]
})
return search_results
# Example search
search_query = "How can AI use vector databases?"
print(f"Searching for: '{search_query}'")
results = search_documents(search_query)
# Display results
print("\nSearch Results:")
for i, result in enumerate(results):
print(f"{i+1}. {result['text']} (Similarity: {result['similarity']:.4f})")
Step 5: Exploring Advanced Features
Once you’re comfortable with the basics, you can explore Milvus’ advanced features:
- Hybrid Search: Combine vector similarity with attribute filtering
- Multi-Vector Search: Search across multiple vector fields
- Partitioning: Organize data into partitions for faster querying
- Consistency Levels: Configure different consistency guarantees
- Dynamic Schema: Modify collection schema on-the-fly
- Time Travel: Query data as of a specific point in time
Example of attribute filtering with vector search:
# Add documents with metadata
documents_with_metadata = [
{"text": "Introduction to deep learning", "category": "AI", "year": 2023},
{"text": "Vector databases for beginners", "category": "Databases", "year": 2024},
{"text": "Advanced neural networks", "category": "AI", "year": 2024},
{"text": "Distributed systems architecture", "category": "Computing", "year": 2022},
{"text": "Modern recommendation systems", "category": "AI", "year": 2023}
]
# Create collection with schema
client.create_collection(
collection_name="articles",
schema={
"fields": [
{"name": "id", "type": "INT64", "is_primary": True},
{"name": "text", "type": "VARCHAR", "max_length": 512},
{"name": "category", "type": "VARCHAR", "max_length": 64},
{"name": "year", "type": "INT64"},
{"name": "vector", "type": "FLOAT_VECTOR", "dim": 1536}
]
}
)
# Insert with metadata
for i, doc in enumerate(documents_with_metadata):
client.insert(
collection_name="articles",
data=[{
"id": i,
"text": doc["text"],
"category": doc["category"],
"year": doc["year"],
"vector": get_embedding(doc["text"])
}]
)
# Hybrid search with filtering
results = client.search(
collection_name="articles",
data=[get_embedding("Latest AI techniques")],
filter="category == 'AI' and year >= 2023",
limit=2,
output_fields=["text", "category", "year"]
)
Resources
Official Documentation
Milvus provides comprehensive and well-structured documentation:
Milvus Documentation GitHub Repository
Key Features
- High Performance: Optimized for large-scale vector similarity search with millisecond-level query latency even on billion-scale datasets
- Scalability: Distributed architecture with horizontal scaling for both storage and compute
- Index Types: Support for multiple index types including HNSW, IVF, DiskANN, FLAT, and more
- Hybrid Search: Combine vector similarity with scalar filtering for precise queries
- Data Consistency: Multiple consistency levels from strong to eventual consistency
- Deployment Options: Flexible deployment from single machine to distributed clusters
- SDK Support: Client libraries for Python, Java, Go, Node.js, and C#
- GPU Acceleration: GPU support for faster index building and search
Community Support
Milvus has an active community and professional support channels:
Discord Community GitHub Discussions Slack Workspace
Tutorials and Examples
Learn through practical examples and integration guides:
Milvus Bootcamp LangChain Integration LlamaIndex Integration
Suggested Projects
You might also be interested in these similar projects:
Qdrant is a high-performance vector similarity search engine and vector database written in Rust, designed for production-ready AI applications
Chroma is the AI-native open-source embedding database for storing and searching vector embeddings
Open-source Firebase alternative with vector database capabilities for AI applications