컬렉션 필드 변경 (Alter Collection Field)
컬렉션 필드의 속성을 바꿔 컬럼 제약 조건을 수정하거나 더 엄격한 데이터 무결성 규칙을 적용할 수 있어요.
이 페이지는 필드의 속성 변경을 다루며, 필드 추가나 삭제 같은 스키마 형태 변경은 다루지 않아요. 기존 컬렉션에 스칼라 필드를 추가하거나 필드를 삭제하려면 Alter Collection Schema를 참고하세요.
- 각 컬렉션은 기본 필드(primary field) 하나만 가져요. 컬렉션 생성 시 설정한 뒤에는 기본 필드를 바꾸거나 그 속성을 변경할 수 없어요.
- 각 컬렉션은 파티션 키(partition key) 하나만 가질 수 있어요. 컬렉션 생성 시 설정한 뒤에는 파티션 키를 변경할 수 없어요.
출처: Milvus 문서
본문
VarChar 필드 변경 (Alter VarChar field)
VarChar 필드에는 max_length라는 속성이 있는데, 이는 필드 값이 포함할 수 있는 최대 문자 수를 제한해요. max_length 속성을 변경할 수 있어요.
다음 예시는 컬렉션에 varchar라는 이름의 VarChar 필드가 있다고 가정하고 그 max_length 속성을 설정해요.
from pymilvus import MilvusClient
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
client.alter_collection_field(
collection_name="my_collection",
field_name="varchar",
field_params={
"max_length": 1024
}
)
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.service.collection.request.*;
ConnectConfig config = ConnectConfig.builder()
.uri("http://localhost:19530")
.token("root:Milvus")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName("my_collection")
.fieldName("varchar")
.property("max_length", "1024")
.build());
await client.alterCollectionFieldProperties({
collection_name: LOAD_COLLECTION_NAME,
field_name: 'varchar',
properties: { max_length: 1024 },
});
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/entity"
"github.com/milvus-io/milvus/client/v2/milvusclient"
"github.com/milvus-io/milvus/pkg/v2/common"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "localhost:19530"
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
defer client.Close(ctx)
err = client.AlterCollectionFieldProperty(ctx, milvusclient.NewAlterCollectionFieldPropertiesOption(
"my_collection", "varchar").WithProperty(common.MaxLengthKey, 1024))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/collections/fields/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data "{
\"collectionName\": \"my_collection\",
\"field_name\": \"varchar\",
\"properties\": {
\"max_length\": \"1024\"
}
}"
ARRAY 필드 변경 (Alter ARRAY field)
배열 필드에는 element_type과 max_capacity 두 가지 속성이 있어요. 전자는 배열 안 요소의 데이터 타입을 결정하고, 후자는 배열의 최대 요소 수를 제한해요. max_capacity 속성만 변경할 수 있어요.
다음 예시는 컬렉션에 array라는 이름의 배열 필드가 있다고 가정하고 그 max_capacity 속성을 설정해요.
client.alter_collection_field(
collection_name="my_collection",
field_name="array",
field_params={
"max_capacity": 64
}
)
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName("my_collection")
.fieldName("array")
.property("max_capacity", "64")
.build());
await client.alterCollectionFieldProperties({
collection_name: "my_collection",
field_name: 'array',
properties: {
max_capacity: 64
}
});
err = client.AlterCollectionFieldProperty(ctx, milvusclient.NewAlterCollectionFieldPropertiesOption(
"my_collection", "array").WithProperty(common.MaxCapacityKey, 64))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/collections/fields/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data "{
\"collectionName\": \"my_collection\",
\"field_name\": \"array\",
\"properties\": {
\"max_capacity\": \"64\"
}
}"
필드별 mmap 설정 변경 (Alter field-level mmap settings)
메모리 매핑(Mmap)은 디스크의 큰 파일에 직접 메모리 접근을 가능하게 해, Milvus가 인덱스와 데이터를 메모리와 하드 드라이브 양쪽에 저장할 수 있게 해 줘요. 이 방식은 접근 빈도에 따라 데이터 배치 정책을 최적화해 검색 성능에 영향을 주지 않으면서 컬렉션의 저장 용량을 늘려 줘요.
다음 예시는 컬렉션에 doc_chunk라는 이름의 필드가 있다고 가정하고 그 mmap_enabled 속성을 설정해요.
client.alter_collection_field(
collection_name="my_collection",
field_name="doc_chunk",
field_params={"mmap.enabled": True}
)
client.alterCollectionField(AlterCollectionFieldReq.builder()
.collectionName("my_collection")
.fieldName("doc_chunk")
.property("mmap.enabled", "True")
.build());
await client.alterCollectionProperties({
collection_name: "my_collection",
field_name: 'doc_chunk',
properties: {
'mmap.enabled': true,
}
});
err = client.AlterCollectionFieldProperty(ctx, milvusclient.NewAlterCollectionFieldPropertiesOption(
"my_collection", "doc_chunk").WithProperty(common.MmapEnabledKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/collections/fields/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data "{
\"collectionName\": \"my_collection\",
\"field_name\": \"doc_chunk\",
\"properties\": {
\"mmap.enabled\": True
}
}"
더 알아보기 (Learn more)
- Alter Collection Schema — 필드 추가·삭제 같은 스키마 형태 변경
- Milvus 공식 문서 — 상세 참고 자료