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

Alter External コレクション スキーマ

External data sources often evolve after you create an external コレクション. For example, a lakehouse table that already stores embeddings might later include a new スカラー field, such as a score, category, or timestamp, that you want to return in query results or use in filters.

Instead of recreating the external コレクション or copying the source data into Zilliz Cloud, add a Zilliz Cloud field that maps to the existing field in the external data source. After adding the field, refresh the external コレクション so the new field can be used in queries and searches.

Limits​

  • External コレクション currently support adding fields after creation. Other スキーマ changes, such as dropping fields, renaming fields, changing field data types, changing ベクトル dimensions, or remapping external_field, are not supported.

  • 追加できるのは、External data source にすでに存在する field のみです。この操作は、既存の external field を Zilliz Cloud field にマッピングします。External data source に新しい field を作成したり、ソースデータを backfill したりするものではありません。

  • Adding SPARSE_FLOAT_VECTOR fields to an existing external コレクション is not supported.

  • Adding StructArray fields to an existing external コレクション is not supported. If your external コレクション needs a StructArray field, define it in the コレクション スキーマ when you create the コレクション.

field の追加​

Before adding a field to an external コレクション, verify that the field already exists in the external data source. Then call add_collection_field() to expose that field in Zilliz Cloud by setting external_field to the field name in the external data source. Set data_type to the Zilliz Cloud data type that matches the field in the external data source. For example, if the mapped field stores double-precision values, use DataType.DOUBLE.

Unlike managed コレクション, values for the added field are read from the external data source after you refresh the external コレクション.

Add a スカラー field​

Use add_collection_field() to add a スカラー field when you want to return the field in query results or use it in filters. The following example adds a score field that maps to the score field in the external data source.

python
from pymilvus import DataType, MilvusClient

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN",
)

client.add_collection_field(
collection_name="product_embeddings",
field_name="score",
data_type=DataType.DOUBLE,
nullable=True,
external_field="score",
)

In this example, score is the Zilliz Cloud field name and external_field="score" maps it to the score field in the external data source. Set nullable=True because the field is added after the コレクション has already been created.

Add a ベクトル field​

You can also add a ベクトル field if the external data source already contains the ベクトル values. Set the ベクトル data_type and dim to match the ベクトル field in the external data source.

The following example adds a dense ベクトル field named image_embedding_v2.

python
from pymilvus import DataType, MilvusClient

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN",
)

client.add_collection_field(
collection_name="product_embeddings",
field_name="image_embedding_v2",
data_type=DataType.FLOAT_VECTOR,
dim=768,
nullable=True,
external_field="image_embedding_v2",
)

If you plan to run ベクトル search on the added ベクトル field, create an インデックス for the field before refreshing the external コレクション.

python
index_params = client.prepare_index_params()

index_params.add_index(
field_name="image_embedding_v2",
index_type="AUTOINDEX",
metric_type="COSINE",
)

client.create_index(
collection_name="product_embeddings",
index_params=index_params,
)

Refresh the external コレクション​

After altering an external コレクション スキーマ, refresh the external コレクション so Zilliz Cloud updates the external コレクション metadata and makes the スキーマ change effective in query, search, and filter results.

python
client.refresh_external_collection(
collection_name="product_embeddings"
)