Collection Operations
Collection APIs manage schemas, collection lifecycle, load/release state, aliases, functions, compaction, external collections, and snapshots.
import { CollectionProperties, DataType, FunctionType,} from '@zilliz/milvus2-sdk-node';createCollection
Section titled “createCollection”Create a collection. MilvusClient#createCollection supports both a quick-create form and explicit schema forms.
createCollection( data: CreateColReq | CreateColWithSchemaAndIndexParamsReq | CreateCollectionReq): Promise<ResStatus>Quick-create parameters
Section titled “Quick-create parameters”collection_name: Collection name.dimension: Vector dimension.primary_field_name?: Primary key field name. Defaults toid.id_type?:DataType.Int64orDataType.VarChar.vector_field_name?: Vector field name. Defaults toembedding.metric_type?: Metric type for the default index.enable_dynamic_field?/enableDynamicField?: Enable dynamic field. Defaults totrue.auto_id?: Whether primary key auto-increments.consistency_level?: Consistency level.index_params?: Optional index params.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.createCollection({ collection_name: 'books', dimension: 768, metric_type: 'COSINE',});Explicit schema parameters
Section titled “Explicit schema parameters”collection_name: Collection name.fieldsorschema: Field schema array.shards_num?: Number of shards.description?: Collection description.consistency_level?: Consistency level.num_partitions?: Initial partition count.partition_key_field?: Partition key field.clustering_key_field?: Clustering key field.enable_dynamic_field?/enableDynamicField?: Enable dynamic field.properties?: Collection properties such as TTL or mmap settings.functions?: Collection functions such as BM25 or text embedding.external_source?,external_spec?,do_physical_backfill?,file_resource_ids?: External collection configuration.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.createCollection({ collection_name: 'books', fields: [ { name: 'id', data_type: DataType.Int64, is_primary_key: true }, { name: 'title', data_type: DataType.VarChar, max_length: 512 }, { name: 'embedding', data_type: DataType.FloatVector, dim: 768 }, ], properties: { [CollectionProperties.TTL_SECONDS]: 86_400, },});Schema mutation
Section titled “Schema mutation”Milvus 3.0 introduces collection schema alteration for adding fields and functions to existing collections. The Node SDK exposes this through the following field and function management methods.
addCollectionField
Section titled “addCollectionField”Add one field to an existing collection.
addCollectionField(data: AddCollectionFieldReq): Promise<ResStatus>Parameters:
collection_name: Collection name.field: Field schema.db_name?: Database name.timeout?: Request timeout in milliseconds.
addCollectionFields
Section titled “addCollectionFields”Add multiple fields by calling addCollectionField for each field.
addCollectionFields(data: AddCollectionFieldsReq): Promise<ResStatus>Parameters:
collection_name: Collection name.fields: Field schema array.db_name?: Database name.timeout?: Request timeout in milliseconds.
alterCollectionFieldProperties
Section titled “alterCollectionFieldProperties”Modify field properties, such as max_length or mmap.enabled.
alterCollectionFieldProperties(data: AlterCollectionFieldPropertiesReq): Promise<ResStatus>Parameters:
collection_name: Collection name.field_name: Field name.properties: Properties to set.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.alterCollectionFieldProperties({ collection_name: 'books', field_name: 'title', properties: { max_length: 1024 },});Collection inspection
Section titled “Collection inspection”hasCollection
Section titled “hasCollection”Check if a collection exists.
hasCollection(data: HasCollectionReq): Promise<BoolResponse>Response: value is true when the collection exists.
showCollections
Section titled “showCollections”List collections or loaded collections.
showCollections(data?: ShowCollectionsReq): Promise<ShowCollectionsResponse>listCollections(data?: ShowCollectionsReq): Promise<ShowCollectionsResponse> // aliaslist_collections(data?: ShowCollectionsReq): Promise<ShowCollectionsResponse> // aliasParameters:
type?:ShowCollectionsType.AllorShowCollectionsType.Loaded.collection_names?: Collection names to check when using loaded status.db_name?: Database name.timeout?: Request timeout in milliseconds.
Response:
data[]: Collection info withname,id,timestamp, andloadedPercentage.
describeCollection
Section titled “describeCollection”Describe schema and collection metadata.
describeCollection(data: DescribeCollectionReq): Promise<DescribeCollectionResponse>Parameters:
collection_name: Collection name.cache?: Return cached schema whentrue.db_name?: Database name.timeout?: Request timeout in milliseconds.
Response highlights:
schema.fields: Field schema list.schema.functions: Function schemas.collectionID,collection_name,consistency_level.aliases.properties.anns_fields,scalar_fields,function_fields: SDK-formatted field maps.
batchDescribeCollections
Section titled “batchDescribeCollections”Describe multiple collections in one request.
batchDescribeCollections(data: BatchDescribeCollectionReq): Promise<BatchDescribeCollectionResponse>Parameters:
collection_names: Collection names.collectionIDs?: Collection IDs.db_name?: Database name.timeout?: Request timeout in milliseconds.
getCollectionStatistics
Section titled “getCollectionStatistics”Get collection statistics.
getCollectionStatistics(data: GetCollectionStatisticsReq): Promise<StatisticsResponse>getCollectionStats(data: GetCollectionStatisticsReq): Promise<StatisticsResponse> // aliasResponse:
stats: Raw key-value statistics.data.row_count: Parsed row count.
Collection properties
Section titled “Collection properties”alterCollectionProperties
Section titled “alterCollectionProperties”Modify collection properties.
alterCollectionProperties(data: AlterCollectionReq): Promise<ResStatus>alterCollection(data: AlterCollectionReq): Promise<ResStatus> // deprecated aliasParameters:
collection_name: Collection name.properties: Properties to set.delete_keys?: Property keys to delete.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.alterCollectionProperties({ collection_name: 'books', properties: { [CollectionProperties.MMAP_ENABLED]: true },});dropCollectionProperties
Section titled “dropCollectionProperties”Remove collection properties.
dropCollectionProperties(data: DropCollectionPropertiesReq): Promise<ResStatus>Parameters:
collection_name: Collection name.properties: Property keys to remove.db_name?: Database name.timeout?: Request timeout in milliseconds.
Load and release
Section titled “Load and release”loadCollectionAsync
Section titled “loadCollectionAsync”Start loading a collection without waiting for completion.
loadCollectionAsync(data: LoadCollectionReq): Promise<ResStatus>loadCollection
Section titled “loadCollection”Load a collection and wait until loading progress reaches 100%.
loadCollection(data: LoadCollectionReq): Promise<ResStatus>loadCollectionSync(data: LoadCollectionReq): Promise<ResStatus> // aliasParameters:
collection_name: Collection name.replica_number?: Replica count.resource_groups?: Target resource groups.refresh?: Refresh loaded data.load_fields?: Fields to load.skip_load_dynamic_field?: Skip dynamic field loading.db_name?: Database name.timeout?: Request timeout in milliseconds.
refreshLoad
Section titled “refreshLoad”Refresh a loaded collection to pick up schema or data changes.
refreshLoad(data: RefreshLoadReq): Promise<ResStatus>releaseCollection
Section titled “releaseCollection”Release a collection from query nodes.
releaseCollection(data: ReleaseLoadCollectionReq): Promise<ResStatus>getLoadingProgress
Section titled “getLoadingProgress”Get load progress for a collection or partitions.
getLoadingProgress(data: GetLoadingProgressReq): Promise<GetLoadingProgressResponse>getLoadState
Section titled “getLoadState”Get collection or partition load state.
getLoadState(data: GetLoadStateReq): Promise<GetLoadStateResponse>Rename, truncate, and drop
Section titled “Rename, truncate, and drop”renameCollection
Section titled “renameCollection”Rename a collection and optionally move it to another database.
renameCollection(data: RenameCollectionReq): Promise<ResStatus>Parameters:
collection_name: Current collection name.new_collection_name: New collection name.new_db_name?: Target database name.db_name?: Current database name.timeout?: Request timeout in milliseconds.
truncateCollection
Section titled “truncateCollection”Delete all rows while keeping the schema.
truncateCollection(data: DropCollectionReq): Promise<{ status: ResStatus }>dropCollection
Section titled “dropCollection”Drop a collection and all its data.
dropCollection(data: DropCollectionReq): Promise<ResStatus>drop_collection(data: DropCollectionReq): Promise<ResStatus> // aliasAlias operations
Section titled “Alias operations”createAlias
Section titled “createAlias”createAlias(data: CreateAliasReq): Promise<ResStatus>Parameters: collection_name, alias, optional db_name, optional timeout.
describeAlias
Section titled “describeAlias”describeAlias(data: DescribeAliasReq): Promise<DescribeAliasResponse>listAliases
Section titled “listAliases”listAliases(data: ListAliasesReq): Promise<ListAliasesResponse>alterAlias
Section titled “alterAlias”alterAlias(data: AlterAliasReq): Promise<ResStatus>dropAlias
Section titled “dropAlias”dropAlias(data: DropAliasReq): Promise<ResStatus>Function operations
Section titled “Function operations”addCollectionFunction
Section titled “addCollectionFunction”Add a function to a collection, such as BM25, text embedding, or rerank.
addCollectionFunction(data: AddCollectionFunctionReq): Promise<ResStatus>Parameters:
collection_name: Collection name.function: Function schema.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.addCollectionFunction({ collection_name: 'books', function: { name: 'title_bm25', type: FunctionType.BM25, input_field_names: ['title'], output_field_names: ['title_sparse'], params: {}, },});alterCollectionFunction
Section titled “alterCollectionFunction”alterCollectionFunction(data: AlterCollectionFunctionReq): Promise<ResStatus>dropCollectionFunction
Section titled “dropCollectionFunction”dropCollectionFunction(data: DropCollectionFunctionReq): Promise<ResStatus>Compaction and replicas
Section titled “Compaction and replicas”compact
Section titled “compact”Trigger compaction.
compact(data: CompactReq): Promise<CompactionResponse>getCompactionState
Section titled “getCompactionState”getCompactionState(data: GetCompactionStateReq): Promise<GetCompactionStateResponse>getCompactionStateWithPlans
Section titled “getCompactionStateWithPlans”getCompactionStateWithPlans(data: GetCompactionPlansReq): Promise<GetCompactionPlansResponse>getReplicas
Section titled “getReplicas”Get collection replica information.
getReplicas(data: GetReplicaReq): Promise<ReplicasResponse>describeReplicas(data: GetReplicaReq): Promise<ReplicasResponse> // aliasPrimary key helpers
Section titled “Primary key helpers”getPkFieldName(data: DescribeCollectionReq, desc?: DescribeCollectionResponse): Promise<string>getPkFieldType(data: DescribeCollectionReq, desc?: DescribeCollectionResponse): Promise<keyof typeof DataType>getPkField(data: DescribeCollectionReq): Promise<FieldSchema>External collection refresh Milvus 3.0
Section titled “External collection refresh Milvus 3.0”refreshExternalCollection
Section titled “refreshExternalCollection”Trigger a refresh job for an external collection.
refreshExternalCollection(data: RefreshExternalCollectionReq): Promise<RefreshExternalCollectionResponse>Parameters:
collection_name: Collection name.external_source?: New external source path.external_spec?: New external spec configuration.db_name?: Database name.timeout?: Request timeout in milliseconds.
getRefreshExternalCollectionProgress
Section titled “getRefreshExternalCollectionProgress”getRefreshExternalCollectionProgress(data: GetRefreshExternalCollectionProgressReq): Promise<GetRefreshExternalCollectionProgressResponse>Parameters: job_id, optional timeout.
listRefreshExternalCollectionJobs
Section titled “listRefreshExternalCollectionJobs”listRefreshExternalCollectionJobs(data?: ListRefreshExternalCollectionJobsReq): Promise<ListRefreshExternalCollectionJobsResponse>Parameters: optional db_name, collection_name, and timeout.
Snapshots Milvus 3.0
Section titled “Snapshots Milvus 3.0”createSnapshot
Section titled “createSnapshot”createSnapshot(data: CreateSnapshotReq): Promise<ResStatus>Parameters:
collection_name: Collection name.snapshot_name: Snapshot name.description?: Snapshot description.compaction_protection_seconds?: Protection duration.db_name?: Database name.timeout?: Request timeout in milliseconds.
dropSnapshot
Section titled “dropSnapshot”dropSnapshot(data: DropSnapshotReq): Promise<ResStatus>listSnapshots
Section titled “listSnapshots”listSnapshots(data: ListSnapshotsReq): Promise<ListSnapshotsResponse>describeSnapshot
Section titled “describeSnapshot”describeSnapshot(data: DescribeSnapshotReq): Promise<DescribeSnapshotResponse>restoreSnapshot
Section titled “restoreSnapshot”Restore a snapshot into a target collection.
restoreSnapshot(data: RestoreSnapshotReq): Promise<RestoreSnapshotResponse>Parameters:
snapshot_name: Snapshot name.source_collection_name: Source collection.target_collection_name: Target collection.source_db_name?: Source database.target_db_name?: Target database.timeout?: Request timeout in milliseconds.
getRestoreSnapshotState
Section titled “getRestoreSnapshotState”getRestoreSnapshotState(data: GetRestoreSnapshotStateReq): Promise<GetRestoreSnapshotStateResponse>listRestoreSnapshotJobs
Section titled “listRestoreSnapshotJobs”listRestoreSnapshotJobs(data?: ListRestoreSnapshotJobsReq): Promise<ListRestoreSnapshotJobsResponse>pinSnapshotData
Section titled “pinSnapshotData”Pin snapshot data to protect it from garbage collection while it is copied out.
pinSnapshotData(data: PinSnapshotDataReq): Promise<PinSnapshotDataResponse>Parameters: collection_name, snapshot_name, optional ttl_seconds, db_name, and timeout.
unpinSnapshotData
Section titled “unpinSnapshotData”Release a snapshot data pin.
unpinSnapshotData(data: UnpinSnapshotDataReq): Promise<ResStatus>Parameters: pin_id, optional timeout.