PyMilvus

2.6.8 · active · verified Sat Feb 28

Official Python SDK for Milvus, the open-source vector database. Has two coexisting APIs: the modern MilvusClient (recommended, introduced in 2.3) and the legacy ORM API (connections.connect + Collection class). Both currently work but LLM-generated and tutorial code overwhelmingly uses the old ORM patterns. Milvus Lite (embedded SQLite-based local mode) is available via the milvus-lite extra on Linux/macOS only. Server version must be kept in sync with client minor version.

Warnings

Install

Imports

Quickstart

MilvusClient is the recommended API for all new code. Milvus Lite works for prototyping on Linux/macOS but is NOT available on Windows.

from pymilvus import MilvusClient, DataType

# Connect to running Milvus server
client = MilvusClient(uri='http://localhost:19530', token='root:Milvus')

# Milvus Lite (embedded, no server, Linux/macOS only):
# client = MilvusClient('my_data.db')

# Create collection (simple API)
client.create_collection(
    collection_name='docs',
    dimension=768,
)

# Insert
data = [
    {'id': 1, 'vector': [0.1] * 768, 'text': 'hello world'},
]
client.insert(collection_name='docs', data=data)

# Search
results = client.search(
    collection_name='docs',
    data=[[0.1] * 768],
    limit=5,
    output_fields=['text'],
)
print(results)

view raw JSON →