github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/test/base/milvus_client.go (about)

     1  package base
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  	"time"
     8  
     9  	"github.com/milvus-io/milvus-sdk-go/v2/client"
    10  	"github.com/milvus-io/milvus-sdk-go/v2/entity"
    11  )
    12  
    13  func preRequest(funcName string, args ...interface{}) {
    14  	log.Printf("(ApiRequest): func [%s], args: %v\n", funcName, args)
    15  }
    16  
    17  func postResponse(funcName string, err error, res ...interface{}) {
    18  	if err != nil {
    19  		log.Printf("(ApiResponse): func [%s], error: %s\n", funcName, err)
    20  	} else {
    21  		log.Printf("(ApiResponse): func [%s], results: %v\n", funcName, res)
    22  	}
    23  }
    24  
    25  type MilvusClient struct {
    26  	mClient client.Client
    27  }
    28  
    29  func NewMilvusClient(ctx context.Context, cfg client.Config) (*MilvusClient, error) {
    30  	preRequest("NewClient", ctx, cfg)
    31  	mClient, err := client.NewClient(ctx, cfg)
    32  	postResponse("NewClient", err, mClient)
    33  	return &MilvusClient{
    34  		mClient,
    35  	}, err
    36  }
    37  
    38  // !!!Deprecated in future, use `NewMilvusClient` first.
    39  func NewDefaultMilvusClient(ctx context.Context, addr string) (*MilvusClient, error) {
    40  	preRequest("NewDefaultGrpcClient", ctx, addr)
    41  	mClient, err := client.NewDefaultGrpcClient(ctx, addr)
    42  	postResponse("NewDefaultGrpcClient", err, mClient)
    43  	return &MilvusClient{
    44  		mClient,
    45  	}, err
    46  }
    47  
    48  func NewDefaultMilvusClientWithURI(ctx context.Context, uri, username, password string) (*MilvusClient, error) {
    49  	preRequest("NewDefaultGrpcClientWithURI", ctx, uri, username)
    50  	mClient, err := client.NewDefaultGrpcClientWithURI(ctx, uri, username, password)
    51  	postResponse("NewDefaultGrpcClientWithURI", err, mClient)
    52  	return &MilvusClient{
    53  		mClient,
    54  	}, err
    55  }
    56  
    57  func NewDefaultMilvusClientWithTLSAuth(ctx context.Context, addr, username, password string) (*MilvusClient, error) {
    58  	preRequest("NewDefaultGrpcClientWithTLSAuth", ctx, addr, username)
    59  	mClient, err := client.NewDefaultGrpcClientWithTLSAuth(ctx, addr, username, password)
    60  	postResponse("NewDefaultGrpcClientWithTLSAuth", err, mClient)
    61  	return &MilvusClient{
    62  		mClient,
    63  	}, err
    64  }
    65  
    66  func NewDefaultMilvusClientWithAuth(ctx context.Context, addr, username, password string) (*MilvusClient, error) {
    67  	preRequest("NewDefaultGrpcClientWithAuth", ctx, addr, username)
    68  	mClient, err := client.NewDefaultGrpcClientWithAuth(ctx, addr, username, password)
    69  	postResponse("NewDefaultGrpcClientWithAuth", err, mClient)
    70  	return &MilvusClient{
    71  		mClient,
    72  	}, err
    73  }
    74  
    75  func (mc *MilvusClient) Close() error {
    76  	preRequest("Close")
    77  	err := mc.mClient.Close()
    78  	postResponse("Close", err)
    79  	return err
    80  }
    81  
    82  // -- database --
    83  
    84  // UsingDatabase for database operation after this function call.
    85  // All request in any goroutine will be applied to new database on the same client. e.g.
    86  // 1. goroutine A access DB1.
    87  // 2. goroutine B call UsingDatabase(ctx, "DB2").
    88  // 3. goroutine A access DB2 after 2.
    89  func (mc *MilvusClient) UsingDatabase(ctx context.Context, dbName string) error {
    90  	preRequest("UsingDatabase", ctx, dbName)
    91  	err := mc.mClient.UsingDatabase(ctx, dbName)
    92  	postResponse("UsingDatabase", err)
    93  	return err
    94  }
    95  
    96  // -- database --
    97  
    98  // ListDatabases list all database in milvus cluster.
    99  func (mc *MilvusClient) ListDatabases(ctx context.Context) ([]entity.Database, error) {
   100  	preRequest("ListDatabases", ctx)
   101  	dbs, err := mc.mClient.ListDatabases(ctx)
   102  	postResponse("ListDatabases", err, dbs)
   103  	return dbs, err
   104  }
   105  
   106  // CreateDatabase create database with the given name.
   107  func (mc *MilvusClient) CreateDatabase(ctx context.Context, dbName string) error {
   108  	preRequest("CreateDatabase", ctx, dbName)
   109  	err := mc.mClient.CreateDatabase(ctx, dbName)
   110  	postResponse("CreateDatabase", err)
   111  	return err
   112  }
   113  
   114  // DropDatabase drop database with the given db name.
   115  func (mc *MilvusClient) DropDatabase(ctx context.Context, dbName string) error {
   116  	preRequest("DropDatabase", ctx, dbName)
   117  	err := mc.mClient.DropDatabase(ctx, dbName)
   118  	postResponse("DropDatabase", err)
   119  	return err
   120  }
   121  
   122  func (mc *MilvusClient) AlterDatabase(ctx context.Context, dbName string, dbAttrs ...entity.DatabaseAttribute) error {
   123  	preRequest("AlterDatabase", ctx, dbName)
   124  	err := mc.mClient.AlterDatabase(ctx, dbName, dbAttrs...)
   125  	postResponse("AlterDatabase", err)
   126  	return err
   127  }
   128  
   129  func (mc *MilvusClient) DescribeDatabase(ctx context.Context, dbName string) (*entity.Database, error) {
   130  	preRequest("DescribeDatabase", ctx, dbName)
   131  	db, err := mc.mClient.DescribeDatabase(ctx, dbName)
   132  	postResponse("DescribeDatabase", err, db)
   133  	return db, err
   134  }
   135  
   136  // -- collection --
   137  
   138  // CreateCollection Create Collection
   139  func (mc *MilvusClient) CreateCollection(ctx context.Context, collSchema *entity.Schema, shardsNum int32, opts ...client.CreateCollectionOption) error {
   140  	if collSchema == nil {
   141  		preRequest("CreateCollection", ctx, collSchema, shardsNum, opts)
   142  	} else {
   143  		preRequest("CreateCollection", ctx, collSchema.CollectionName, collSchema, shardsNum, opts)
   144  	}
   145  	err := mc.mClient.CreateCollection(ctx, collSchema, shardsNum, opts...)
   146  	postResponse("CreateCollection", err)
   147  	return err
   148  }
   149  
   150  // NewCollection highlevel new Collection
   151  func (mc *MilvusClient) NewCollection(ctx context.Context, collName string, dim int64, opts ...client.CreateCollectionOption) error {
   152  	preRequest("NewCollection", ctx, collName, dim, opts)
   153  	err := mc.mClient.NewCollection(ctx, collName, dim, opts...)
   154  	postResponse("NewCollection", err)
   155  	return err
   156  }
   157  
   158  // ListCollections list collections
   159  func (mc *MilvusClient) ListCollections(ctx context.Context) ([]*entity.Collection, error) {
   160  	preRequest("ListCollections", ctx)
   161  	collections, err := mc.mClient.ListCollections(ctx)
   162  	postResponse("ListCollections", err, collections)
   163  	return collections, err
   164  }
   165  
   166  // DescribeCollection Describe collection
   167  func (mc *MilvusClient) DescribeCollection(ctx context.Context, collName string) (*entity.Collection, error) {
   168  	preRequest("DescribeCollection", ctx, collName)
   169  	collection, err := mc.mClient.DescribeCollection(ctx, collName)
   170  	postResponse("DescribeCollection", err, collection)
   171  	return collection, err
   172  }
   173  
   174  // DropCollection Drop Collection
   175  func (mc *MilvusClient) DropCollection(ctx context.Context, collName string) error {
   176  	preRequest("DropCollection", ctx, collName)
   177  	err := mc.mClient.DropCollection(ctx, collName)
   178  	postResponse("DropCollection", err)
   179  	return err
   180  }
   181  
   182  // GetCollectionStatistics Get Collection Statistics
   183  func (mc *MilvusClient) GetCollectionStatistics(ctx context.Context, collName string) (map[string]string, error) {
   184  	preRequest("GetCollectionStatistics", ctx, collName)
   185  	stats, err := mc.mClient.GetCollectionStatistics(ctx, collName)
   186  	postResponse("GetCollectionStatistics", err, stats)
   187  	return stats, err
   188  }
   189  
   190  // LoadCollection Load Collection
   191  func (mc *MilvusClient) LoadCollection(ctx context.Context, collName string, async bool, opts ...client.LoadCollectionOption) error {
   192  	funcName := "LoadCollection"
   193  	preRequest(funcName, ctx, collName, opts)
   194  	err := mc.mClient.LoadCollection(ctx, collName, async, opts...)
   195  	postResponse(funcName, err)
   196  	return err
   197  }
   198  
   199  // ReleaseCollection Release Collection
   200  func (mc *MilvusClient) ReleaseCollection(ctx context.Context, collName string) error {
   201  	preRequest("ReleaseCollection", ctx, collName)
   202  	err := mc.mClient.ReleaseCollection(ctx, collName)
   203  	postResponse("ReleaseCollection", err)
   204  	return err
   205  }
   206  
   207  // HasCollection Has Collection
   208  func (mc *MilvusClient) HasCollection(ctx context.Context, collName string) (bool, error) {
   209  	preRequest("HasCollection", ctx, collName)
   210  	has, err := mc.mClient.HasCollection(ctx, collName)
   211  	postResponse("HasCollection", err, has)
   212  	return has, err
   213  }
   214  
   215  // AlterCollection changes collection attributes
   216  func (mc *MilvusClient) AlterCollection(ctx context.Context, collName string, attrs ...entity.CollectionAttribute) error {
   217  	preRequest("AlterCollection", ctx, collName)
   218  	err := mc.mClient.AlterCollection(ctx, collName, attrs...)
   219  	postResponse("AlterCollection", err)
   220  	return err
   221  }
   222  
   223  // -- alias --
   224  
   225  // CreateAlias Create Alias
   226  func (mc *MilvusClient) CreateAlias(ctx context.Context, collName string, alias string) error {
   227  	preRequest("CreateAlias", ctx, collName, alias)
   228  	err := mc.mClient.CreateAlias(ctx, collName, alias)
   229  	postResponse("CreateAlias", err)
   230  	return err
   231  }
   232  
   233  // DropAlias drop alias
   234  func (mc *MilvusClient) DropAlias(ctx context.Context, alias string) error {
   235  	preRequest("DropAlias", ctx, alias)
   236  	err := mc.mClient.DropAlias(ctx, alias)
   237  	postResponse("DropAlias", err)
   238  	return err
   239  }
   240  
   241  // AlterAlias Alter Alias
   242  func (mc *MilvusClient) AlterAlias(ctx context.Context, collName string, alias string) error {
   243  	preRequest("AlterAlias", ctx, collName, alias)
   244  	err := mc.mClient.AlterAlias(ctx, collName, alias)
   245  	postResponse("AlterAlias", err)
   246  	return err
   247  }
   248  
   249  // GetReplicas Get Replicas
   250  func (mc *MilvusClient) GetReplicas(ctx context.Context, collName string) ([]*entity.ReplicaGroup, error) {
   251  	preRequest("GetReplicas", ctx, collName)
   252  	replicas, err := mc.mClient.GetReplicas(ctx, collName)
   253  	postResponse("GetReplicas", err, replicas)
   254  	return replicas, err
   255  }
   256  
   257  // -- authentication --
   258  
   259  // CreateCredential Create Credential
   260  func (mc *MilvusClient) CreateCredential(ctx context.Context, username string, password string) error {
   261  	preRequest("CreateCredential", ctx, username)
   262  	err := mc.mClient.CreateCredential(ctx, username, password)
   263  	postResponse("CreateCredential", err)
   264  	return err
   265  }
   266  
   267  // UpdateCredential Update Credential
   268  func (mc *MilvusClient) UpdateCredential(ctx context.Context, username string, oldPassword string, newPassword string) error {
   269  	preRequest("UpdateCredential", ctx, username)
   270  	err := mc.mClient.UpdateCredential(ctx, username, oldPassword, newPassword)
   271  	postResponse("UpdateCredential", err)
   272  	return err
   273  }
   274  
   275  // DeleteCredential delete credential
   276  func (mc *MilvusClient) DeleteCredential(ctx context.Context, username string) error {
   277  	preRequest("DeleteCredential", ctx, username)
   278  	err := mc.mClient.DeleteCredential(ctx, username)
   279  	postResponse("DeleteCredential", err)
   280  	return err
   281  }
   282  
   283  // ListCredUsers list all usernames
   284  func (mc *MilvusClient) ListCredUsers(ctx context.Context) ([]string, error) {
   285  	preRequest("ListCredUsers", ctx)
   286  	users, err := mc.mClient.ListCredUsers(ctx)
   287  	postResponse("ListCredUsers", err, users)
   288  	return users, err
   289  }
   290  
   291  // -- partition --
   292  
   293  // CreatePartition Create Partition
   294  func (mc *MilvusClient) CreatePartition(ctx context.Context, collName string, partitionName string) error {
   295  	preRequest("CreatePartition", ctx, collName, partitionName)
   296  	err := mc.mClient.CreatePartition(ctx, collName, partitionName)
   297  	postResponse("CreatePartition", err)
   298  	return err
   299  }
   300  
   301  // DropPartition Drop Partition
   302  func (mc *MilvusClient) DropPartition(ctx context.Context, collName string, partitionName string) error {
   303  	preRequest("DropPartition", ctx, collName, partitionName)
   304  	err := mc.mClient.DropPartition(ctx, collName, partitionName)
   305  	postResponse("DropPartition", err)
   306  	return err
   307  }
   308  
   309  // ShowPartitions Show Partitions
   310  func (mc *MilvusClient) ShowPartitions(ctx context.Context, collName string) ([]*entity.Partition, error) {
   311  	preRequest("ShowPartitions", ctx, collName)
   312  	partitions, err := mc.mClient.ShowPartitions(ctx, collName)
   313  	postResponse("ShowPartitions", err, partitions)
   314  	return partitions, err
   315  }
   316  
   317  // HasPartition Has Partition
   318  func (mc *MilvusClient) HasPartition(ctx context.Context, collName string, partitionName string) (bool, error) {
   319  	preRequest("HasPartition", ctx, collName)
   320  	has, err := mc.mClient.HasPartition(ctx, collName, partitionName)
   321  	postResponse("HasPartition", err, has)
   322  	return has, err
   323  }
   324  
   325  // LoadPartitions Load Partitions into memory
   326  func (mc *MilvusClient) LoadPartitions(ctx context.Context, collName string, partitionNames []string, async bool) error {
   327  	preRequest("LoadPartitions", ctx, collName, partitionNames, async)
   328  	err := mc.mClient.LoadPartitions(ctx, collName, partitionNames, async)
   329  	postResponse("LoadPartitions", err)
   330  	return err
   331  }
   332  
   333  // ReleasePartitions release partitions
   334  func (mc *MilvusClient) ReleasePartitions(ctx context.Context, collName string, partitionNames []string) error {
   335  	preRequest("ReleasePartitions", ctx, collName, partitionNames)
   336  	err := mc.mClient.ReleasePartitions(ctx, collName, partitionNames)
   337  	postResponse("ReleasePartitions", err)
   338  	return err
   339  }
   340  
   341  // GetPersistentSegmentInfo Get Persistent Segment Info
   342  func (mc *MilvusClient) GetPersistentSegmentInfo(ctx context.Context, collName string) ([]*entity.Segment, error) {
   343  	preRequest("GetPersistentSegmentInfo", ctx, collName)
   344  	segments, err := mc.mClient.GetPersistentSegmentInfo(ctx, collName)
   345  	postResponse("GetPersistentSegmentInfo", err, segments)
   346  	return segments, err
   347  }
   348  
   349  // CreateIndex Create Index
   350  func (mc *MilvusClient) CreateIndex(ctx context.Context, collName string, fieldName string, idx entity.Index, async bool, opts ...client.IndexOption) error {
   351  	preRequest("CreateIndex", ctx, collName, fieldName, async, idx, opts)
   352  	err := mc.mClient.CreateIndex(ctx, collName, fieldName, idx, async, opts...)
   353  	postResponse("CreateIndex", err)
   354  	return err
   355  }
   356  
   357  // DescribeIndex Describe Index
   358  func (mc *MilvusClient) DescribeIndex(ctx context.Context, collectionName string, fieldName string, opts ...client.IndexOption) ([]entity.Index, error) {
   359  	preRequest("DescribeIndex", ctx, collectionName, fieldName, opts)
   360  	indexes, err := mc.mClient.DescribeIndex(ctx, collectionName, fieldName, opts...)
   361  	postResponse("DescribeIndex", err, indexes)
   362  	return indexes, err
   363  }
   364  
   365  // DropIndex Drop Index
   366  func (mc *MilvusClient) DropIndex(ctx context.Context, collName string, fieldName string, opts ...client.IndexOption) error {
   367  	preRequest("DropIndex", ctx, collName, fieldName, opts)
   368  	err := mc.mClient.DropIndex(ctx, collName, fieldName, opts...)
   369  	postResponse("DropIndex", err)
   370  	return err
   371  }
   372  
   373  // GetIndexState Get IndexState, index naming is not supported yet
   374  func (mc *MilvusClient) GetIndexState(ctx context.Context, collName string, fieldName string, opts ...client.IndexOption) (entity.IndexState, error) {
   375  	preRequest("GetIndexState", ctx, collName, fieldName, opts)
   376  	indexState, err := mc.mClient.GetIndexState(ctx, collName, fieldName, opts...)
   377  	postResponse("GetIndexState", err, indexState)
   378  	return indexState, err
   379  }
   380  
   381  // AlterIndex modifies the index params.
   382  func (mc *MilvusClient) AlterIndex(ctx context.Context, collName string, indexName string, opts ...client.IndexOption) error {
   383  	preRequest("AlterIndex", ctx, collName, indexName, opts)
   384  	err := mc.mClient.AlterIndex(ctx, collName, indexName, opts...)
   385  	postResponse("AlterIndex", err)
   386  	return err
   387  }
   388  
   389  // -- basic operation --
   390  
   391  // Insert insert data
   392  func (mc *MilvusClient) Insert(ctx context.Context, collName string, partitionName string, columns ...entity.Column) (entity.Column, error) {
   393  	preRequest("Insert", ctx, collName, partitionName, columns)
   394  	ids, err := mc.mClient.Insert(ctx, collName, partitionName, columns...)
   395  	postResponse("Insert", err, ids)
   396  	return ids, err
   397  }
   398  
   399  // Flush flush collection
   400  func (mc *MilvusClient) Flush(ctx context.Context, collName string, async bool) error {
   401  	preRequest("Flush", ctx, collName, async)
   402  	err := mc.mClient.Flush(ctx, collName, async)
   403  	postResponse("Flush", err)
   404  	return err
   405  }
   406  
   407  // DeleteByPks deletes entries related to provided primary keys
   408  func (mc *MilvusClient) DeleteByPks(ctx context.Context, collName string, partitionName string, ids entity.Column) error {
   409  	preRequest("DeleteByPks", ctx, collName, partitionName, ids)
   410  	err := mc.mClient.DeleteByPks(ctx, collName, partitionName, ids)
   411  	postResponse("DeleteByPks", err)
   412  	return err
   413  }
   414  
   415  // Delete deletes entries match expression
   416  func (mc *MilvusClient) Delete(ctx context.Context, collName string, partitionName string, expr string) error {
   417  	preRequest("Delete", ctx, collName, partitionName, expr)
   418  	err := mc.mClient.Delete(ctx, collName, partitionName, expr)
   419  	postResponse("Delete", err)
   420  	return err
   421  }
   422  
   423  func (mc *MilvusClient) Upsert(ctx context.Context, collName string, partitionName string, columns ...entity.Column) (entity.Column, error) {
   424  	preRequest("Upsert", ctx, collName, partitionName, columns)
   425  	ids, err := mc.mClient.Upsert(ctx, collName, partitionName, columns...)
   426  	postResponse("Upsert", err, ids)
   427  	return ids, err
   428  }
   429  
   430  // Search search from collection
   431  func (mc *MilvusClient) Search(ctx context.Context, collName string, partitions []string, expr string,
   432  	outputFields []string, vectors []entity.Vector, vectorField string, metricType entity.MetricType, topK int, sp entity.SearchParam, opts ...client.SearchQueryOptionFunc,
   433  ) ([]client.SearchResult, error) {
   434  	funcName := "Search"
   435  	preRequest(funcName, ctx, collName, partitions, expr, outputFields, fmt.Sprintf("nq=%d", len(vectors)), vectorField, metricType, topK, sp, opts)
   436  
   437  	searchResult, err := mc.mClient.Search(ctx, collName, partitions, expr, outputFields, vectors, vectorField, metricType, topK, sp, opts...)
   438  	postResponse(funcName, err, searchResult)
   439  
   440  	return searchResult, err
   441  }
   442  
   443  func (mc *MilvusClient) HybridSearch(ctx context.Context, collName string, partitions []string, limit int, outputFields []string,
   444  	reranker client.Reranker, subRequests []*client.ANNSearchRequest, opts ...client.SearchQueryOptionFunc,
   445  ) ([]client.SearchResult, error) {
   446  	funcName := "HybridSearch"
   447  	preRequest(funcName, ctx, collName, partitions, limit, outputFields, reranker, subRequests, opts)
   448  
   449  	searchResult, err := mc.mClient.HybridSearch(ctx, collName, partitions, limit, outputFields, reranker, subRequests, opts...)
   450  	postResponse(funcName, err, searchResult)
   451  
   452  	return searchResult, err
   453  }
   454  
   455  // QueryByPks query from collection
   456  func (mc *MilvusClient) QueryByPks(ctx context.Context, collName string, partitions []string, ids entity.Column,
   457  	outputFields []string, opts ...client.SearchQueryOptionFunc,
   458  ) (client.ResultSet, error) {
   459  	funcName := "QueryByPks"
   460  	preRequest(funcName, ctx, collName, partitions, ids, outputFields, opts)
   461  
   462  	queryResults, err := mc.mClient.QueryByPks(ctx, collName, partitions, ids, outputFields, opts...)
   463  
   464  	postResponse(funcName, err, queryResults)
   465  	return queryResults, err
   466  }
   467  
   468  // Query query from collection
   469  func (mc *MilvusClient) Query(ctx context.Context, collName string, partitions []string, expr string, outputFields []string, opts ...client.SearchQueryOptionFunc,
   470  ) (client.ResultSet, error) {
   471  	funcName := "Query"
   472  	preRequest(funcName, ctx, collName, partitions, expr, outputFields, opts)
   473  
   474  	queryResults, err := mc.mClient.Query(ctx, collName, partitions, expr, outputFields, opts...)
   475  
   476  	postResponse(funcName, err, queryResults)
   477  	return queryResults, err
   478  }
   479  
   480  // Get query from collection
   481  func (mc *MilvusClient) Get(ctx context.Context, collName string, ids entity.Column, opts ...client.GetOption,
   482  ) (client.ResultSet, error) {
   483  	funcName := "Get"
   484  	preRequest(funcName, ctx, collName, ids, opts)
   485  	queryResults, err := mc.mClient.Get(ctx, collName, ids, opts...)
   486  	postResponse(funcName, err, queryResults)
   487  	return queryResults, err
   488  }
   489  
   490  // QueryIterator QueryIterator from collection
   491  func (mc *MilvusClient) QueryIterator(ctx context.Context, opt *client.QueryIteratorOption) (*client.QueryIterator, error) {
   492  	funcName := "QueryIterator"
   493  	preRequest(funcName, ctx, opt)
   494  	itr, err := mc.mClient.QueryIterator(ctx, opt)
   495  	postResponse(funcName, err, itr)
   496  	return itr, err
   497  }
   498  
   499  // -- row based apis --
   500  
   501  // CreateCollectionByRow Create Collection By Row
   502  func (mc *MilvusClient) CreateCollectionByRow(ctx context.Context, row entity.Row, shardNum int32) error {
   503  	preRequest("CreateCollectionByRow", ctx, row, shardNum)
   504  	err := mc.mClient.CreateCollectionByRow(ctx, row, shardNum)
   505  	postResponse("CreateCollectionByRow", err)
   506  	return err
   507  }
   508  
   509  // InsertRows InsertByRows insert by rows
   510  func (mc *MilvusClient) InsertRows(ctx context.Context, collName string, partitionName string, rows []interface{}) (entity.Column, error) {
   511  	preRequest("InsertRows", ctx, collName, partitionName, len(rows))
   512  	column, err := mc.mClient.InsertRows(ctx, collName, partitionName, rows)
   513  	postResponse("InsertRows", err, column)
   514  	return column, err
   515  }
   516  
   517  // Compact Manual Compaction
   518  func (mc *MilvusClient) Compact(ctx context.Context, collName string, toleranceDuration time.Duration) (int64, error) {
   519  	preRequest("ManualCompaction", ctx, collName, toleranceDuration)
   520  	compactionID, err := mc.mClient.ManualCompaction(ctx, collName, toleranceDuration)
   521  	postResponse("ManualCompaction", err, compactionID)
   522  	return compactionID, err
   523  }
   524  
   525  // GetCompactionState Get Compaction State
   526  func (mc *MilvusClient) GetCompactionState(ctx context.Context, id int64) (entity.CompactionState, error) {
   527  	preRequest("GetCompactionState", ctx, id)
   528  	compactionState, err := mc.mClient.GetCompactionState(ctx, id)
   529  	postResponse("GetCompactionState", err, compactionState)
   530  	return compactionState, err
   531  }
   532  
   533  // GetCompactionStateWithPlans Get Compaction State With Plans
   534  func (mc *MilvusClient) GetCompactionStateWithPlans(ctx context.Context, id int64) (entity.CompactionState, []entity.CompactionPlan, error) {
   535  	preRequest("GetCompactionStateWithPlans", ctx, id)
   536  	compactionState, compactionPlan, err := mc.mClient.GetCompactionStateWithPlans(ctx, id)
   537  	postResponse("GetCompactionStateWithPlans", err, compactionState, compactionPlan)
   538  	return compactionState, compactionPlan, err
   539  }
   540  
   541  // BulkInsert Bulk Insert import data files(json, numpy, etc.) on MinIO/S3 storage, read and parse them into sealed segments
   542  func (mc *MilvusClient) BulkInsert(ctx context.Context, collName string, partitionName string, files []string, opts ...client.BulkInsertOption) (int64, error) {
   543  	preRequest("BulkInsert", ctx, collName, partitionName, files, opts)
   544  	taskID, err := mc.mClient.BulkInsert(ctx, collName, partitionName, files, opts...)
   545  	postResponse("BulkInsert", err, taskID)
   546  	return taskID, err
   547  }
   548  
   549  // GetBulkInsertState checks import task state
   550  func (mc *MilvusClient) GetBulkInsertState(ctx context.Context, taskID int64) (*entity.BulkInsertTaskState, error) {
   551  	preRequest("GetBulkInsertState", ctx, taskID)
   552  	bulkInsertTaskState, err := mc.mClient.GetBulkInsertState(ctx, taskID)
   553  	postResponse("GetBulkInsertState", err, bulkInsertTaskState)
   554  	return bulkInsertTaskState, err
   555  }
   556  
   557  // ListBulkInsertTasks List Bulk Insert Tasks
   558  func (mc *MilvusClient) ListBulkInsertTasks(ctx context.Context, collName string, limit int64) ([]*entity.BulkInsertTaskState, error) {
   559  	preRequest("ListBulkInsertTasks", ctx, collName, limit)
   560  	bulkInsertTaskStates, err := mc.mClient.ListBulkInsertTasks(ctx, collName, limit)
   561  	postResponse("ListBulkInsertTasks", err, bulkInsertTaskStates)
   562  	return bulkInsertTaskStates, err
   563  }
   564  
   565  // GetLoadingProgress
   566  func (mc *MilvusClient) GetLoadingProgress(ctx context.Context, collName string, partitionNames []string) (int64, error) {
   567  	preRequest("GetLoadingProgress", ctx, collName, partitionNames)
   568  	loadingProgress, err := mc.mClient.GetLoadingProgress(ctx, collName, partitionNames)
   569  	postResponse("GetLoadingProgress", err, loadingProgress)
   570  	return loadingProgress, err
   571  }
   572  
   573  // GetLoadState
   574  func (mc *MilvusClient) GetLoadState(ctx context.Context, collName string, partitionNames []string) (entity.LoadState, error) {
   575  	preRequest("GetLoadState", ctx, collName, partitionNames)
   576  	loadState, err := mc.mClient.GetLoadState(ctx, collName, partitionNames)
   577  	postResponse("GetLoadState", err, loadState)
   578  	return loadState, err
   579  }
   580  
   581  // *** self-hosted
   582  func (mc *MilvusClient) WaitForCompactionCompleted(ctx context.Context, compactionID int64) error {
   583  	for {
   584  		time.Sleep(time.Millisecond * 500)
   585  		compactionState, err := mc.GetCompactionState(ctx, compactionID)
   586  		if err != nil {
   587  			return err
   588  		}
   589  		if compactionState == entity.CompactionStateCompleted {
   590  			return nil
   591  		}
   592  	}
   593  }
   594  
   595  // ListResourceGroups List Resource Groups
   596  func (mc *MilvusClient) ListResourceGroups(ctx context.Context) ([]string, error) {
   597  	preRequest("ListResourceGroups", ctx)
   598  	rgs, err := mc.mClient.ListResourceGroups(ctx)
   599  	postResponse("ListResourceGroups", err, rgs)
   600  	return rgs, err
   601  }
   602  
   603  // CreateResourceGroup
   604  func (mc *MilvusClient) CreateResourceGroup(ctx context.Context, rgName string) error {
   605  	preRequest("CreateResourceGroup", ctx, rgName)
   606  	err := mc.mClient.CreateResourceGroup(ctx, rgName)
   607  	postResponse("CreateResourceGroup", err)
   608  	return err
   609  }
   610  
   611  // DescribeResourceGroup describe resource group
   612  func (mc *MilvusClient) DescribeResourceGroup(ctx context.Context, rgName string) (*entity.ResourceGroup, error) {
   613  	preRequest("DescribeResourceGroup", ctx, rgName)
   614  	rg, err := mc.mClient.DescribeResourceGroup(ctx, rgName)
   615  	postResponse("DescribeResourceGroup", err, rg)
   616  	return rg, err
   617  }
   618  
   619  // DropResourceGroup drop resource group
   620  func (mc *MilvusClient) DropResourceGroup(ctx context.Context, rgName string) error {
   621  	preRequest("DropResourceGroup", ctx, rgName)
   622  	err := mc.mClient.DropResourceGroup(ctx, rgName)
   623  	postResponse("DropResourceGroup", err)
   624  	return err
   625  }
   626  
   627  // TransferNode transfer node
   628  func (mc *MilvusClient) TransferNode(ctx context.Context, sourceRg, targetRg string, nodesNum int32) error {
   629  	preRequest("TransferNode", ctx, sourceRg, targetRg, nodesNum)
   630  	err := mc.mClient.TransferNode(ctx, sourceRg, targetRg, nodesNum)
   631  	postResponse("TransferNode", err)
   632  	return err
   633  }
   634  
   635  // TransferReplica transfer replica
   636  func (mc *MilvusClient) TransferReplica(ctx context.Context, sourceRg, targetRg string, collectionName string, replicaNum int64) error {
   637  	preRequest("TransferReplica", ctx, sourceRg, targetRg, collectionName, replicaNum)
   638  	err := mc.mClient.TransferReplica(ctx, sourceRg, targetRg, collectionName, replicaNum)
   639  	postResponse("TransferReplica", err)
   640  	return err
   641  }