예제
Milvus Lite — 임베디드 벡터 검색

실제로 실행 가능한 미니 프로젝트입니다. 받아서 Docker로 실행해 보세요.

2026년 6월 28일

Milvus Lite — 임베디드 벡터 검색

Milvus Lite를 쓰는 아주 작은 Milvus 스크립트입니다. 컬렉션을 만들고 벡터 몇 개를 넣은 뒤 유사도 검색으로 가장 가까운 행을 출력합니다. 로컬 파일에서 임베디드로 동작해 서버·API 키·네트워크가 필요 없고, 출력이 결정적입니다.

Docker로 실행

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

Docker로 실행 (DooD를 쓰는 devcontainer에서)

호스트 Docker 데몬과 통신하는 dev container(Docker-outside-of-Docker)에서는 위의 포그라운드 docker run이 종종 아무것도 출력하지 않고 exit 0으로 끝납니다. 하지만 실행 자체는 성공한 것입니다. detached로 실행하고 로그를 따라가세요:

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

로컬에서 실행

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

같은 MilvusClient API가 Milvus Lite에서 셀프호스트 Milvus 클러스터나 Zilliz Cloud까지 확장됩니다 — 파일 경로 대신 서버 URI만 넘기면 됩니다.


실행 결과

Milvus Lite는 로컬에서 동작하고 이 샘플은 결정적이라, 출력이 매번 동일합니다.

nearest: Cats are independent pets that purr.

파일

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()