컬렉션 수정

컬렉션의 이름을 바꾸거나 컬렉션의 설정을 변경할 수 있습니다. 이 페이지에서는 컬렉션을 수정하는 방법에 대해 중점적으로 설명합니다.

컬렉션 이름 바꾸기

다음과 같이 컬렉션의 이름을 변경할 수 있습니다.

from pymilvus import MilvusClient

client = MilvusClient(
    uri="http://localhost:19530",
    token="root:Milvus"
)

client.rename_collection(
    old_name="my_collection",
    new_name="my_new_collection"
)
import io.milvus.v2.service.collection.request.RenameCollectionReq;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;

String CLUSTER_ENDPOINT = "http://localhost:19530";
String TOKEN = "root:Milvus";

// 1. Connect to Milvus server
ConnectConfig connectConfig = ConnectConfig.builder()
    .uri(CLUSTER_ENDPOINT)
    .token(TOKEN)
    .build();
    
MilvusClientV2 client = new MilvusClientV2(connectConfig);

RenameCollectionReq renameCollectionReq = RenameCollectionReq.builder()
        .collectionName("my_collection")
        .newCollectionName("my_new_collection")
        .build();

client.renameCollection(renameCollectionReq);
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";

const address = "http://localhost:19530";
const token = "root:Milvus";
const client = new MilvusClient({address, token});

const res = await client.renameCollection({
    oldName: "my_collection",
    newName: "my_new_collection"
});
import (
    "context"
    "fmt"

    "github.com/milvus-io/milvus/client/v2/milvusclient"
)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

milvusAddr := "localhost:19530"
token := "root:Milvus"

client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
    Address: milvusAddr,
    APIKey:  token,
})
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
defer client.Close(ctx)

err = client.RenameCollection(ctx, milvusclient.NewRenameCollectionOption("my_collection", "my_new_collection"))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"

curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/rename" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
    "collectionName": "my_collection",
    "newCollectionName": "my_new_collection"
}'

컬렉션 속성 설정

컬렉션을 만든 후 컬렉션 수준 속성을 수정할 수 있습니다.

지원되는 속성

속성

설명

collection.ttl.seconds

컬렉션의 데이터를 특정 기간 후에 삭제해야 하는 경우 TTL(Time-To-Live)을 초 단위로 설정하는 것이 좋습니다. TTL이 초과되면 Milvus는 컬렉션에서 모든 엔티티를 삭제합니다.

삭제는 비동기식으로 이루어지므로 삭제가 완료되기 전에도 검색 및 쿼리가 가능합니다.

자세한 내용은 컬렉션 TTL 설정을 참조하세요.

mmap.enabled

메모리 매핑(Mmap)을 사용하면 디스크의 대용량 파일에 직접 메모리에 액세스할 수 있으므로 Milvus는 인덱스와 데이터를 메모리와 하드 드라이브 모두에 저장할 수 있습니다. 이 접근 방식은 액세스 빈도에 따라 데이터 배치 정책을 최적화하여 검색 성능에 영향을 주지 않으면서 컬렉션의 저장 용량을 확장하는 데 도움이 됩니다.

자세한 내용은 mmap 사용을 참조하세요.

partitionkey.isolation

파티션 키 격리를 활성화하면 Milvus는 파티션 키 값을 기준으로 엔터티를 그룹화하고 각 그룹에 대해 별도의 인덱스를 생성합니다. 검색 요청을 받으면 Milvus는 필터링 조건에 지정된 파티션 키 값을 기준으로 인덱스를 찾고 인덱스에 포함된 엔티티 내에서 검색 범위를 제한하여 검색 중 관련 없는 엔티티를 검색하지 않고 검색 성능을 크게 향상시킵니다.

자세한 내용은 파티션 키 격리 사용을 참조하세요.

dynamicfield.enabled

동적 필드를 활성화하지 않고 만든 컬렉션에 대해 동적 필드를 활성화합니다. 활성화하면 원래 스키마에 정의되지 않은 필드가 있는 엔티티를 삽입할 수 있습니다. 자세한 내용은 동적 필드를 참조하세요.

allow_insert_auto_id

컬렉션에 대해 AutoID가 활성화된 경우 컬렉션에서 사용자가 제공한 기본 키 값을 허용할지 여부입니다.

  • "true"로 설정하면: 삽입, 업서트 및 대량 가져오기는 사용자가 제공한 기본 키가 있는 경우 해당 기본 키를 사용하며, 그렇지 않으면 기본 키 값이 자동으로 생성됩니다.

  • "false"로 설정된 경우: 사용자가 제공한 기본 키 값이 거부되거나 무시되며 기본 키 값은 항상 자동 생성됩니다. 기본값은 "false"입니다.

timezone

시간에 민감한 작업, 특히 TIMESTAMPTZ 필드를 처리할 때 이 컬렉션의 기본 시간대를 지정합니다. 타임스탬프는 내부적으로 UTC로 저장되며, Milvus는 이 설정에 따라 표시 및 비교를 위해 값을 변환합니다. 설정된 경우 컬렉션 표준 시간대가 데이터베이스의 기본 표준 시간대를 재정의하며, 쿼리의 표준 시간대 매개변수는 일시적으로 두 표준 시간대를 모두 재정의할 수 있습니다. 값은 유효한 IANA 표준 시간대 식별자 (예: 아시아/상하이, 미국/시카고 또는 UTC)여야 합니다. TIMESTAMPTZ 필드 사용 방법에 대한 자세한 내용은 TIMESTAMPTZ 필드를 참조하세요.

예 1: 컬렉션 TTL 설정

다음 코드 스니펫은 컬렉션 TTL을 설정하는 방법을 보여줍니다.

from pymilvus import MilvusClient

client.alter_collection_properties(
    collection_name="my_collection",
    properties={"collection.ttl.seconds": 60}
)
import io.milvus.v2.service.collection.request.AlterCollectionReq;
import java.util.HashMap;
import java.util.Map;

Map<String, String> properties = new HashMap<>();
properties.put("collection.ttl.seconds", "60");

AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
        .collectionName("my_collection")
        .properties(properties)
        .build();

client.alterCollection(alterCollectionReq);
res = await client.alterCollection({
    collection_name: "my_collection",
    properties: {
        "collection.ttl.seconds": 60
    }
})
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.CollectionTTLConfigKey, 60))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"

curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
    "collectionName": "test_collection",
    "properties": {
        "collection.ttl.seconds": 60
    }
}'

예 2: mmap 활성화

다음 코드 스니펫은 mmap을 활성화하는 방법을 보여줍니다.

from pymilvus import MilvusClient

client.alter_collection_properties(
    collection_name="my_collection",
    properties={"mmap.enabled": True}
)
Map<String, String> properties = new HashMap<>();
properties.put("mmap.enabled", "True");

AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
        .collectionName("my_collection")
        .properties(properties)
        .build();

client.alterCollection(alterCollectionReq);
await client.alterCollectionProperties({
    collection_name: "my_collection",
    properties: {
        "mmap.enabled": true
    }
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.MmapEnabledKey, true))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful
curl -X POST "http://localhost:19530/v2/vectordb/collections/alter_properties" \
  -H "Content-Type: application/json" \
  -d '{
    "collectionName": "my_collection",
    "properties": {
      "mmap.enabled": "true"
    }
  }'

예 3: 파티션 키 활성화

다음 코드 스니펫은 파티션 키를 활성화하는 방법을 보여줍니다.

from pymilvus import MilvusClient

client.alter_collection_properties(
    collection_name="my_collection",
    properties={"partitionkey.isolation": True}
)
Map<String, String> properties = new HashMap<>();
properties.put("partitionkey.isolation", "True");

AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
        .collectionName("my_collection")
        .properties(properties)
        .build();

client.alterCollection(alterCollectionReq);
await client.alterCollectionProperties({
    collection_name: "my_collection",
    properties: {
        "partitionkey.isolation": true
    }
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.PartitionKeyIsolationKey, true))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful
curl -X POST "http://localhost:19530/v2/vectordb/collections/alter_properties" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "collectionName": "my_collection",
    "properties": {
      "partitionkey.isolation": "true"
    }
  }'

예 4: 동적 필드 활성화

다음 코드 스니펫은 동적 필드를 활성화하는 방법을 보여줍니다.

from pymilvus import MilvusClient

client.alter_collection_properties(
    collection_name="my_collection",
    properties={"dynamicfield.enabled": True}
)
Map<String, String> properties = new HashMap<>();
properties.put("dynamicfield.enabled", "True");

AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
        .collectionName("my_collection")
        .properties(properties)
        .build();

client.alterCollection(alterCollectionReq);
await client.alterCollectionProperties({
    collection_name: "my_collection",
    properties: {
        "dynamicfield.enabled": true
    }
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.EnableDynamicSchemaKey, true))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful
curl -X POST "http://localhost:19530/v2/vectordb/collections/alter_properties" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "collectionName": "my_collection",
    "properties": {
      "dynamicfield.enabled": "true"
    }
  }'

예 5: allow_insert_auto_id 활성화

allow_insert_auto_id 속성을 사용하면 AutoID가 활성화된 컬렉션에서 삽입, 업서트 및 일괄 가져오기 중에 사용자가 제공한 기본 키 값을 허용할 수 있습니다. "true"로 설정하면 Milvus는 사용자가 제공한 기본 키 값이 있는 경우 해당 값을 사용하고, 그렇지 않으면 자동 생성합니다. 기본값은 "false"입니다.

아래 예는 allow_insert_auto_id 을 활성화하는 방법을 보여줍니다:

client.alter_collection_properties(
    collection_name="my_collection",
    properties={"allow_insert_auto_id": "true"}
)
# After enabling, inserts with a PK column will use that PK; otherwise Milvus auto-generates.
Map<String, String> properties = new HashMap<>();
properties.put("allow_insert_auto_id", "True");

AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
        .collectionName("my_collection")
        .properties(properties)
        .build();

client.alterCollection(alterCollectionReq);
await client.alterCollectionProperties({
    collection_name: "my_collection",
    properties: {
        "allow_insert_auto_id": true
    }
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.AllowInsertAutoIDKey, true))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful
curl -X POST "http://localhost:19530/v2/vectordb/collections/alter_properties" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "collectionName": "my_collection",
    "properties": {
      "allow_insert_auto_id": "true"
    }
  }'

예 6: 수집 시간대 설정

timezone 속성을 사용하여 컬렉션의 기본 시간대를 설정할 수 있습니다. 이는 데이터 삽입, 쿼리, 결과 표시 등 컬렉션 내의 모든 작업에서 시간 관련 데이터가 해석되고 표시되는 방식을 결정합니다.

timezone 값은 Asia/Shanghai, America/Chicago 또는 UTC 과 같은 유효한 IANA 표준 시간대 식별자이어야 합니다. 유효하지 않거나 비표준 값을 사용하면 컬렉션 속성을 수정할 때 오류가 발생합니다.

아래 예는 수집 시간대를 아시아/상하이로 설정하는 방법을 보여줍니다:

client.alter_collection_properties(
    collection_name="my_collection",
    properties={"timezone": "Asia/Shanghai"}
)
Map<String, String> properties = new HashMap<>();
properties.put("timezone", "Asia/Shanghai");

AlterCollectionReq alterCollectionReq = AlterCollectionReq.builder()
        .collectionName("my_collection")
        .properties(properties)
        .build();

client.alterCollection(alterCollectionReq);
// js
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.CollectionDefaultTimezone, true))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful
curl -X POST "http://localhost:19530/v2/vectordb/collections/alter_properties" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "collectionName": "my_collection",
    "properties": {
      "timezone": "Asia/Shanghai"
    }
  }'

컬렉션 속성 삭제

컬렉션 속성을 다음과 같이 삭제하여 재설정할 수도 있습니다.

client.drop_collection_properties(
    collection_name="my_collection",
    property_keys=[
        "collection.ttl.seconds"
    ]
)
client.dropCollectionProperties(DropCollectionPropertiesReq.builder()
        .collectionName("my_collection")
        .propertyKeys(Collections.singletonList("collection.ttl.seconds"))
        .build());
client.dropCollectionProperties({
    collection_name:"my_collection",
    properties: ['collection.ttl.seconds'],
});
err = client.DropCollectionProperties(ctx, milvusclient.NewDropCollectionPropertiesOption("my_collection", common.CollectionTTLConfigKey))
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/drop_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
    "collectionName": "my_collection",
    "propertyKeys": [
        "collection.ttl.seconds"
    ]
}'