milvus-logo

Check Collection Information

This topic describes how to check the information of the collection in Milvus.

Check if a collection exists

Verify if a collection exists in Milvus.

from pymilvus import utility
utility.has_collection("book")
await milvusClient.collectionManager.hasCollection({
  collection_name: "book",
});
hasColl, err := milvusClient.HasCollection(
  context.Background(), // ctx
  collectionName,       // CollectionName
)
if err != nil {
  log.Fatal("failed to check whether collection exists:", err.Error())
}
log.Println(hasColl)
R<Boolean> respHasCollection = milvusClient.hasCollection(
  HasCollectionParam.newBuilder()
    .withCollectionName("book")
    .build()
);
if (respHasCollection.getData() == Boolean.TRUE) {
  System.out.println("Collection exists.");
}
describe collection -c book
curl -X 'GET' \
  'http://localhost:9091/api/v1/collection/existence' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "collection_name": "book"
  }'
Output:
{
  "status":{},
  "value":true
}
Parameter Description
collection_name Name of the collection to check.
Parameter Description
collection_name Name of the collection to check.
Parameter Description
ctx Context to control API invocation process.
CollectionName Name of the collection to check.
Parameter Description
CollectionName Name of the collection to check.
Option Description
-c Name of the collection to check.
Parameter Description
collection_name Name of the collection to check.

Check collection details

Check the details of a collection.

from pymilvus import Collection
collection = Collection("book")  # Get an existing collection.

collection.schema                # Return the schema.CollectionSchema of the collection.
collection.description           # Return the description of the collection.
collection.name                  # Return the name of the collection.
collection.is_empty              # Return the boolean value that indicates if the collection is empty.
collection.num_entities          # Return the number of entities in the collection.
collection.primary_field         # Return the schema.FieldSchema of the primary key field.
collection.partitions            # Return the list[Partition] object.
collection.indexes               # Return the list[Index] object.
await milvusClient.collectionManager.describeCollection({          // Return the name and schema of the collection.
  collection_name: "book",
});

await milvusClient.collectionManager.getCollectionStatistics({     // Return the statistics information of the collection.
  collection_name: "book",
});
collDesc, err := milvusClient.DescribeCollection(               // Return the name and schema of the collection.
  context.Background(),   // ctx
  "book",                 // CollectionName
)
if err != nil {
  log.Fatal("failed to check collection schema:", err.Error())
}
log.Printf("%v\n", collDesc)

collStat, err := milvusClient.GetCollectionStatistics(          // Return the statistics information of the collection.
  context.Background(),   // ctx
  "book",                 // CollectionName
)
if err != nil {
  log.Fatal("failed to check collection statistics:", err.Error())
}
R<DescribeCollectionResponse> respDescribeCollection = milvusClient.describeCollection(
  // Return the name and schema of the collection.
  DescribeCollectionParam.newBuilder()
    .withCollectionName("book")
    .build()
);
DescCollResponseWrapper wrapperDescribeCollection = new DescCollResponseWrapper(respDescribeCollection.getData());
System.out.println(wrapperDescribeCollection);

R<GetCollectionStatisticsResponse> respCollectionStatistics = milvusClient.getCollectionStatistics(
  // Return the statistics information of the collection.
  GetCollectionStatisticsParam.newBuilder()
    .withCollectionName("book")
    .build()
  );
GetCollStatResponseWrapper wrapperCollectionStatistics = new GetCollStatResponseWrapper(respCollectionStatistics.getData());
System.out.println("Collection row count: " + wrapperCollectionStatistics.getRowCount());
describe collection -c book
curl -X 'GET' \
  'http://localhost:9091/api/v1/collection' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "collection_name": "book"
  }'
Output:
{
  "status": {},
  "schema": {
    "name": "book",
    "description": "Test book search",
    "fields": [
      {
        "fieldID": 100,
        "name": "book_id",
        "is_primary_key": true,
        "description": "book id",
        "data_type": 5
      },
      {
        "fieldID": 101,
        "name": "book_intro",
        "description": "embedded vector of book introduction",
        "data_type": 101,
        "type_params": [
          {
            "key": "dim",
            "value": "2"
          }
        ]
      }
    ]
  },
  "collectionID": 434240188610972993,
  "virtual_channel_names": [
    "by-dev-rootcoord-dml_0_434240188610972993v0",
    "by-dev-rootcoord-dml_1_434240188610972993v1"
  ],
  "physical_channel_names": [
    "by-dev-rootcoord-dml_0",
    "by-dev-rootcoord-dml_1"
  ],
  "created_timestamp": 434240188610772994,
  "created_utc_timestamp": 1656494860118,
  "shards_num": 2,
  "consistency_level": 1
}
Parameter Description
schema The schema of the collection.
description The description of the collection.
name The name of the collection.
is_empty A boolean value that indicates whether the collection is empty.
num_entities The number of entities in the collection.
primary_field The primary field of the collection.
Parameter Description
collection_name Name of the collection to check.
Parameter Description
ctx Context to control API invocation process.
CollectionName Name of the collection to check.
Parameter Description
CollectionName Name of the collection to check.
Option Description
-c Name of the collection to check.
Parameter Description
collection_name Name of the collection to check.

List all collections

List all collections in this Milvus Instance.

from pymilvus import utility
utility.list_collections()
await milvusClient.collectionManager.showCollections();
listColl, err := milvusClient.ListCollections(
  context.Background(),   // ctx
)
if err != nil {
  log.Fatal("failed to list all collections:", err.Error())
}
log.Println(listColl)
R<ShowCollectionsResponse> respShowCollections = milvusClient.showCollections(
    ShowCollectionsParam.newBuilder().build()
  );
System.out.println(respShowCollections);
list collections
curl -X 'GET' \
  'http://localhost:9091/api/v1/collections' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json'
Output:
{
  "status": {},
  "collection_names": [
    "book"
  ],
  "collection_ids": [
    434240188610972993
  ],
  "created_timestamps": [
    434240188610772994
  ],
  "created_utc_timestamps": [
    1656494860118
  ]
}
Parameter Description
ctx Context to control API invocation process.

What's next

Is this page helpful?
On this page