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.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.");
}
var collectionExists = await Client.HasCollectionAsync("book");
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.

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.
collection.properties		# Return the expiration time of data in the collection.
await milvusClient.describeCollection({          // Return the name and schema of the collection.
  collection_name: "book",
});

await milvusClient.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());
var collection = milvusClient.GetCollection("book");
var desc = await collection.DescribeAsync();
curl -X 'GET' \
  '${MILVUS_HOST}:${MILVUS_PORT}/v1/vector/collections/describe' \
  -H 'Authorization: Bearer ${TOKEN}' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "collectionName": "book"
  }'
Output:
// Output of describeCollection
{
    "code": 200,
    "data": {
        "collectionName": "string",
        "description": "string",
        "fields": [
            {
                "autoId": true,
                "description": "string",
                "name": "string",
                "primaryKey": true,
                "type": "string"
            }
        ],
        "indexes": [
            {
                "fieldName": "string",
                "indexName": "string",
                "metricType": "string"
            }
        ],
        "load": "string",
        "shardsNum": 0,
        "enableDynamic": true
    }
}
Parameter Description
collectionName Name of the collection to check.
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.
properties Currently, only the property of collection.ttl.seconds is shown. Collection time to live (TTL) is the expiration time of data in a 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.
Parameter Description
collectionName 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.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);
var collections = await milvusClient.ListCollectionsAsync();

foreach (var collection in collections) {
    Console.WriteLine(collection.Name);
}
curl -X 'GET' \
  '${MILVUS_HOST}:${MILVUS_PORT}/v1/vector/collections' \
  -H 'Authorization: Bearer ${TOKEN}' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json'
Output:
// Output of list collections
{
   code: 200,
   data: [
         "collection1",
         "collection2",
         ...
         "collectionN",
         ]
}
Parameter Description
ctx Context to control API invocation process.

What's next

On this page