A lightweight version of Milvus wrapped with Python for vector similarity search in AI applications
npx @tessl/cli install tessl/pypi-milvus-lite@2.5.0A lightweight version of Milvus wrapped with Python for AI applications requiring vector similarity search. Milvus Lite provides the core vector search functionality of Milvus in a compact, embedded form suitable for development environments, prototyping, and edge devices.
pip install milvus-lite (or pip install pymilvus which includes milvus-lite)# Import through pymilvus (recommended approach)
from pymilvus import MilvusClient
# Direct imports (advanced usage)
from milvus_lite.server import Server
from milvus_lite.server_manager import server_manager_instance
# Package version
import milvus_lite
print(milvus_lite.__version__)from pymilvus import MilvusClient
import numpy as np
# Create client with local database file (this activates milvus-lite)
client = MilvusClient("./milvus_demo.db")
# Create a collection with vector dimension
client.create_collection(
collection_name="demo_collection",
dimension=384 # Vector dimension
)
# Prepare sample data
docs = [
"Artificial intelligence was founded as an academic discipline in 1956.",
"Alan Turing was the first person to conduct substantial research in AI.",
"Born in Maida Vale, London, Turing was raised in southern England.",
]
# Generate vectors (in practice, use actual embedding models)
vectors = [[np.random.uniform(-1, 1) for _ in range(384)] for _ in range(len(docs))]
data = [{"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"} for i in range(len(vectors))]
# Insert data
client.insert(collection_name="demo_collection", data=data)
# Perform vector search
results = client.search(
collection_name="demo_collection",
data=[vectors[0]], # Query vector
filter="subject == 'history'",
limit=2,
output_fields=["text", "subject"]
)
print(results)
# Query with filters
results = client.query(
collection_name="demo_collection",
filter="subject == 'history'",
output_fields=["text", "subject"]
)
print(results)Milvus Lite is a hybrid Python-C++ implementation that provides embedded vector database functionality:
This architecture enables seamless development workflows where the same API works from local prototyping with milvus-lite to production deployment with Milvus Standalone or Distributed.
The recommended way to use milvus-lite through the pymilvus client interface, which automatically activates milvus-lite when using local file URIs. This provides the complete Milvus API surface including collections, vector operations, indexing, and querying.
from pymilvus import MilvusClient
client = MilvusClient(uri="./database.db") # Activates milvus-lite
# Full Milvus API available through clientAdvanced server lifecycle management for custom integrations and process control. Provides direct access to the underlying milvus server process with configuration options for networking, logging, and resource management.
class Server:
def __init__(self, db_file: str, address: Optional[str] = None): ...
def init(self) -> bool: ...
def start(self) -> bool: ...
def stop(self) -> None: ...
@property
def uds_path(self) -> str: ...
@property
def args(self) -> List[str]: ...Thread-safe management of multiple milvus-lite server instances with automatic lifecycle handling and resource cleanup. Useful for applications managing multiple independent databases or multi-tenant scenarios.
class ServerManager:
def start_and_get_uri(self, path: str, args=None) -> Optional[str]: ...
def release_server(self, path: str) -> None: ...
def release_all(self) -> None: ...
server_manager_instance: ServerManager # Global singletonData export and migration utilities for moving data between milvus-lite and other Milvus deployments. Includes collection dumping with support for various vector types and bulk data operations.
milvus-lite dump -d DB_FILE -c COLLECTION -p PATHfrom typing import Optional, List, Dict, Any, Union
# Package-level exports
__version__: str # Package version string
# Constants
BIN_PATH: str # Path to directory containing milvus binary and libraries
# Core types used across the API
PathType = str # File system path to database file
AddressType = Optional[str] # Network address (host:port) or None for UDS
URIType = str # Connection URI (file path for milvus-lite)Milvus Lite raises specific exceptions for different error conditions:
RuntimeError: Invalid database names, path issues, server startup failuresBlockingIOError: Database file locked by another processsubprocess.TimeoutExpired: Server process management timeoutsFileNotFoundError: Missing binary files or database files^[a-zA-Z0-9.\-_]+$