メインコンテンツまでスキップ

Serving Cluster クイックスタート

serving cluster は、リアルタイム本番運用向けにコンピュートとストレージの両方を組み合わせた自己完結型サーバーです。Extract-Transform-Load (ETL) パイプラインを通じてデータをクリーンアップした後、それを serving cluster にインポートすることで、大幅なパフォーマンス向上を実現できます。

開始前に

Zilliz Cloud は Bring-Your-Own-Cloud (BYOC) ソリューションを提供しており、組織は Zilliz Cloud のインフラストラクチャ上ではなく、自社のクラウドアカウント内でアプリケーションとデータをホストできます。BYOC ソリューションの詳細については、BYOC Overview を参照してください。

次の図は、BYOC ソリューションを開始するための手順を示しています。

W1G2wotilhctoibaBlocf2bfngf

このクイックスタートを進める前に、以下を確認してください。

  • Zilliz Cloud でアカウント登録が完了していること。

    手順については、Register with Zilliz Cloud を参照してください。

  • Zilliz Cloud の営業に連絡し、アカウント情報を提供済みであること。

    📘注記

    Zilliz BYOC は現在 General Availability として提供されています。アクセス方法および実装の詳細については、Zilliz Cloud sales までお問い合わせください。

  • BYOC 組織内に project を作成し、その project 用の data plane インフラストラクチャをデプロイ済みであること。

    Zilliz BYOC はお使いの Virtual Private Cloud (VPC) 内で動作するため、data plane コンポーネントのデプロイを開始する必要があります。次のクラウドプロバイダー上でホストされる VPC に data plane をデプロイできます。

    お使いのクラウドプロバイダーが上記にない場合は、Zilliz Cloud support までお問い合わせください。

  • BYOC cluster への接続方法を決定済みであること。詳細については、Prepare for Cluster Connection を参照してください。

以下の手順では、すでに serving cluster を作成し、その endpoint とアクセス認証情報を取得済みであることを前提としています。

ステップ 1: 接続を設定する

cluster の認証情報を取得したら、それを使用して cluster に接続できます。

python
from pymilvus import MilvusClient, DataType

SERVING_CLUSTER_ENDPOINT = "https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530"
TOKEN = "YOUR_ZILLIZ_API_KEY"
# A valid token could be
#
# - Use your Zilliz Cloud API key

# 1. Set up a Milvus client
client = MilvusClient(
uri=SERVING_CLUSTER_ENDPOINT,
token=TOKEN
)

ステップ 2: (任意)database を作成する。

serving cluster にはデフォルトの database が付属しています。それを使用する場合は、このステップをスキップしてください。次のように database を作成することもできます。

python
# connect to the serving cluster
client = MilvusClient(
# a cluster-specific endpoint
uri=SERVING_CLUSTER_ENDPOINT,
token=TOKEN
)

client.create_database(
db_name="my_database"
)

ステップ 3: collection を作成する。

database の準備ができたら、その中に managed collection を作成できます。collection の列を外部データファイルにマッピングする external collection とは異なり、managed collection では大幅なパフォーマンス向上のためにデータをインポートする必要があります。

次の例は、collection schema を設定して collection を作成する方法を示しています。

python
from pymilvus import MilvusClient, DataType

schema = MilvusClient.create_schema()

schema.add_field(
field_name="product_id",
datatype=DataType.INT64,
is_primary=True
)

schema.add_field(
field_name="product_name",
datatype=DataType.VARCHAR,
max_length=512
)

schema.add_field(
field_name="embedding",
datatype=DataType.FLOAT_VECTOR,
dim=768
)

その後、上記の schema を使用して collection を作成できます。デフォルトの database を使用する場合は、db_name パラメーターを安全に省略できます。

python
client.use_database(
db_name="my_database"
)

# create the collection
client.create_collection(
collection_name="prod_collection",
schema=schema
)

ステップ 4: index を作成する。

すべての vector field に対して index を作成し、必要に応じて選択した scalar field に対しても index を作成する必要があります。

python
index_params = client.prepare_index_params()

# Add indexes
index_params.add_index(
field_name="embedding",
index_type="AUTOINDEX",
metric_type="COSINE"
)

index_params.add_index(
field_name="product_name",
index_type="AUTOINDEX"
)

client.create_index(
db_name="my_database",
collection_name="prod_collection",
index_params=index_params
)

ステップ 5: collection をロードする。

index の準備ができたら、collection をメモリにロードします。

python
client.load_collection(
db_name="my_database",
collection_name="prod_collection"
)

ステップ 6: データをインポートする。

すべての設定が完了したら、処理済みデータをインポートできます。次の例では、処理済みデータを external storage bucket に保存していることを前提としています。

bucket 内のデータ形式または storage integration については、Format Options を参照してください。

python
from pymilvus.bulk_writer import bulk_import

# The path should be relative to the root
# of a zilliz cloud volume or an external storage
OBJECT_URLS = [[
"https://s3.us-west-2.amazonaws.com/your-bucket/path/in/external/storage.json"
]]

ACCESS_KEY = "YOUR_STORAGE_ACCESS_KEY"
SECRET_KEY = "YOUR_STORAGE_SECRET_KEY"

res = bulk_import(
api_key="YOUR_ZILLIZ_API_KEY",
url="https://api.cloud.zilliz.com",
cluster_id="inxx-xxxxxxxxxxxxxxxxxxx",
db_name="my_database",
collection_name="prod_collection",
object_urls=OBJECT_URLS,
access_key=ACCESS_KEY,
secret_key=SECRET_KEY
)

# job-xxxxxxxxxxxxxxxxxxxxx

返された job ID を使用して、進行状況を監視できます。

python
import json
from pymilvus.bulk_writer import get_import_progress

# Get bulk-insert job progress
resp = get_import_progress(
api_key="YOUR_ZILLIZ_API_KEY",
url="https://api.cloud.zilliz.com",
cluster_id="inxx-xxxxxxxxxxxxxxxxxxx",
job_id="job-xxxxxxxxxxxxxxxxxxxxx",
)

print(json.dumps(resp.json(), indent=4))

ステップ 7: データを提供する。

インポートが完了したら、検索、クエリ、および hybrid search を通じてユーザーがデータを利用できるようにできます。

python
query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, ..., 0.9029438446296592]
res = client.search(
db_name="my_database",
collection_name="prod_collection",
anns_field="embedding",
data=[query_vector],
limit=3,
output_fields=["product_name"]
)
Ctrl I