Last modified: Jun 13, 2026
Install Milvus Lite in Python Guide
Milvus Lite is a lightweight version of the Milvus vector database. It runs entirely in Python without a separate server. This makes it perfect for learning, prototyping, and small projects. In this guide, you will learn how to install Milvus Lite in Python step by step.
Vector databases are essential for AI applications. They store and search embeddings. Milvus Lite gives you this power without complex setup. You can run it on your laptop or in a notebook.
What is Milvus Lite?
Milvus Lite is a Python library. It is a small version of Milvus. It uses the same API as the full Milvus. You do not need Docker or a server. It stores data in a local file. This makes it easy to test and develop.
Milvus Lite supports all core features. You can create collections, insert vectors, and search. It is ideal for small datasets. For large production workloads, use the full Milvus server.
Prerequisites
Before you start, ensure you have Python installed. Milvus Lite works with Python 3.7 or newer. You also need pip, the Python package manager. Check your Python version with this command.
python --version
If Python is not installed, download it from python.org. Make sure pip is available too. Run pip --version to verify.
Step 1: Install Milvus Lite
Installing Milvus Lite is simple. Use pip to install the package. Open your terminal or command prompt. Run the following command.
pip install pymilvus
This installs the PyMilvus package. PyMilvus includes Milvus Lite. It also includes the client for the full Milvus server. The installation takes a few seconds. You will see output like this.
Collecting pymilvus
Downloading pymilvus-2.3.6-py3-none-any.whl (1.2 MB)
Installing collected packages: pymilvus
Successfully installed pymilvus-2.3.6
If you see errors, update pip first. Run pip install --upgrade pip. Then try again.
Step 2: Verify the Installation
After installation, verify it works. Open a Python shell or create a script. Import the Milvus module. Check the version.
# Import the Milvus package
from pymilvus import connections
# Print the version
import pymilvus
print(pymilvus.__version__)
Run the code. You should see the version number. For example, 2.3.6. If no error appears, installation is successful.
Step 3: Start Milvus Lite
Milvus Lite starts automatically when you connect. You do not need to start a server. Use the connections.connect method. Set the host to "localhost" and port to "19530". This creates a local database.
# Connect to Milvus Lite
from pymilvus import connections
# Start the local database
connections.connect(host="localhost", port="19530")
print("Connected to Milvus Lite")
The output will be Connected to Milvus Lite. The database is now ready. It stores data in a file named milvus.db in your current directory.
Step 4: Create a Collection
A collection is like a table in SQL. It holds your vectors. First, define the schema. Use CollectionSchema and FieldSchema. Then create the collection.
# Import necessary classes
from pymilvus import Collection, CollectionSchema, FieldSchema, DataType
# Define fields: id, embedding, and metadata
fields = [
FieldSchema(name="id", dtype=DataType.INT64, is_primary=True),
FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=128),
FieldSchema(name="title", dtype=DataType.VARCHAR, max_length=100)
]
# Create schema
schema = CollectionSchema(fields, description="My first collection")
# Create collection
collection = Collection(name="demo_collection", schema=schema)
print("Collection created successfully")
This creates a collection named demo_collection. It has three fields. The embedding field is a vector of 128 dimensions. The title field stores text.
Step 5: Insert Data
Now insert some vectors. Use the insert method. Provide a list of data. Each item must match the schema.
# Generate sample data
import random
# Create 10 random vectors
vectors = [[random.random() for _ in range(128)] for _ in range(10)]
titles = [f"document_{i}" for i in range(10)]
ids = list(range(10))
# Insert data
collection.insert([ids, vectors, titles])
print("Inserted 10 vectors")
This inserts 10 vectors. Each vector has 128 random values. The titles are simple strings. The output confirms insertion.
Step 6: Search Vectors
Searching is the core feature. Create an index first. Then perform a similarity search. Use the search method.
# Create an index for faster search
index_params = {
"metric_type": "L2",
"index_type": "IVF_FLAT",
"params": {"nlist": 128}
}
collection.create_index(field_name="embedding", index_params=index_params)
# Load collection into memory
collection.load()
# Create a random query vector
query_vector = [[random.random() for _ in range(128)]]
# Search for top 3 similar vectors
results = collection.search(
data=query_vector,
anns_field="embedding",
param={"metric_type": "L2", "params": {"nprobe": 10}},
limit=3,
output_fields=["title"]
)
# Print results
for result in results[0]:
print(f"ID: {result.id}, Distance: {result.distance}, Title: {result.entity.get('title')}")
The output shows the closest vectors. It includes the ID, distance, and title. The distance indicates similarity. Lower distance means more similar.
ID: 3, Distance: 16.23, Title: document_3
ID: 7, Distance: 18.45, Title: document_7
ID: 1, Distance: 19.01, Title: document_1
Step 7: Clean Up
When done, release resources. Drop the collection to remove data. Then disconnect.
# Drop the collection
collection.drop()
print("Collection dropped")
# Disconnect
connections.disconnect("default")
print("Disconnected from Milvus Lite")
This clears the database. The milvus.db file remains. You can delete it manually if needed.
Troubleshooting Common Issues
Some users face errors. Here are solutions.
ImportError: No module named pymilvus. This means the package is not installed. Run pip install pymilvus again. Ensure you use the correct Python environment.
ConnectionError: Cannot connect. Milvus Lite may not start. Check your firewall. Try running as administrator. Or restart your Python kernel.
PermissionError: Access denied. Milvus Lite writes a file. Ensure you have write permissions in the current directory. Change directory to a writable location.
Conclusion
Installing Milvus Lite in Python is straightforward. You installed it with pip. You connected, created a collection, inserted data, and searched vectors. This gives you a local vector database in minutes. Use it for learning, testing, and small AI projects. For production, consider the full Milvus server. Start building your vector search applications today.