SDKs overview
Milvus offers a range of Software Development Kits (SDKs) designed to facilitate interaction with the Milvus vector database. These SDKs abstract the underlying gRPC communication, allowing developers to perform operations like data insertion, vector indexing, and similarity searches using native language constructs. The availability of SDKs across several popular programming languages supports diverse development environments and integration scenarios. Milvus also provides a RESTful API for environments where SDKs are not preferred or available, as detailed in the Milvus API reference documentation.
The SDKs are developed and maintained by the Milvus community and Zilliz, the primary contributor to Milvus. They aim to provide a consistent and efficient interface for both the open-source Milvus instance and the managed Zilliz Cloud service.
Official SDKs by language
Milvus provides official SDKs for several programming languages, enabling developers to integrate vector database functionalities into their applications. Each SDK is designed to offer a language-idiomatic way to interact with Milvus clusters, supporting data manipulation, query execution, and system management tasks.
| Language | Package/Module | Maturity | Description |
|---|---|---|---|
| Python | pymilvus |
Stable | The primary Milvus client for Python, widely used for data science and AI/ML applications. It supports all core Milvus operations. |
| Java | milvus-sdk-java |
Stable | A Java client for Milvus, suitable for enterprise applications and large-scale data processing in JVM environments. |
| Go | milvus-sdk-go |
Stable | The Go language client for Milvus, often used in high-performance backend services and cloud-native applications. |
| Node.js | @zilliz/milvus2-sdk-node |
Stable | A Node.js client for Milvus, enabling JavaScript developers to integrate Milvus into their backend services. |
| C++ | milvus-sdk-cpp |
Stable | A C++ client providing direct access for performance-critical applications, often used for custom integrations. |
Installation
The installation process for Milvus SDKs typically involves using the respective language's package manager. Below are common installation commands for the officially supported SDKs:
Python SDK (pymilvus)
To install the Python client, use pip:
pip install pymilvus
For specific versions or additional features, consult the Milvus Python SDK installation guide.
Java SDK (milvus-sdk-java)
For Java projects, add the following dependency to your pom.xml (Maven) or build.gradle (Gradle):
Maven
<dependency>
<groupId>io.milvus</groupId>
<artifactId>milvus-sdk-java</artifactId>
<version>2.4.0</version> <!-- Use the latest version -->
</dependency>
Gradle
implementation 'io.milvus:milvus-sdk-java:2.4.0' // Use the latest version
Refer to the Milvus Java SDK documentation for setup details.
Go SDK (milvus-sdk-go)
To install the Go client, use go get:
go get github.com/milvus-io/milvus-sdk-go/v2
More information is available in the Milvus Go SDK installation instructions.
Node.js SDK (@zilliz/milvus2-sdk-node)
For Node.js projects, install using npm or yarn:
npm
npm install @zilliz/milvus2-sdk-node
yarn
yarn add @zilliz/milvus2-sdk-node
The Milvus Node.js SDK guide provides further details.
C++ SDK (milvus-sdk-cpp)
The C++ SDK typically requires building from source or using a package manager that supports C++ libraries. Installation often involves cloning the repository and compiling. For detailed instructions, refer to the Milvus C++ SDK documentation.
Quickstart example
This Python quickstart demonstrates connecting to Milvus, creating a collection, inserting data, and performing a vector search. This example uses the pymilvus SDK.
from pymilvus import connections, utility, FieldSchema, CollectionSchema, DataType, Collection
# 1. Connect to Milvus
connections.connect(alias="default", host="localhost", port="19530") # Replace with your Milvus instance details
# 2. Define schema for the collection
fields = [
FieldSchema(name="id", dtype=DataType.INT64, is_primary=True, auto_id=False),
FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=128)
]
collection_schema = CollectionSchema(fields, "my_vector_collection description")
# 3. Create a collection
collection_name = "my_vector_collection"
if utility.has_collection(collection_name):
utility.drop_collection(collection_name)
collection = Collection(collection_name, collection_schema, consistency_level="Strong")
# 4. Prepare data for insertion
import random
nb = 3000 # Number of vectors
dim = 128 # Dimension of vectors
data = [
[i for i in range(nb)], # IDs
[[random.random() for _ in range(dim)] for _ in range(nb)] # Embeddings
]
# 5. Insert data
insert_result = collection.insert(data)
print(f"Inserted {insert_result.insert_count} entities.")
# 6. Create an index
index_params = {
"index_type": "IVF_FLAT",
"metric_type": "L2",
"params": {"nlist": 128}
}
collection.create_index("embedding", index_params)
collection.load()
# 7. Perform a vector search
search_vector = [[random.random() for _ in range(dim)]]
search_params = {"data": search_vector, "anns_field": "embedding", "param": {"nprobe": 10}, "limit": 3}
results = collection.search(**search_params)
print("\nSearch Results:")
for hit in results[0]:
print(f"ID: {hit.id}, Distance: {hit.distance}")
# 8. Drop the collection (optional)
# utility.drop_collection(collection_name)
This example demonstrates the fundamental steps of setting up a Milvus collection, populating it with vector data, and querying for similar vectors. For more detailed examples and advanced usage, refer to the Milvus official quickstart guide.
Community libraries
Beyond the official SDKs, the Milvus ecosystem benefits from various community-contributed libraries and integrations that extend its functionality or simplify its use within specific frameworks. These contributions often include:
- Framework Integrations: Libraries that integrate Milvus with popular data science and machine learning frameworks like LangChain or LlamaIndex for building generative AI applications. For example, the LangChain Milvus integration allows using Milvus as a vector store for conversational AI.
- ORM/ODM Abstractions: Higher-level object-relational mapping (ORM) or object-document mapping (ODM) style libraries that provide more abstract interfaces over the core SDKs, simplifying data model definition and interaction.
- Tools and Utilities: Command-line tools, data migration scripts, or visualization aids that enhance the developer experience with Milvus.
- Language Bindings: Unofficial or experimental SDKs for languages not officially supported, developed by community members.
Developers can typically find these community projects on GitHub or through the broader Milvus community channels. It is advisable to check the project's activity and maintenance status before relying on community-contributed libraries for production systems. For broader context on vector databases and their role in AI, the Google Cloud blog on vector databases offers additional insights.