Milvus is the most popular open-source vector database for AI applications. It powers similarity search for RAG, recommendation systems, image search, and anomaly detection at companies like Salesforce, PayPal, and Shopee.
Free, open source, CNCF graduated project. Handles billions of vectors.
Why Use Milvus?
- Purpose-built for vectors — not a bolted-on feature in a general database
- Billion-scale — handles 1B+ vectors with sub-second search
- Multiple indexes — IVF, HNSW, DiskANN, GPU indexes
- Hybrid search — combine vector similarity with scalar filtering
- Cloud-native — scales horizontally, Kubernetes-ready
Quick Setup
1. Install
# Docker Compose (easiest)
wget https://github.com/milvus-io/milvus/releases/download/v2.4.0/milvus-standalone-docker-compose.yml -O docker-compose.yml
docker compose up -d
# Milvus Lite (embedded, for development)
pip install pymilvus
2. Create Collection & Insert Vectors
from pymilvus import MilvusClient
client = MilvusClient(uri="http://localhost:19530")
# Create collection
client.create_collection(
collection_name="articles",
dimension=768 # embedding dimension
)
# Insert vectors
import random
data = [
{"id": i, "vector": [random.random() for _ in range(768)],
"title": f"Article {i}", "category": "tech"}
for i in range(1000)
]
client.insert(collection_name="articles", data=data)
3. Search
# Vector similarity search
results = client.search(
collection_name="articles",
data=[[random.random() for _ in range(768)]], # query vector
limit=5,
output_fields=["title", "category"]
)
for hits in results:
for hit in hits:
print(f"ID: {hit['id']} | Distance: {hit['distance']:.4f} | Title: {hit['entity']['title']}")
# Filtered search
results = client.search(
collection_name="articles",
data=[[random.random() for _ in range(768)]],
limit=5,
filter='category == "tech"',
output_fields=["title"]
)
4. REST API
MILVUS="http://localhost:19530"
# List collections
curl -s "$MILVUS/v2/vectordb/collections/list" -H "Content-Type: application/json" -d '{}' | jq
# Search vectors
curl -s "$MILVUS/v2/vectordb/entities/search" \
-H "Content-Type: application/json" \
-d '{
"collectionName": "articles",
"data": [[0.1, 0.2, ...]],
"limit": 5,
"outputFields": ["title"]
}' | jq
# Get collection info
curl -s "$MILVUS/v2/vectordb/collections/describe" \
-d '{"collectionName": "articles"}' | jq
RAG Example
from pymilvus import MilvusClient
from openai import OpenAI
milvus = MilvusClient(uri="http://localhost:19530")
openai_client = OpenAI()
def get_embedding(text):
response = openai_client.embeddings.create(
model="text-embedding-3-small", input=text)
return response.data[0].embedding
# Index documents
docs = ["Web scraping extracts data from websites",
"Rate limiting prevents server overload",
"BeautifulSoup parses HTML documents"]
data = [{"id": i, "vector": get_embedding(doc), "text": doc}
for i, doc in enumerate(docs)]
milvus.insert(collection_name="knowledge", data=data)
# RAG query
query = "How to extract data from websites?"
results = milvus.search(
collection_name="knowledge",
data=[get_embedding(query)],
limit=3, output_fields=["text"])
context = "\n".join([hit["entity"]["text"] for hit in results[0]])
answer = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "system", "content": f"Answer based on: {context}"},
{"role": "user", "content": query}])
print(answer.choices[0].message.content)
Key REST Endpoints
| Endpoint | Description |
|---|---|
| /v2/vectordb/collections/list | List collections |
| /v2/vectordb/collections/create | Create collection |
| /v2/vectordb/entities/insert | Insert vectors |
| /v2/vectordb/entities/search | Vector search |
| /v2/vectordb/entities/query | Scalar query |
| /v2/vectordb/entities/delete | Delete entities |
Need custom data extraction or scraping solution? I build production-grade scrapers for any website. Email: Spinov001@gmail.com | My Apify Actors
Top comments (0)