Milvus 연결 시작하기
Milvus는 비정형 데이터 임베딩으로 AI 애플리케이션을 구축하기 위한 오픈 소스 벡터 데이터베이스입니다. 시작하는 데 필요한 모든 것이 기본으로 내장되어 있으며, 로컬 머신에서 실행하거나 Zilliz Cloud에 호스팅할 수 있습니다(노트북 Zilliz Free Tier에 연결 참조).
Milvus에는 네 가지 SDK가 있습니다: Java, Python, React, 그리고 Ruby. 아래에서는 Python을 위한 단계를 보여드리겠습니다.
Milvus 서버 설치 및 시작
pip install milvus pymilvus #pymilvus is the python sdk
from milvus import default_server
default_server.start()
참고: Zilliz에 연결하는 경우, Milvus 설치를 건너뛰고 대신 콘솔에서 클러스터를 시작할 수 있습니다.
Milvus 클라이언트 가져오기(연결)
from pymilvus import connections
connections.connect(
host=’127.0.0.1’,
port=default_server.listen_port)
참고: localhost 대신 Zilliz Cloud에서 실행되는 서버리스 Milvus에 연결하려면, 콘솔에서 엔드포인트 uri와 토큰을 가져와야 합니다.
from pymilvus import connections
ENDPOINT=”https://endpoint.api.region.zillizcloud.com:443”
connections.connect(
uri=ENDPOINT,
token=TOKEN)
컬렉션 생성
컬렉션은 데이터베이스 테이블과 같다고 생각할 수 있습니다. 임베딩, 문서, 그리고 추가 메타데이터를 저장하는 곳입니다.
컬렉션에는 스키마와 인덱스가 연결되어 있습니다.
인덱스는 벡터 검색 알고리즘과 벡터 유사도 메트릭을 사용해 구축됩니다. Milvus 기본값을 사용할 수 있습니다. 그러나 최적의 성능을 위해서는 매개변수를 구성해야 합니다. 검색 인덱스와 매개변수의 선택은 데이터에 따라 달라집니다. 검색 인덱스 선택에 대해서는 이 모범 사례 가이드를 참조하세요. 이 노트북은 매개변수를 수정하는 방법을 보여줍니다.
from pymilvus import (
FieldSchema, DataType,
CollectionSchema, Collection)
## 1. Define a minimum expandable schema.
fields = [
FieldSchema(“pk”, DataType.INT64, is_primary=True, auto_id=True),
FieldSchema(“vector”, DataType.FLOAT_VECTOR, dim=768),
]
schema = CollectionSchema(
fields,
enable_dynamic_field=True,
)
## 2. Create a collection.
mc = Collection(“my_collection_name”, schema)
## 3. Index the collection.
mc.create_index(
field_name=”vector”,
index_params={
“Index_type”: “AUTOINDEX”,
“Metric_type”: “COSINE”,
}
Milvus에 데이터 삽입
비정형 데이터에서 이미 생성된 임베딩이 있다면, 이를 로드할 수 있습니다.
입력 데이터는 pandas dataframe 또는 딕셔너리 목록 형태일 수 있습니다. 벡터 임베딩을 포함해야 합니다. 나머지 필드는 선택 사항입니다: 원본 텍스트 청크와 메타데이터 필드.
from pymilvus import connections
## 1. Input data can be pandas dataframe or list of dicts.
data_rows = []
data_rows.extend([
{“vector”: np.random.randn(768).tolist(),
“text”: “This is a document”,
“source”: “source_url_1”},
{“vector”: np.random.randn(768).tolist(),
“text”: “This is another document”,
“source”: “source_url_2”},
])
## 2. Insert data into milvus.
mc.insert(data_rows)
mc.flush()
컬렉션 쿼리
질문은 데이터베이스에 로드된 비정형 데이터를 임베딩하는 데 사용한 것과 동일한 모델을 사용해 임베딩해야 합니다. 질문 임베딩을 사용하여 Milvus 기본 검색 매개변수로 컬렉션을 쿼리할 수 있습니다. 최적의 성능을 위해 적절한 검색 인덱스를 선택하는 데에도 동일한 모범 사례가 적용됩니다.
아래에서 Milvus는 top_k = 3개의 가장 유사한 결과를 반환합니다. 또한 원본 텍스트 청크와 메타데이터가 반환된다는 점에 주목하세요. 이는 그라운딩(환각을 줄이기 위해 생성된 텍스트를 사실 정보에 기반하도록 하는 것)에 도움이 될 수 있습니다.
## 1. Search for answers to your embedded questions.
mc.load()
results = mc.search(
data=encoder([“my_question_1”]),
anns_field=”vector”,
output_fields-[“text”, “source”], #optional return fields
limit=3,
param={}, #no params if using milvus defaults
)
## 2. View the answers.
for n, hits in enumerate(results):
print(f”{n}th result:”)
for hit in hits:
print(hit)
다음 블로그에서는 LangChain과 Milvus를 사용해 챗봇을 구축하는 방법을 다룰 예정입니다. 기대해 주세요.
Milvus와 Zilliz를 시작하기 위한 추가 리소스
계속 읽기

Build Multimodal Search for 3D Assets with Tripo and Zilliz Cloud
Generate 3D assets with Tripo, then search them by text, image, and metadata with multimodal embeddings and Zilliz Cloud.

Zilliz Named "Highest Performer" and "Easiest to Use" in G2's Summer 2025 Grid® Report for Vector Databases
Zilliz shines in G2's Summer 2025 Grid® Report as both "Highest Performer" and "Easiest to Use," solving the performance-usability dilemma.

What is the K-Nearest Neighbors (KNN) Algorithm in Machine Learning?
KNN is a supervised machine learning technique and algorithm for classification and regression. This post is the ultimate guide to KNN.



