Example
Milvus Lite — embedded vector search

A real, runnable mini-project. Download it and run with Docker.

June 28, 2026

Milvus Lite — embedded vector search

A tiny Milvus script using Milvus Lite: it creates a collection, inserts a few vectors, runs a similarity search, and prints the closest row. Embedded from a local file — no server, no API key, no network — so the output is deterministic.

Run with Docker

cd samples/milvus_1
docker build -t aas-milvus .
docker run --rm aas-milvus

Run with Docker (in a devcontainer with DooD)

In a dev container that talks to the host Docker daemon (Docker-outside-of-Docker), the foreground docker run above often prints nothing and exits 0 — but the run itself succeeds. Run detached and follow the logs instead:

cd samples/milvus_1
docker build -t aas-milvus .
docker logs -f "$(docker run -d aas-milvus)"

Run locally

cd samples/milvus_1
pip install -r requirements.txt
python app.py

The same MilvusClient API scales from Milvus Lite to a self-hosted Milvus cluster or Zilliz Cloud — just pass a server URI instead of a file path.


Example run

Milvus Lite runs locally and this sample is deterministic, so the output is the same every run.

nearest: Cats are independent pets that purr.

Files

app.py
"""Milvus Lite: embedded Milvus from a local file — no server to start.

Creates a collection, inserts a few vectors, runs a similarity search, and
prints the closest row. Fully local and deterministic: no API key, no network.

Run:
    docker build -t aas-milvus .
    docker run --rm aas-milvus
"""

from pymilvus import MilvusClient


def main() -> None:
    client = MilvusClient("/tmp/milvus-demo.db")  # Milvus Lite — embedded file
    if client.has_collection("docs"):
        client.drop_collection("docs")
    client.create_collection("docs", dimension=4)
    client.insert(
        "docs",
        [
            {"id": 1, "vector": [0.1, 0.2, 0.3, 0.4], "text": "Cats are independent pets that purr."},
            {"id": 2, "vector": [0.9, 0.8, 0.7, 0.6], "text": "A rocket is propelled by ejecting exhaust."},
        ],
    )

    hits = client.search("docs", data=[[0.12, 0.21, 0.29, 0.41]], limit=1, output_fields=["text"])
    print("nearest:", hits[0][0]["entity"]["text"])


if __name__ == "__main__":
    main()