diff --git a/src/main/java/io/milvus/v2/client/ConnectConfig.java b/src/main/java/io/milvus/v2/client/ConnectConfig.java index 9c8024a79..165097915 100644 --- a/src/main/java/io/milvus/v2/client/ConnectConfig.java +++ b/src/main/java/io/milvus/v2/client/ConnectConfig.java @@ -5,8 +5,6 @@ import lombok.experimental.SuperBuilder; import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.Base64; import java.util.concurrent.TimeUnit; @Data @@ -16,7 +14,7 @@ public class ConnectConfig { private String token; private String username; private String password; - private String databaseName; + private String dbName; @Builder.Default private long connectTimeoutMs = 10000; @Builder.Default diff --git a/src/main/java/io/milvus/v2/client/MilvusClientV2.java b/src/main/java/io/milvus/v2/client/MilvusClientV2.java index b167db5b0..853ea5f71 100644 --- a/src/main/java/io/milvus/v2/client/MilvusClientV2.java +++ b/src/main/java/io/milvus/v2/client/MilvusClientV2.java @@ -2,11 +2,10 @@ import io.grpc.ManagedChannel; import io.milvus.grpc.MilvusServiceGrpc; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.service.collection.CollectionService; import io.milvus.v2.service.collection.request.*; import io.milvus.v2.service.collection.response.DescribeCollectionResp; +import io.milvus.v2.service.collection.response.GetCollectionStatsResp; import io.milvus.v2.service.collection.response.ListCollectionsResp; import io.milvus.v2.service.index.IndexService; import io.milvus.v2.service.index.request.CreateIndexReq; @@ -24,12 +23,11 @@ import io.milvus.v2.service.utility.request.AlterAliasReq; import io.milvus.v2.service.utility.request.CreateAliasReq; import io.milvus.v2.service.utility.request.DropAliasReq; -import io.milvus.v2.service.utility.request.FlushReq; +import io.milvus.v2.service.utility.response.DescribeAliasResp; +import io.milvus.v2.service.utility.response.ListAliasResp; import io.milvus.v2.service.vector.VectorService; import io.milvus.v2.service.vector.request.*; -import io.milvus.v2.service.vector.response.GetResp; -import io.milvus.v2.service.vector.response.QueryResp; -import io.milvus.v2.service.vector.response.SearchResp; +import io.milvus.v2.service.vector.response.*; import io.milvus.v2.utils.ClientUtils; import lombok.NonNull; import lombok.Setter; @@ -87,9 +85,9 @@ private void connect(ConnectConfig connectConfig){ blockingStub = MilvusServiceGrpc.newBlockingStub(channel); } - if (connectConfig.getDatabaseName() != null) { + if (connectConfig.getDbName() != null) { // check if database exists - clientUtils.checkDatabaseExist(this.blockingStub, connectConfig.getDatabaseName()); + clientUtils.checkDatabaseExist(this.blockingStub, connectConfig.getDbName()); } } @@ -101,7 +99,7 @@ public void useDatabase(@NonNull String dbName) { // check if database exists clientUtils.checkDatabaseExist(this.blockingStub, dbName); try { - this.connectConfig.setDatabaseName(dbName); + this.connectConfig.setDbName(dbName); this.close(3); this.connect(this.connectConfig); }catch (InterruptedException e){ @@ -113,20 +111,21 @@ public void useDatabase(@NonNull String dbName) { /** * Fast Creates a collection in Milvus. * - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createCollection(CreateCollectionReq request) { - return collectionService.createCollection(this.blockingStub, request); + public void createCollection(CreateCollectionReq request) { + collectionService.createCollection(this.blockingStub, request); } /** * Creates a collection with Schema in Milvus. * * @param request create collection request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createCollectionWithSchema(CreateCollectionWithSchemaReq request) { - return collectionService.createCollectionWithSchema(this.blockingStub, request); + public void createCollectionWithSchema(CreateCollectionWithSchemaReq request) { + collectionService.createCollectionWithSchema(this.blockingStub, request); + } + public CreateCollectionWithSchemaReq.CollectionSchema createSchema(Boolean enableDynamicField, String description) { + return collectionService.createSchema(enableDynamicField, description); } /** @@ -134,7 +133,7 @@ public R createCollectionWithSchema(CreateCollectionWithSchemaReq req * * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R listCollections(){ + public ListCollectionsResp listCollections() { return collectionService.listCollections(this.blockingStub); } @@ -142,10 +141,9 @@ public R listCollections(){ * Drops a collection in Milvus. * * @param request drop collection request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R dropCollection(DropCollectionReq request){ - return collectionService.dropCollection(this.blockingStub, request); + public void dropCollection(DropCollectionReq request) { + collectionService.dropCollection(this.blockingStub, request); } /** * Checks whether a collection exists in Milvus. @@ -153,7 +151,7 @@ public R dropCollection(DropCollectionReq request){ * @param request has collection request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R hasCollection(HasCollectionReq request){ + public Boolean hasCollection(HasCollectionReq request) { return collectionService.hasCollection(this.blockingStub, request); } /** @@ -162,7 +160,7 @@ public R hasCollection(HasCollectionReq request){ * @param request describe collection request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R describeCollection(DescribeCollectionReq request){ + public DescribeCollectionResp describeCollection(DescribeCollectionReq request) { return collectionService.describeCollection(this.blockingStub, request); } /** @@ -171,35 +169,32 @@ public R describeCollection(DescribeCollectionReq reques * @param request get collection stats request * @return {status:result code, data:RpcStatus{msg: result message}} */ -// public R getCollectionStats(GetCollectionStatsReq request){ -// return collectionService.getCollectionStats(this.blockingStub, request); -// } + public GetCollectionStatsResp getCollectionStats(GetCollectionStatsReq request) { + return collectionService.getCollectionStats(this.blockingStub, request); + } /** * rename collection in a collection in Milvus. * * @param request rename collection request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R renameCollection(RenameCollectionReq request){ - return collectionService.renameCollection(this.blockingStub, request); + public void renameCollection(RenameCollectionReq request) { + collectionService.renameCollection(this.blockingStub, request); } /** * Loads a collection into memory in Milvus. * * @param request load collection request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R loadCollection(LoadCollectionReq request){ - return collectionService.loadCollection(this.blockingStub, request); + public void loadCollection(LoadCollectionReq request) { + collectionService.loadCollection(this.blockingStub, request); } /** * Releases a collection from memory in Milvus. * * @param request release collection request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R releaseCollection(ReleaseCollectionReq request){ - return collectionService.releaseCollection(this.blockingStub, request); + public void releaseCollection(ReleaseCollectionReq request) { + collectionService.releaseCollection(this.blockingStub, request); } /** * Checks whether a collection is loaded in Milvus. @@ -207,7 +202,7 @@ public R releaseCollection(ReleaseCollectionReq request){ * @param request get load state request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R getLoadState(GetLoadStateReq request){ + public Boolean getLoadState(GetLoadStateReq request) { return collectionService.getLoadState(this.blockingStub, request); } @@ -216,19 +211,17 @@ public R getLoadState(GetLoadStateReq request){ * Creates an index for a specified field in a collection in Milvus. * * @param request create index request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createIndex(CreateIndexReq request){ - return indexService.createIndex(this.blockingStub, request); + public void createIndex(CreateIndexReq request) { + indexService.createIndex(this.blockingStub, request); } /** * Drops an index for a specified field in a collection in Milvus. * * @param request drop index request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R dropIndex(DropIndexReq request){ - return indexService.dropIndex(this.blockingStub, request); + public void dropIndex(DropIndexReq request) { + indexService.dropIndex(this.blockingStub, request); } /** * Checks whether an index exists for a specified field in a collection in Milvus. @@ -236,7 +229,7 @@ public R dropIndex(DropIndexReq request){ * @param request describe index request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R describeIndex(DescribeIndexReq request){ + public DescribeIndexResp describeIndex(DescribeIndexReq request) { return indexService.describeIndex(this.blockingStub, request); } @@ -248,7 +241,7 @@ public R describeIndex(DescribeIndexReq request){ * @param request insert request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R insert(InsertReq request){ + public InsertResp insert(InsertReq request) { return vectorService.insert(this.blockingStub, request); } /** @@ -257,7 +250,7 @@ public R insert(InsertReq request){ * @param request upsert request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R upsert(UpsertReq request){ + public UpsertResp upsert(UpsertReq request) { return vectorService.upsert(this.blockingStub, request); } /** @@ -266,7 +259,7 @@ public R upsert(UpsertReq request){ * @param request delete request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R delete(DeleteReq request){ + public DeleteResp delete(DeleteReq request) { return vectorService.delete(this.blockingStub, request); } /** @@ -275,7 +268,7 @@ public R delete(DeleteReq request){ * @param request get request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R get(GetReq request){ + public GetResp get(GetReq request) { return vectorService.get(this.blockingStub, request); } @@ -285,7 +278,7 @@ public R get(GetReq request){ * @param request query request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R query(QueryReq request){ + public QueryResp query(QueryReq request) { return vectorService.query(this.blockingStub, request); } /** @@ -294,7 +287,7 @@ public R query(QueryReq request){ * @param request search request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R search(SearchReq request){ + public SearchResp search(SearchReq request) { return vectorService.search(this.blockingStub, request); } @@ -303,20 +296,18 @@ public R search(SearchReq request){ * Creates a partition in a collection in Milvus. * * @param request create partition request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createPartition(CreatePartitionReq request) { - return partitionService.createPartition(this.blockingStub, request); + public void createPartition(CreatePartitionReq request) { + partitionService.createPartition(this.blockingStub, request); } /** * Drops a partition in a collection in Milvus. * * @param request drop partition request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R dropPartition(DropPartitionReq request) { - return partitionService.dropPartition(this.blockingStub, request); + public void dropPartition(DropPartitionReq request) { + partitionService.dropPartition(this.blockingStub, request); } /** @@ -325,7 +316,7 @@ public R dropPartition(DropPartitionReq request) { * @param request has partition request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R hasPartition(HasPartitionReq request) { + public Boolean hasPartition(HasPartitionReq request) { return partitionService.hasPartition(this.blockingStub, request); } @@ -335,7 +326,7 @@ public R hasPartition(HasPartitionReq request) { * @param request list partitions request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R> listPartitions(ListPartitionsReq request) { + public List listPartitions(ListPartitionsReq request) { return partitionService.listPartitions(this.blockingStub, request); } @@ -343,19 +334,17 @@ public R> listPartitions(ListPartitionsReq request) { * Loads partitions in a collection in Milvus. * * @param request load partitions request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R loadPartitions(LoadPartitionsReq request) { - return partitionService.loadPartitions(this.blockingStub, request); + public void loadPartitions(LoadPartitionsReq request) { + partitionService.loadPartitions(this.blockingStub, request); } /** * Releases partitions in a collection in Milvus. * * @param request release partitions request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R releasePartitions(ReleasePartitionsReq request) { - return partitionService.releasePartitions(this.blockingStub, request); + public void releasePartitions(ReleasePartitionsReq request) { + partitionService.releasePartitions(this.blockingStub, request); } // rbac operations // user operations @@ -364,7 +353,7 @@ public R releasePartitions(ReleasePartitionsReq request) { * * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R> listUsers(){ + public List listUsers() { return userService.listUsers(this.blockingStub); } /** @@ -373,35 +362,32 @@ public R> listUsers(){ * @param request describe user request * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R describeUser(DescribeUserReq request){ + public DescribeUserResp describeUser(DescribeUserReq request) { return userService.describeUser(this.blockingStub, request); } /** * create user * * @param request create user request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createUser(CreateUserReq request){ - return userService.createUser(this.blockingStub, request); + public void createUser(CreateUserReq request) { + userService.createUser(this.blockingStub, request); } /** * change password * * @param request change password request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R updatePassword(UpdatePasswordReq request) { - return userService.updatePassword(this.blockingStub, request); + public void updatePassword(UpdatePasswordReq request) { + userService.updatePassword(this.blockingStub, request); } /** * drop user * * @param request drop user request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R dropUser(DropUserReq request){ - return userService.dropUser(this.blockingStub, request); + public void dropUser(DropUserReq request) { + userService.dropUser(this.blockingStub, request); } // role operations /** @@ -409,7 +395,7 @@ public R dropUser(DropUserReq request){ * * @return {status:result code, data:List{msg: result message}} */ - public R> listRoles() { + public List listRoles() { return roleService.listRoles(this.blockingStub); } /** @@ -418,95 +404,95 @@ public R> listRoles() { * @param request describe role request * @return {status:result code, data:DescribeRoleResp{msg: result message}} */ - public R describeRole(DescribeRoleReq request) { + public DescribeRoleResp describeRole(DescribeRoleReq request) { return roleService.describeRole(this.blockingStub, request); } /** * create role * * @param request create role request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createRole(CreateRoleReq request) { - return roleService.createRole(this.blockingStub, request); + public void createRole(CreateRoleReq request) { + roleService.createRole(this.blockingStub, request); } /** * drop role * * @param request drop role request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R dropRole(DropRoleReq request) { - return roleService.dropRole(this.blockingStub, request); + public void dropRole(DropRoleReq request) { + roleService.dropRole(this.blockingStub, request); } /** * grant privilege * * @param request grant privilege request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R grantPrivilege(GrantPrivilegeReq request) { - return roleService.grantPrivilege(this.blockingStub, request); + public void grantPrivilege(GrantPrivilegeReq request) { + roleService.grantPrivilege(this.blockingStub, request); } /** * revoke privilege * * @param request revoke privilege request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R revokePrivilege(RevokePrivilegeReq request) { - return roleService.revokePrivilege(this.blockingStub, request); + public void revokePrivilege(RevokePrivilegeReq request) { + roleService.revokePrivilege(this.blockingStub, request); } /** * grant role * * @param request grant role request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R grantRole(GrantRoleReq request) { - return roleService.grantRole(this.blockingStub, request); + public void grantRole(GrantRoleReq request) { + roleService.grantRole(this.blockingStub, request); } /** * revoke role * * @param request revoke role request - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R revokeRole(RevokeRoleReq request) { - return roleService.revokeRole(this.blockingStub, request); + public void revokeRole(RevokeRoleReq request) { + roleService.revokeRole(this.blockingStub, request); } // Utility Operations /** * create aliases - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R createAlias(CreateAliasReq request) { - return utilityService.createAlias(this.blockingStub, request); + public void createAlias(CreateAliasReq request) { + utilityService.createAlias(this.blockingStub, request); } /** * drop aliases - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R dropAlias(DropAliasReq request) { - return utilityService.dropAlias(this.blockingStub, request); + public void dropAlias(DropAliasReq request) { + utilityService.dropAlias(this.blockingStub, request); } /** * alter aliases - * @return {status:result code, data:RpcStatus{msg: result message}} */ - public R alterAlias(AlterAliasReq request) { - return utilityService.alterAlias(this.blockingStub, request); + public void alterAlias(AlterAliasReq request) { + utilityService.alterAlias(this.blockingStub, request); } /** - * flush collection - * @param request flush request - * @return {status:result code, data:RpcStatus{msg: result message}} + * list aliases + * + * @return {status:result code, data:List{msg: result message}} + */ + public ListAliasResp listAliases() { + return utilityService.listAliases(this.blockingStub); + } + /** + * describe aliases + * + * @return {status:result code, data:DescribeAliasResp{msg: result message}} */ - public R flush(FlushReq request) { - return utilityService.flush(this.blockingStub, request); + public DescribeAliasResp describeAlias(String alias) { + return utilityService.describeAlias(this.blockingStub, alias); } + /** * close client * diff --git a/src/main/java/io/milvus/v2/examples/Simple.java b/src/main/java/io/milvus/v2/examples/Simple.java new file mode 100644 index 000000000..450b19571 --- /dev/null +++ b/src/main/java/io/milvus/v2/examples/Simple.java @@ -0,0 +1,92 @@ +package io.milvus.v2.examples; + +import com.alibaba.fastjson.JSONObject; +import io.milvus.v2.client.ConnectConfig; +import io.milvus.v2.client.MilvusClientV2; +import io.milvus.v2.exception.MilvusClientException; +import io.milvus.v2.service.collection.request.CreateCollectionReq; +import io.milvus.v2.service.collection.request.DescribeCollectionReq; +import io.milvus.v2.service.collection.request.DropCollectionReq; +import io.milvus.v2.service.collection.request.HasCollectionReq; +import io.milvus.v2.service.vector.request.InsertReq; +import io.milvus.v2.service.vector.request.QueryReq; +import io.milvus.v2.service.vector.request.SearchReq; +import io.milvus.v2.service.vector.response.QueryResp; +import io.milvus.v2.service.vector.response.SearchResp; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +public class Simple { + Integer dim = 2; + String collectionName = "book"; + static Logger logger = LoggerFactory.getLogger(Simple.class); + public static void main(String[] args) { + try { + new Simple().run(); + } catch (MilvusClientException | InterruptedException e) { + logger.info(e.toString()); + } + } + + public void run() throws InterruptedException { + ConnectConfig connectConfig = ConnectConfig.builder() + .uri("https://in01-******.aws-us-west-2.vectordb.zillizcloud.com:19531") + .token("*****") + .build(); + MilvusClientV2 client = new MilvusClientV2(connectConfig); + // check collection exists + if (client.hasCollection(HasCollectionReq.builder().collectionName(collectionName).build())) { + logger.info("collection exists"); + client.dropCollection(DropCollectionReq.builder().collectionName(collectionName).build()); + TimeUnit.SECONDS.sleep(1); + } + // create collection + CreateCollectionReq createCollectionReq = CreateCollectionReq.builder() + .collectionName(collectionName) + .dimension(dim) + .build(); + client.createCollection(createCollectionReq); + + logger.info(String.valueOf(client.listCollections())); + logger.info(String.valueOf(client.describeCollection(DescribeCollectionReq.builder().collectionName(collectionName).build()))); + //insert data + List insertData = new ArrayList<>(); + for(int i = 0; i < 6; i++){ + JSONObject jsonObject = new JSONObject(); + List vectorList = new ArrayList<>(); + for(int j = 0; j < dim; j++){ + // generate random float vector + vectorList.add(new Random().nextFloat()); + } + jsonObject.put("id", (long) i); + jsonObject.put("vector", vectorList); + insertData.add(jsonObject); + } + InsertReq insertReq = InsertReq.builder() + .collectionName(collectionName) + .data(insertData) + .build(); + client.insert(insertReq); + //query data + QueryReq queryReq = QueryReq.builder() + .collectionName(collectionName) + .filter("id in [0]") + .build(); + QueryResp queryResp = client.query(queryReq); + System.out.println(queryResp); + //search data + SearchReq searchReq = SearchReq.builder() + .collectionName(collectionName) + .data(Collections.singletonList(insertData.get(0).get("vector"))) + .topK(10) + .build(); + SearchResp searchResp = client.search(searchReq); + System.out.println(searchResp); + } +} diff --git a/src/main/java/io/milvus/v2/examples/Simple_Schema.java b/src/main/java/io/milvus/v2/examples/Simple_Schema.java new file mode 100644 index 000000000..9bf6c94c3 --- /dev/null +++ b/src/main/java/io/milvus/v2/examples/Simple_Schema.java @@ -0,0 +1,108 @@ +package io.milvus.v2.examples; + +import com.alibaba.fastjson.JSONObject; +import io.milvus.v2.client.ConnectConfig; +import io.milvus.v2.client.MilvusClientV2; +import io.milvus.v2.common.DataType; +import io.milvus.v2.common.IndexParam; +import io.milvus.v2.service.collection.request.CreateCollectionWithSchemaReq; +import io.milvus.v2.service.collection.request.DropCollectionReq; +import io.milvus.v2.service.collection.request.HasCollectionReq; +import io.milvus.v2.service.collection.request.LoadCollectionReq; +import io.milvus.v2.service.index.request.CreateIndexReq; +import io.milvus.v2.service.vector.request.InsertReq; +import io.milvus.v2.service.vector.request.QueryReq; +import io.milvus.v2.service.vector.request.SearchReq; +import io.milvus.v2.service.vector.response.QueryResp; +import io.milvus.v2.service.vector.response.SearchResp; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +public class Simple_Schema { + Integer dim = 2; + String collectionName = "book"; + static Logger logger = LoggerFactory.getLogger(Simple_Schema.class); + public void run() throws InterruptedException { + ConnectConfig connectConfig = ConnectConfig.builder() + .uri("https://in01-****.aws-us-west-2.vectordb.zillizcloud.com:19531") + .token("******") + .build(); + MilvusClientV2 client = new MilvusClientV2(connectConfig); + // check collection exists + if (client.hasCollection(HasCollectionReq.builder().collectionName(collectionName).build())) { + logger.info("collection exists"); + client.dropCollection(DropCollectionReq.builder().collectionName(collectionName).build()); + TimeUnit.SECONDS.sleep(1); + } + // create collection + CreateCollectionWithSchemaReq.CollectionSchema collectionSchema = client.createSchema(Boolean.TRUE, ""); + collectionSchema.addPrimaryField("id", DataType.Int64, Boolean.TRUE, Boolean.FALSE); + collectionSchema.addVectorField("vector", DataType.FloatVector, dim); + collectionSchema.addScalarField("num", DataType.Int32); + + CreateCollectionWithSchemaReq createCollectionReq = CreateCollectionWithSchemaReq.builder() + .collectionName(collectionName) + .collectionSchema(collectionSchema) + .build(); + client.createCollectionWithSchema(createCollectionReq); + //create index + IndexParam indexParam = IndexParam.builder() + .fieldName("vector") + .metricType(IndexParam.MetricType.COSINE) + .build(); + CreateIndexReq createIndexReq = CreateIndexReq.builder() + .collectionName(collectionName) + .indexParams(Collections.singletonList(indexParam)) + .build(); + client.createIndex(createIndexReq); + client.loadCollection(LoadCollectionReq.builder().collectionName(collectionName).build()); + //insert data + List insertData = new ArrayList<>(); + for(int i = 0; i < 6; i++){ + JSONObject jsonObject = new JSONObject(); + List vectorList = new ArrayList<>(); + for(int j = 0; j < dim; j++){ + // generate random float vector + vectorList.add(new Random().nextFloat()); + } + jsonObject.put("id", (long) i); + jsonObject.put("vector", vectorList); + jsonObject.put("num", i); + insertData.add(jsonObject); + } + + InsertReq insertReq = InsertReq.builder() + .collectionName(collectionName) + .data(insertData) + .build(); + client.insert(insertReq); + //query data + QueryReq queryReq = QueryReq.builder() + .collectionName(collectionName) + .filter("id in [0]") + .build(); + QueryResp queryResp = client.query(queryReq); + System.out.println(queryResp); + //search data + SearchReq searchReq = SearchReq.builder() + .collectionName(collectionName) + .data(Collections.singletonList(insertData.get(0).get("vector"))) + .topK(10) + .build(); + SearchResp searchResp = client.search(searchReq); + System.out.println(searchResp); + } + public static void main(String[] args) { + try { + new Simple_Schema().run(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/io/milvus/v2/exception/ErrorCode.java b/src/main/java/io/milvus/v2/exception/ErrorCode.java new file mode 100644 index 000000000..5c1b6d8e8 --- /dev/null +++ b/src/main/java/io/milvus/v2/exception/ErrorCode.java @@ -0,0 +1,16 @@ +package io.milvus.v2.exception; + +import lombok.Getter; + +@Getter +public enum ErrorCode { + SUCCESS(0), + COLLECTION_NOT_FOUND(1), + SERVER_ERROR(2); + + private final int code; + + ErrorCode(int i) { + this.code = i; + } +} diff --git a/src/main/java/io/milvus/v2/exception/MilvusClientException.java b/src/main/java/io/milvus/v2/exception/MilvusClientException.java new file mode 100644 index 000000000..1855b386c --- /dev/null +++ b/src/main/java/io/milvus/v2/exception/MilvusClientException.java @@ -0,0 +1,16 @@ +package io.milvus.v2.exception; + +import lombok.Getter; + +@Getter +public class MilvusClientException extends RuntimeException { + + private final ErrorCode errorCode; + + public MilvusClientException(ErrorCode errorCode, String message) { + super(message); + this.errorCode = errorCode; + } + + +} diff --git a/src/main/java/io/milvus/v2/service/BaseService.java b/src/main/java/io/milvus/v2/service/BaseService.java index 6560fab97..2f82bc251 100644 --- a/src/main/java/io/milvus/v2/service/BaseService.java +++ b/src/main/java/io/milvus/v2/service/BaseService.java @@ -1,16 +1,19 @@ package io.milvus.v2.service; -import io.milvus.exception.MilvusException; import io.milvus.grpc.BoolResponse; import io.milvus.grpc.HasCollectionRequest; import io.milvus.grpc.MilvusServiceGrpc; -import io.milvus.param.R; +import io.milvus.v2.exception.ErrorCode; +import io.milvus.v2.exception.MilvusClientException; import io.milvus.v2.utils.ConvertUtils; import io.milvus.v2.utils.DataUtils; -import io.milvus.v2.utils.VectorUtils; import io.milvus.v2.utils.RpcUtils; +import io.milvus.v2.utils.VectorUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class BaseService { + protected static final Logger logger = LoggerFactory.getLogger(BaseService.class); public RpcUtils rpcUtils = new RpcUtils(); public DataUtils dataUtils = new DataUtils(); public VectorUtils vectorUtils = new VectorUtils(); @@ -21,7 +24,8 @@ protected void checkCollectionExist(MilvusServiceGrpc.MilvusServiceBlockingStub BoolResponse result = blockingStub.hasCollection(request); rpcUtils.handleResponse("", result.getStatus()); if (!result.getValue() == Boolean.TRUE) { - throw new MilvusException("Collection " + collectionName + " not exist", R.Status.CollectionNotExists.getCode()); + logger.error("Collection not found"); + throw new MilvusClientException(ErrorCode.COLLECTION_NOT_FOUND, "Collection not found"); } } } diff --git a/src/main/java/io/milvus/v2/service/collection/CollectionService.java b/src/main/java/io/milvus/v2/service/collection/CollectionService.java index 906e638ff..683fcb37f 100644 --- a/src/main/java/io/milvus/v2/service/collection/CollectionService.java +++ b/src/main/java/io/milvus/v2/service/collection/CollectionService.java @@ -1,22 +1,22 @@ package io.milvus.v2.service.collection; import io.milvus.grpc.*; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; +import io.milvus.v2.common.IndexParam; import io.milvus.v2.service.BaseService; import io.milvus.v2.service.collection.request.*; import io.milvus.v2.service.collection.response.DescribeCollectionResp; import io.milvus.v2.service.collection.response.GetCollectionStatsResp; import io.milvus.v2.service.collection.response.ListCollectionsResp; -import io.milvus.v2.common.IndexParam; import io.milvus.v2.service.index.IndexService; import io.milvus.v2.service.index.request.CreateIndexReq; import io.milvus.v2.utils.SchemaUtils; +import java.util.Collections; + public class CollectionService extends BaseService { public IndexService indexService = new IndexService(); - public R createCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateCollectionReq request) { + public void createCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateCollectionReq request) { String title = String.format("CreateCollectionRequest collectionName:%s", request.getCollectionName()); FieldSchema vectorSchema = FieldSchema.newBuilder() .setName(request.getVectorFieldName()) @@ -27,11 +27,11 @@ public R createCollection(MilvusServiceGrpc.MilvusServiceBlockingStub FieldSchema idSchema = FieldSchema.newBuilder() .setName("id") - .setDataType(DataType.valueOf(request.getPrimaryFieldType())) + .setDataType(DataType.valueOf(request.getPrimaryFieldType().name())) .setIsPrimaryKey(Boolean.TRUE) .setAutoID(request.getAutoID()) .build(); - if(request.getPrimaryFieldType().equals("VarChar") && request.getMaxLength() != null){ + if(request.getPrimaryFieldType().name().equals("VarChar") && request.getMaxLength() != null){ idSchema = idSchema.toBuilder().addTypeParams(KeyValuePair.newBuilder().setKey("max_length").setValue(String.valueOf(request.getMaxLength())).build()).build(); } @@ -57,16 +57,15 @@ public R createCollection(MilvusServiceGrpc.MilvusServiceBlockingStub .fieldName("vector") .build(); CreateIndexReq createIndexReq = CreateIndexReq.builder() - .indexParam(indexParam) + .indexParams(Collections.singletonList(indexParam)) .collectionName(request.getCollectionName()) .build(); indexService.createIndex(blockingStub, createIndexReq); //load collection loadCollection(blockingStub, LoadCollectionReq.builder().collectionName(request.getCollectionName()).build()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R createCollectionWithSchema(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateCollectionWithSchemaReq request) { + public void createCollectionWithSchema(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateCollectionWithSchemaReq request) { String title = String.format("CreateCollectionRequest collectionName:%s", request.getCollectionName()); //convert CollectionSchema to io.milvus.grpc.CollectionSchema @@ -92,31 +91,28 @@ public R createCollectionWithSchema(MilvusServiceGrpc.MilvusServiceBl if(request.getIndexParams() != null && !request.getIndexParams().isEmpty()) { for(IndexParam indexParam : request.getIndexParams()) { CreateIndexReq createIndexReq = CreateIndexReq.builder() - .indexParam(indexParam) + .indexParams(Collections.singletonList(indexParam)) .collectionName(request.getCollectionName()) .build(); indexService.createIndex(blockingStub, createIndexReq); } + //load collection + loadCollection(blockingStub, LoadCollectionReq.builder().collectionName(request.getCollectionName()).build()); } - - //load collection - loadCollection(blockingStub, LoadCollectionReq.builder().collectionName(request.getCollectionName()).build()); - - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R listCollections(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub) { + public ListCollectionsResp listCollections(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub) { ShowCollectionsRequest showCollectionsRequest = ShowCollectionsRequest.newBuilder() .build(); ShowCollectionsResponse response = milvusServiceBlockingStub.showCollections(showCollectionsRequest); - ListCollectionsResp a = ListCollectionsResp.builder() + ListCollectionsResp listCollectionsResp = ListCollectionsResp.builder() .collectionNames(response.getCollectionNamesList()) .build(); - return R.success(a); + return listCollectionsResp; } - public R dropCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DropCollectionReq request) { + public void dropCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DropCollectionReq request) { String title = String.format("DropCollectionRequest collectionName:%s", request.getCollectionName()); DropCollectionRequest dropCollectionRequest = DropCollectionRequest.newBuilder() @@ -124,18 +120,18 @@ public R dropCollection(MilvusServiceGrpc.MilvusServiceBlockingStub m .build(); Status status = milvusServiceBlockingStub.dropCollection(dropCollectionRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R hasCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, HasCollectionReq request) { + public Boolean hasCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, HasCollectionReq request) { HasCollectionRequest hasCollectionRequest = HasCollectionRequest.newBuilder() .setCollectionName(request.getCollectionName()) .build(); BoolResponse response = milvusServiceBlockingStub.hasCollection(hasCollectionRequest); - return R.success(response.getValue()); + rpcUtils.handleResponse("HasCollectionRequest", response.getStatus()); + return response.getValue(); } - public R describeCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DescribeCollectionReq request) { + public DescribeCollectionResp describeCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DescribeCollectionReq request) { //check collection exists checkCollectionExist(milvusServiceBlockingStub, request.getCollectionName()); @@ -157,10 +153,10 @@ public R describeCollection(MilvusServiceGrpc.MilvusServ .createTime(response.getCreatedTimestamp()) .build(); - return R.success(describeCollectionResp); + return describeCollectionResp; } - public R renameCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, RenameCollectionReq request) { + public void renameCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, RenameCollectionReq request) { String title = String.format("RenameCollectionRequest collectionName:%s", request.getCollectionName()); RenameCollectionRequest renameCollectionRequest = RenameCollectionRequest.newBuilder() .setOldName(request.getCollectionName()) @@ -168,41 +164,41 @@ public R renameCollection(MilvusServiceGrpc.MilvusServiceBlockingStub .build(); Status status = milvusServiceBlockingStub.renameCollection(renameCollectionRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R loadCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, LoadCollectionReq request) { + public void loadCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, LoadCollectionReq request) { String title = String.format("LoadCollectionRequest collectionName:%s", request.getCollectionName()); LoadCollectionRequest loadCollectionRequest = LoadCollectionRequest.newBuilder() .setCollectionName(request.getCollectionName()) .build(); Status status = milvusServiceBlockingStub.loadCollection(loadCollectionRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R releaseCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, ReleaseCollectionReq request) { + public void releaseCollection(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, ReleaseCollectionReq request) { String title = String.format("ReleaseCollectionRequest collectionName:%s", request.getCollectionName()); ReleaseCollectionRequest releaseCollectionRequest = ReleaseCollectionRequest.newBuilder() .setCollectionName(request.getCollectionName()) .build(); Status status = milvusServiceBlockingStub.releaseCollection(releaseCollectionRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R getLoadState(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, GetLoadStateReq request) { + public Boolean getLoadState(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, GetLoadStateReq request) { // getLoadState String title = String.format("GetLoadStateRequest collectionName:%s", request.getCollectionName()); GetLoadStateRequest getLoadStateRequest = GetLoadStateRequest.newBuilder() .setCollectionName(request.getCollectionName()) .build(); + if(request.getPartitionName() != null) { + getLoadStateRequest = getLoadStateRequest.toBuilder().addPartitionNames(request.getPartitionName()).build(); + } GetLoadStateResponse response = milvusServiceBlockingStub.getLoadState(getLoadStateRequest); rpcUtils.handleResponse(title, response.getStatus()); - return R.success(response.getState() == LoadState.LoadStateLoaded); + return response.getState() == LoadState.LoadStateLoaded; } - public R getCollectionStats(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GetCollectionStatsReq request) { + public GetCollectionStatsResp getCollectionStats(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GetCollectionStatsReq request) { String title = String.format("GetCollectionStatisticsRequest collectionName:%s", request.getCollectionName()); GetCollectionStatisticsRequest getCollectionStatisticsRequest = GetCollectionStatisticsRequest.newBuilder() .setCollectionName(request.getCollectionName()) @@ -213,6 +209,13 @@ public R getCollectionStats(MilvusServiceGrpc.MilvusServ GetCollectionStatsResp getCollectionStatsResp = GetCollectionStatsResp.builder() .numOfEntities(response.getStatsList().stream().filter(stat -> stat.getKey().equals("row_count")).map(stat -> Long.parseLong(stat.getValue())).findFirst().get()) .build(); - return R.success(getCollectionStatsResp); + return getCollectionStatsResp; + } + + public CreateCollectionWithSchemaReq.CollectionSchema createSchema(Boolean enableDynamicField, String description) { + return CreateCollectionWithSchemaReq.CollectionSchema.builder() + .enableDynamicField(enableDynamicField) + .description(description) + .build(); } } diff --git a/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionReq.java b/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionReq.java index ebbf5b2f9..c73cbac9d 100644 --- a/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionReq.java +++ b/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionReq.java @@ -15,7 +15,7 @@ public class CreateCollectionReq { @Builder.Default private String primaryFieldName = "id"; @Builder.Default - private String primaryFieldType = DataType.VarChar.name(); + private DataType primaryFieldType = DataType.Int64; @Builder.Default private Integer maxLength = 65535; @Builder.Default @@ -23,5 +23,5 @@ public class CreateCollectionReq { @Builder.Default private String metricType = IndexParam.MetricType.IP.name(); @Builder.Default - private Boolean autoID = Boolean.TRUE; + private Boolean autoID = Boolean.FALSE; } diff --git a/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionWithSchemaReq.java b/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionWithSchemaReq.java index 1aeb90ef9..1eda2d9e8 100644 --- a/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionWithSchemaReq.java +++ b/src/main/java/io/milvus/v2/service/collection/request/CreateCollectionWithSchemaReq.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.experimental.SuperBuilder; +import java.util.ArrayList; import java.util.List; @SuperBuilder @@ -18,7 +19,8 @@ public class CreateCollectionWithSchemaReq { @Data @SuperBuilder public static class CollectionSchema { - private List fieldSchemaList; + @Builder.Default + private List fieldSchemaList = new ArrayList<>(); @Builder.Default private String description = ""; private Boolean enableDynamicField; @@ -31,6 +33,53 @@ public FieldSchema getField(String fieldName) { } return null; } + public void addPrimaryField(String fieldName, DataType dataType, Boolean isPrimaryKey, Boolean autoID) { + // primary key field + FieldSchema fieldSchema = FieldSchema.builder() + .name(fieldName) + .dataType(dataType) + .isPrimaryKey(isPrimaryKey) + .autoID(autoID) + .build(); + fieldSchemaList.add(fieldSchema); + } + public void addPrimaryField(String fieldName, DataType dataType, Integer maxLength, Boolean isPrimaryKey, Boolean autoID) { + // primary key field + FieldSchema fieldSchema = FieldSchema.builder() + .name(fieldName) + .dataType(dataType) + .maxLength(maxLength) + .isPrimaryKey(isPrimaryKey) + .autoID(autoID) + .build(); + fieldSchemaList.add(fieldSchema); + } + public void addVectorField(String fieldName, DataType dataType, Integer dimension) { + // vector field + FieldSchema fieldSchema = FieldSchema.builder() + .name(fieldName) + .dataType(dataType) + .dimension(dimension) + .build(); + fieldSchemaList.add(fieldSchema); + } + public void addScalarField(String fieldName, DataType dataType, Integer maxLength) { + // scalar field + FieldSchema fieldSchema = FieldSchema.builder() + .name(fieldName) + .dataType(dataType) + .maxLength(maxLength) + .build(); + fieldSchemaList.add(fieldSchema); + } + public void addScalarField(String fieldName, DataType dataType) { + // scalar field + FieldSchema fieldSchema = FieldSchema.builder() + .name(fieldName) + .dataType(dataType) + .build(); + fieldSchemaList.add(fieldSchema); + } } @Data diff --git a/src/main/java/io/milvus/v2/service/collection/request/GetLoadStateReq.java b/src/main/java/io/milvus/v2/service/collection/request/GetLoadStateReq.java index e102645d1..4d73d6ddd 100644 --- a/src/main/java/io/milvus/v2/service/collection/request/GetLoadStateReq.java +++ b/src/main/java/io/milvus/v2/service/collection/request/GetLoadStateReq.java @@ -7,4 +7,5 @@ @SuperBuilder public class GetLoadStateReq { private String collectionName; + private String partitionName; } diff --git a/src/main/java/io/milvus/v2/service/index/IndexService.java b/src/main/java/io/milvus/v2/service/index/IndexService.java index 9291ffe87..1ce0d5a5b 100644 --- a/src/main/java/io/milvus/v2/service/index/IndexService.java +++ b/src/main/java/io/milvus/v2/service/index/IndexService.java @@ -1,8 +1,6 @@ package io.milvus.v2.service.index; import io.milvus.grpc.*; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.common.IndexParam; import io.milvus.v2.service.BaseService; import io.milvus.v2.service.index.request.CreateIndexReq; @@ -11,29 +9,36 @@ import io.milvus.v2.service.index.response.DescribeIndexResp; public class IndexService extends BaseService { - public R createIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, CreateIndexReq request) { - String title = String.format("CreateIndexRequest collectionName:%s, fieldName:%s", - request.getCollectionName(), request.getIndexParam().getFieldName()); - CreateIndexRequest createIndexRequest = CreateIndexRequest.newBuilder() - .setCollectionName(request.getCollectionName()) - .setIndexName(request.getIndexParam().getIndexName()) - .setFieldName(request.getIndexParam().getFieldName()) - .addExtraParams(KeyValuePair.newBuilder() - .setKey("index_type") - .setValue(String.valueOf(request.getIndexParam().getIndexType())) - .build()) - .addExtraParams(KeyValuePair.newBuilder() - .setKey("metric_type") - .setValue(String.valueOf(request.getIndexParam().getMetricType())) - .build()) - .build(); - Status status = milvusServiceBlockingStub.createIndex(createIndexRequest); - rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); + public void createIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, CreateIndexReq request) { + for(IndexParam indexParam : request.getIndexParams()) { + String title = String.format("CreateIndexRequest collectionName:%s, fieldName:%s", + request.getCollectionName(), indexParam.getFieldName()); + CreateIndexRequest createIndexRequest = CreateIndexRequest.newBuilder() + .setCollectionName(request.getCollectionName()) + .setIndexName(indexParam.getIndexName()) + .setFieldName(indexParam.getFieldName()) + .addExtraParams(KeyValuePair.newBuilder() + .setKey("index_type") + .setValue(String.valueOf(indexParam.getIndexType())) + .build()) + .build(); + if(indexParam.getMetricType()!= null){ + // only vector field has a metric type + createIndexRequest = createIndexRequest.toBuilder() + .addExtraParams(KeyValuePair.newBuilder() + .setKey("metric_type") + .setValue(String.valueOf(indexParam.getMetricType())) + .build()) + .build(); + } + + Status status = milvusServiceBlockingStub.createIndex(createIndexRequest); + rpcUtils.handleResponse(title, status); + } } - public R dropIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DropIndexReq request) { + public void dropIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DropIndexReq request) { String title = String.format("DropIndexRequest collectionName:%s, fieldName:%s, indexName:%s", request.getCollectionName(), request.getFieldName(), request.getIndexName()); DropIndexRequest dropIndexRequest = DropIndexRequest.newBuilder() @@ -44,10 +49,9 @@ public R dropIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvus Status status = milvusServiceBlockingStub.dropIndex(dropIndexRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R describeIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DescribeIndexReq request) { + public DescribeIndexResp describeIndex(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DescribeIndexReq request) { String title = String.format("DescribeIndexRequest collectionName:%s, fieldName:%s, indexName:%s", request.getCollectionName(), request.getFieldName(), request.getIndexName()); DescribeIndexRequest describeIndexRequest = DescribeIndexRequest.newBuilder() diff --git a/src/main/java/io/milvus/v2/service/index/request/CreateIndexReq.java b/src/main/java/io/milvus/v2/service/index/request/CreateIndexReq.java index 422c54123..9dbee8d86 100644 --- a/src/main/java/io/milvus/v2/service/index/request/CreateIndexReq.java +++ b/src/main/java/io/milvus/v2/service/index/request/CreateIndexReq.java @@ -4,9 +4,11 @@ import lombok.Data; import lombok.experimental.SuperBuilder; +import java.util.List; + @Data @SuperBuilder public class CreateIndexReq { private String collectionName; - private IndexParam indexParam; + private List indexParams; } diff --git a/src/main/java/io/milvus/v2/service/partition/PartitionService.java b/src/main/java/io/milvus/v2/service/partition/PartitionService.java index e0a3df78c..42046cb9c 100644 --- a/src/main/java/io/milvus/v2/service/partition/PartitionService.java +++ b/src/main/java/io/milvus/v2/service/partition/PartitionService.java @@ -3,17 +3,13 @@ import io.milvus.grpc.CreatePartitionRequest; import io.milvus.grpc.MilvusServiceGrpc; import io.milvus.grpc.Status; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.v2.service.partition.request.*; import io.milvus.v2.service.BaseService; -import io.milvus.v2.service.collection.request.LoadCollectionReq; -import io.milvus.v2.service.collection.request.ReleaseCollectionReq; +import io.milvus.v2.service.partition.request.*; import java.util.List; public class PartitionService extends BaseService { - public R createPartition(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreatePartitionReq request) { + public void createPartition(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreatePartitionReq request) { String title = String.format("Create partition %s in collection %s", request.getPartitionName(), request.getCollectionName()); CreatePartitionRequest createPartitionRequest = io.milvus.grpc.CreatePartitionRequest.newBuilder() @@ -23,10 +19,9 @@ public R createPartition(MilvusServiceGrpc.MilvusServiceBlockingStub Status status = blockingStub.createPartition(createPartitionRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R dropPartition(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropPartitionReq request) { + public void dropPartition(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropPartitionReq request) { String title = String.format("Drop partition %s in collection %s", request.getPartitionName(), request.getCollectionName()); io.milvus.grpc.DropPartitionRequest dropPartitionRequest = io.milvus.grpc.DropPartitionRequest.newBuilder() @@ -36,10 +31,9 @@ public R dropPartition(MilvusServiceGrpc.MilvusServiceBlockingStub bl Status status = blockingStub.dropPartition(dropPartitionRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R hasPartition(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, HasPartitionReq request) { + public Boolean hasPartition(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, HasPartitionReq request) { String title = String.format("Has partition %s in collection %s", request.getPartitionName(), request.getCollectionName()); io.milvus.grpc.HasPartitionRequest hasPartitionRequest = io.milvus.grpc.HasPartitionRequest.newBuilder() @@ -49,10 +43,10 @@ public R hasPartition(MilvusServiceGrpc.MilvusServiceBlockingStub block io.milvus.grpc.BoolResponse boolResponse = blockingStub.hasPartition(hasPartitionRequest); rpcUtils.handleResponse(title, boolResponse.getStatus()); - return R.success(boolResponse.getValue()); + return boolResponse.getValue(); } - public R> listPartitions(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, ListPartitionsReq request) { + public List listPartitions(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, ListPartitionsReq request) { String title = String.format("List partitions in collection %s", request.getCollectionName()); io.milvus.grpc.ShowPartitionsRequest showPartitionsRequest = io.milvus.grpc.ShowPartitionsRequest.newBuilder() @@ -61,10 +55,10 @@ public R> listPartitions(MilvusServiceGrpc.MilvusServiceBlockingStu io.milvus.grpc.ShowPartitionsResponse showPartitionsResponse = blockingStub.showPartitions(showPartitionsRequest); rpcUtils.handleResponse(title, showPartitionsResponse.getStatus()); - return R.success(showPartitionsResponse.getPartitionNamesList()); + return showPartitionsResponse.getPartitionNamesList(); } - public R loadPartitions(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, LoadPartitionsReq request) { + public void loadPartitions(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, LoadPartitionsReq request) { String title = String.format("Load partitions %s in collection %s", request.getPartitionNames(), request.getCollectionName()); io.milvus.grpc.LoadPartitionsRequest loadPartitionsRequest = io.milvus.grpc.LoadPartitionsRequest.newBuilder() @@ -72,10 +66,9 @@ public R loadPartitions(MilvusServiceGrpc.MilvusServiceBlockingStub b .addAllPartitionNames(request.getPartitionNames()).build(); Status status = blockingStub.loadPartitions(loadPartitionsRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R releasePartitions(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, ReleasePartitionsReq request) { + public void releasePartitions(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, ReleasePartitionsReq request) { String title = String.format("Release partitions %s in collection %s", request.getPartitionNames(), request.getCollectionName()); io.milvus.grpc.ReleasePartitionsRequest releasePartitionsRequest = io.milvus.grpc.ReleasePartitionsRequest.newBuilder() @@ -83,6 +76,5 @@ public R releasePartitions(MilvusServiceGrpc.MilvusServiceBlockingStu .addAllPartitionNames(request.getPartitionNames()).build(); Status status = blockingStub.releasePartitions(releasePartitionsRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } } diff --git a/src/main/java/io/milvus/v2/service/rbac/RoleService.java b/src/main/java/io/milvus/v2/service/rbac/RoleService.java index d26f46310..d5d08ba12 100644 --- a/src/main/java/io/milvus/v2/service/rbac/RoleService.java +++ b/src/main/java/io/milvus/v2/service/rbac/RoleService.java @@ -1,8 +1,6 @@ package io.milvus.v2.service.rbac; import io.milvus.grpc.*; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.service.BaseService; import io.milvus.v2.service.rbac.request.*; import io.milvus.v2.service.rbac.response.DescribeRoleResp; @@ -12,17 +10,16 @@ public class RoleService extends BaseService { - public R> listRoles(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub) { + public List listRoles(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub) { String title = "listRoles"; SelectRoleRequest request = SelectRoleRequest.newBuilder().build(); SelectRoleResponse response = blockingStub.selectRole(request); rpcUtils.handleResponse(title, response.getStatus()); - List roles = response.getResultsList().stream().map(roleResult -> roleResult.getRole().getName()).collect(Collectors.toList()); - return R.success(roles); + return response.getResultsList().stream().map(roleResult -> roleResult.getRole().getName()).collect(Collectors.toList()); } - public R createRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateRoleReq request) { + public void createRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateRoleReq request) { String title = "createRole"; CreateRoleRequest createRoleRequest = CreateRoleRequest.newBuilder() .setEntity(RoleEntity.newBuilder() @@ -31,10 +28,9 @@ public R createRole(MilvusServiceGrpc.MilvusServiceBlockingStub block .build(); Status status = blockingStub.createRole(createRoleRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R describeRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DescribeRoleReq request) { + public DescribeRoleResp describeRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DescribeRoleReq request) { String title = "describeRole"; SelectGrantRequest selectGrantRequest = SelectGrantRequest.newBuilder() .setEntity(GrantEntity.newBuilder() @@ -54,20 +50,19 @@ public R describeRole(MilvusServiceGrpc.MilvusServiceBlockingS .grantor(grantEntity.getGrantor().getUser().getName()) .build()).collect(Collectors.toList())) .build(); - return R.success(describeRoleResp); + return describeRoleResp; } - public R dropRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropRoleReq request) { + public void dropRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropRoleReq request) { String title = "dropRole"; DropRoleRequest dropRoleRequest = DropRoleRequest.newBuilder() .setRoleName(request.getRoleName()) .build(); Status status = blockingStub.dropRole(dropRoleRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R grantPrivilege(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GrantPrivilegeReq request) { + public void grantPrivilege(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GrantPrivilegeReq request) { String title = "grantPrivilege"; GrantEntity entity = GrantEntity.newBuilder() .setRole(RoleEntity.newBuilder() @@ -84,10 +79,9 @@ public R grantPrivilege(MilvusServiceGrpc.MilvusServiceBlockingStub b .build(); Status status = blockingStub.operatePrivilege(operatePrivilegeRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R revokePrivilege(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, RevokePrivilegeReq request) { + public void revokePrivilege(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, RevokePrivilegeReq request) { String title = "revokePrivilege"; GrantEntity entity = GrantEntity.newBuilder() .setRole(RoleEntity.newBuilder() @@ -104,10 +98,9 @@ public R revokePrivilege(MilvusServiceGrpc.MilvusServiceBlockingStub .build(); Status status = blockingStub.operatePrivilege(operatePrivilegeRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R grantRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GrantRoleReq request) { + public void grantRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GrantRoleReq request) { String title = "grantRole"; OperateUserRoleRequest operateUserRoleRequest = OperateUserRoleRequest.newBuilder() .setUsername(request.getUserName()) @@ -116,10 +109,9 @@ public R grantRole(MilvusServiceGrpc.MilvusServiceBlockingStub blocki .build(); Status status = blockingStub.operateUserRole(operateUserRoleRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R revokeRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, RevokeRoleReq request) { + public void revokeRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, RevokeRoleReq request) { String title = "grantRole"; OperateUserRoleRequest operateUserRoleRequest = OperateUserRoleRequest.newBuilder() .setUsername(request.getUserName()) @@ -128,6 +120,5 @@ public R revokeRole(MilvusServiceGrpc.MilvusServiceBlockingStub block .build(); Status status = blockingStub.operateUserRole(operateUserRoleRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } } diff --git a/src/main/java/io/milvus/v2/service/rbac/UserService.java b/src/main/java/io/milvus/v2/service/rbac/UserService.java index 7db4f0cac..a2dba0578 100644 --- a/src/main/java/io/milvus/v2/service/rbac/UserService.java +++ b/src/main/java/io/milvus/v2/service/rbac/UserService.java @@ -1,10 +1,11 @@ package io.milvus.v2.service.rbac; import io.milvus.grpc.*; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.v2.service.rbac.request.*; import io.milvus.v2.service.BaseService; +import io.milvus.v2.service.rbac.request.CreateUserReq; +import io.milvus.v2.service.rbac.request.DescribeUserReq; +import io.milvus.v2.service.rbac.request.DropUserReq; +import io.milvus.v2.service.rbac.request.UpdatePasswordReq; import io.milvus.v2.service.rbac.response.DescribeUserResp; import java.nio.charset.StandardCharsets; @@ -14,15 +15,15 @@ public class UserService extends BaseService { - public R> listUsers(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub) { + public List listUsers(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub) { String title = "list users"; ListCredUsersRequest request = ListCredUsersRequest.newBuilder().build(); ListCredUsersResponse response = blockingStub.listCredUsers(request); rpcUtils.handleResponse(title, response.getStatus()); - return R.success(response.getUsernamesList()); + return response.getUsernamesList(); } - public R describeUser(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DescribeUserReq request) { + public DescribeUserResp describeUser(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DescribeUserReq request) { String title = String.format("describe user %s", request.getUserName()); // TODO: check user exists SelectUserRequest selectUserRequest = SelectUserRequest.newBuilder() @@ -34,10 +35,10 @@ public R describeUser(MilvusServiceGrpc.MilvusServiceBlockingS DescribeUserResp describeUserResp = DescribeUserResp.builder() .roles(response.getResultsList().isEmpty()? null : response.getResultsList().get(0).getRolesList().stream().map(RoleEntity::getName).collect(Collectors.toList())) .build(); - return R.success(describeUserResp); + return describeUserResp; } - public R createUser(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateUserReq request) { + public void createUser(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateUserReq request) { String title = String.format("create user %s", request.getUserName()); CreateCredentialRequest createCredentialRequest = CreateCredentialRequest.newBuilder() .setUsername(request.getUserName()) @@ -45,11 +46,10 @@ public R createUser(MilvusServiceGrpc.MilvusServiceBlockingStub block .build(); Status response = blockingStub.createCredential(createCredentialRequest); rpcUtils.handleResponse(title, response); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R updatePassword(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, UpdatePasswordReq request) { + public void updatePassword(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, UpdatePasswordReq request) { String title = String.format("update password for user %s", request.getUserName()); UpdateCredentialRequest updateCredentialRequest = UpdateCredentialRequest.newBuilder() .setUsername(request.getUserName()) @@ -58,16 +58,14 @@ public R updatePassword(MilvusServiceGrpc.MilvusServiceBlockingStub b .build(); Status response = blockingStub.updateCredential(updateCredentialRequest); rpcUtils.handleResponse(title, response); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R dropUser(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropUserReq request) { + public void dropUser(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropUserReq request) { String title = String.format("drop user %s", request.getUserName()); DeleteCredentialRequest deleteCredentialRequest = DeleteCredentialRequest.newBuilder() .setUsername(request.getUserName()) .build(); Status response = blockingStub.deleteCredential(deleteCredentialRequest); rpcUtils.handleResponse(title, response); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } } diff --git a/src/main/java/io/milvus/v2/service/utility/UtilityService.java b/src/main/java/io/milvus/v2/service/utility/UtilityService.java index ef0aa5525..8cb08fca2 100644 --- a/src/main/java/io/milvus/v2/service/utility/UtilityService.java +++ b/src/main/java/io/milvus/v2/service/utility/UtilityService.java @@ -4,11 +4,11 @@ import io.milvus.grpc.MilvusServiceGrpc; import io.milvus.param.R; import io.milvus.param.RpcStatus; -import io.milvus.v2.service.utility.request.FlushReq; import io.milvus.v2.service.BaseService; import io.milvus.v2.service.utility.request.AlterAliasReq; import io.milvus.v2.service.utility.request.CreateAliasReq; import io.milvus.v2.service.utility.request.DropAliasReq; +import io.milvus.v2.service.utility.request.FlushReq; import io.milvus.v2.service.utility.response.DescribeAliasResp; import io.milvus.v2.service.utility.response.ListAliasResp; @@ -23,7 +23,7 @@ public R flush(MilvusServiceGrpc.MilvusServiceBlockingStub blockingSt return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R createAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateAliasReq request) { + public void createAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, CreateAliasReq request) { String title = String.format("Create alias %s for collection %s", request.getAlias(), request.getCollectionName()); io.milvus.grpc.CreateAliasRequest createAliasRequest = io.milvus.grpc.CreateAliasRequest.newBuilder() .setCollectionName(request.getCollectionName()) @@ -31,20 +31,18 @@ public R createAlias(MilvusServiceGrpc.MilvusServiceBlockingStub bloc .build(); io.milvus.grpc.Status status = blockingStub.createAlias(createAliasRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R dropAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropAliasReq request) { + public void dropAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DropAliasReq request) { String title = String.format("Drop alias %s", request.getAlias()); io.milvus.grpc.DropAliasRequest dropAliasRequest = io.milvus.grpc.DropAliasRequest.newBuilder() .setAlias(request.getAlias()) .build(); io.milvus.grpc.Status status = blockingStub.dropAlias(dropAliasRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R alterAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterAliasReq request) { + public void alterAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, AlterAliasReq request) { String title = String.format("Alter alias %s for collection %s", request.getAlias(), request.getCollectionName()); io.milvus.grpc.AlterAliasRequest alterAliasRequest = io.milvus.grpc.AlterAliasRequest.newBuilder() .setCollectionName(request.getCollectionName()) @@ -52,10 +50,9 @@ public R alterAlias(MilvusServiceGrpc.MilvusServiceBlockingStub block .build(); io.milvus.grpc.Status status = blockingStub.alterAlias(alterAliasRequest); rpcUtils.handleResponse(title, status); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); } - public R describeAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, String alias) { + public DescribeAliasResp describeAlias(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, String alias) { String title = String.format("Describe alias %s", alias); io.milvus.grpc.DescribeAliasRequest describeAliasRequest = io.milvus.grpc.DescribeAliasRequest.newBuilder() .setAlias(alias) @@ -64,13 +61,13 @@ public R describeAlias(MilvusServiceGrpc.MilvusServiceBlockin rpcUtils.handleResponse(title, response.getStatus()); - return R.success(DescribeAliasResp.builder() + return DescribeAliasResp.builder() .collectionName(response.getCollection()) .alias(response.getAlias()) - .build()); + .build(); } - public R listAliases(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub) { + public ListAliasResp listAliases(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub) { String title = "List aliases"; io.milvus.grpc.ListAliasesRequest listAliasesRequest = io.milvus.grpc.ListAliasesRequest.newBuilder() .build(); @@ -78,9 +75,9 @@ public R listAliases(MilvusServiceGrpc.MilvusServiceBlockingStub rpcUtils.handleResponse(title, response.getStatus()); - return R.success(ListAliasResp.builder() + return ListAliasResp.builder() .collectionName(response.getCollectionName()) .alias(response.getAliasesList()) - .build()); + .build(); } } diff --git a/src/main/java/io/milvus/v2/service/vector/VectorService.java b/src/main/java/io/milvus/v2/service/vector/VectorService.java index 110c8724b..58f898e65 100644 --- a/src/main/java/io/milvus/v2/service/vector/VectorService.java +++ b/src/main/java/io/milvus/v2/service/vector/VectorService.java @@ -1,20 +1,16 @@ package io.milvus.v2.service.vector; import io.milvus.grpc.*; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.response.DescCollResponseWrapper; import io.milvus.v2.service.BaseService; import io.milvus.v2.service.collection.CollectionService; import io.milvus.v2.service.collection.request.DescribeCollectionReq; import io.milvus.v2.service.collection.response.DescribeCollectionResp; +import io.milvus.v2.service.index.IndexService; import io.milvus.v2.service.index.request.DescribeIndexReq; import io.milvus.v2.service.index.response.DescribeIndexResp; -import io.milvus.v2.service.index.IndexService; import io.milvus.v2.service.vector.request.*; -import io.milvus.v2.service.vector.response.QueryResp; -import io.milvus.v2.service.vector.response.GetResp; -import io.milvus.v2.service.vector.response.SearchResp; +import io.milvus.v2.service.vector.response.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,7 +19,7 @@ public class VectorService extends BaseService { public CollectionService collectionService = new CollectionService(); public IndexService indexService = new IndexService(); - public R insert(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, InsertReq request){ + public InsertResp insert(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, InsertReq request) { String title = String.format("InsertRequest collectionName:%s", request.getCollectionName()); checkCollectionExist(blockingStub, request.getCollectionName()); DescribeCollectionRequest describeCollectionRequest = DescribeCollectionRequest.newBuilder() @@ -32,10 +28,12 @@ public R insert(MilvusServiceGrpc.MilvusServiceBlockingStub blockingS MutationResult response = blockingStub.insert(dataUtils.convertGrpcInsertRequest(request, new DescCollResponseWrapper(descResp))); rpcUtils.handleResponse(title, response.getStatus()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); + return InsertResp.builder() + .InsertCnt(response.getInsertCnt()) + .build(); } - public R upsert(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, UpsertReq request) { + public UpsertResp upsert(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, UpsertReq request) { String title = String.format("UpsertRequest collectionName:%s", request.getCollectionName()); checkCollectionExist(milvusServiceBlockingStub, request.getCollectionName()); @@ -46,60 +44,63 @@ public R upsert(MilvusServiceGrpc.MilvusServiceBlockingStub milvusSer MutationResult response = milvusServiceBlockingStub.upsert(dataUtils.convertGrpcUpsertRequest(request, new DescCollResponseWrapper(descResp))); rpcUtils.handleResponse(title, response.getStatus()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); + return UpsertResp.builder() + .upsertCnt(response.getInsertCnt()) + .build(); } - public R query(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, QueryReq request) { + public QueryResp query(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, QueryReq request) { String title = String.format("QueryRequest collectionName:%s", request.getCollectionName()); checkCollectionExist(milvusServiceBlockingStub, request.getCollectionName()); - R descR = collectionService.describeCollection(milvusServiceBlockingStub, DescribeCollectionReq.builder().collectionName(request.getCollectionName()).build()); + DescribeCollectionResp descR = collectionService.describeCollection(milvusServiceBlockingStub, DescribeCollectionReq.builder().collectionName(request.getCollectionName()).build()); if(request.getOutputFields() == null){ - request.setOutputFields(descR.getData().getFieldNames()); + request.setOutputFields(descR.getFieldNames()); + } + if(request.getIds() != null){ + request.setFilter(vectorUtils.getExprById(descR.getPrimaryFieldName(), request.getIds())); } QueryResults response = milvusServiceBlockingStub.query(vectorUtils.ConvertToGrpcQueryRequest(request)); rpcUtils.handleResponse(title, response.getStatus()); - QueryResp res = QueryResp.builder() + return QueryResp.builder() .queryResults(convertUtils.getEntities(response)) .build(); - return R.success(res); } - public R search(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, SearchReq request) { + public SearchResp search(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, SearchReq request) { String title = String.format("SearchRequest collectionName:%s", request.getCollectionName()); checkCollectionExist(milvusServiceBlockingStub, request.getCollectionName()); - R descR = collectionService.describeCollection(milvusServiceBlockingStub, DescribeCollectionReq.builder().collectionName(request.getCollectionName()).build()); + DescribeCollectionResp descR = collectionService.describeCollection(milvusServiceBlockingStub, DescribeCollectionReq.builder().collectionName(request.getCollectionName()).build()); if (request.getVectorFieldName() == null) { - request.setVectorFieldName(descR.getData().getVectorFieldName().get(0)); + request.setVectorFieldName(descR.getVectorFieldName().get(0)); } - if(request.getOutFields() == null){ - request.setOutFields(descR.getData().getFieldNames()); + if(request.getOutputFields() == null){ + request.setOutputFields(descR.getFieldNames()); } DescribeIndexReq describeIndexReq = DescribeIndexReq.builder() .collectionName(request.getCollectionName()) .fieldName(request.getVectorFieldName()) .build(); - R respR = indexService.describeIndex(milvusServiceBlockingStub, describeIndexReq); + DescribeIndexResp respR = indexService.describeIndex(milvusServiceBlockingStub, describeIndexReq); - SearchRequest searchRequest = vectorUtils.ConvertToGrpcSearchRequest(respR.getData().getMetricType(), request); + SearchRequest searchRequest = vectorUtils.ConvertToGrpcSearchRequest(respR.getMetricType(), request); SearchResults response = milvusServiceBlockingStub.search(searchRequest); rpcUtils.handleResponse(title, response.getStatus()); - SearchResp searchResp = SearchResp.builder() + return SearchResp.builder() .searchResults(convertUtils.getEntities(response)) .build(); - return R.success(searchResp); } - public R delete(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DeleteReq request) { + public DeleteResp delete(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, DeleteReq request) { String title = String.format("DeleteRequest collectionName:%s", request.getCollectionName()); checkCollectionExist(milvusServiceBlockingStub, request.getCollectionName()); - R respR = collectionService.describeCollection(milvusServiceBlockingStub, DescribeCollectionReq.builder().collectionName(request.getCollectionName()).build()); + DescribeCollectionResp respR = collectionService.describeCollection(milvusServiceBlockingStub, DescribeCollectionReq.builder().collectionName(request.getCollectionName()).build()); if(request.getExpr() == null){ - request.setExpr(vectorUtils.getExprById(respR.getData().getPrimaryFieldName(), request.getIds())); + request.setExpr(vectorUtils.getExprById(respR.getPrimaryFieldName(), request.getIds())); } DeleteRequest deleteRequest = DeleteRequest.newBuilder() .setCollectionName(request.getCollectionName()) @@ -108,27 +109,22 @@ public R delete(MilvusServiceGrpc.MilvusServiceBlockingStub milvusSer .build(); MutationResult response = milvusServiceBlockingStub.delete(deleteRequest); rpcUtils.handleResponse(title, response.getStatus()); - return R.success(new RpcStatus(RpcStatus.SUCCESS_MSG)); + return DeleteResp.builder() + .deleteCnt(response.getDeleteCnt()) + .build(); } - public R get(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, GetReq request) { + public GetResp get(MilvusServiceGrpc.MilvusServiceBlockingStub milvusServiceBlockingStub, GetReq request) { String title = String.format("GetRequest collectionName:%s", request.getCollectionName()); - checkCollectionExist(milvusServiceBlockingStub, request.getCollectionName()); - DescribeCollectionReq describeCollectionReq = DescribeCollectionReq.builder() - .collectionName(request.getCollectionName()) - .build(); - R resp = collectionService.describeCollection(milvusServiceBlockingStub, describeCollectionReq); - - String expr = vectorUtils.getExprById(resp.getData().getPrimaryFieldName(), request.getIds()); + logger.debug(title); QueryReq queryReq = QueryReq.builder() .collectionName(request.getCollectionName()) - .expr(expr) + .ids(request.getIds()) .build(); - R queryResp = query(milvusServiceBlockingStub, queryReq); + QueryResp queryResp = query(milvusServiceBlockingStub, queryReq); - GetResp getResp = GetResp.builder() - .getResults(queryResp.getData().getQueryResults()) + return GetResp.builder() + .getResults(queryResp.getQueryResults()) .build(); - return R.success(getResp); } } diff --git a/src/main/java/io/milvus/v2/service/vector/request/GetReq.java b/src/main/java/io/milvus/v2/service/vector/request/GetReq.java index 882f8bbb5..4d5b35be2 100644 --- a/src/main/java/io/milvus/v2/service/vector/request/GetReq.java +++ b/src/main/java/io/milvus/v2/service/vector/request/GetReq.java @@ -12,5 +12,5 @@ public class GetReq { private String collectionName; @Builder.Default private String partitionName = ""; - private List ids; + private List ids; } diff --git a/src/main/java/io/milvus/v2/service/vector/request/InsertReq.java b/src/main/java/io/milvus/v2/service/vector/request/InsertReq.java index c9d1eddc5..61e4ece64 100644 --- a/src/main/java/io/milvus/v2/service/vector/request/InsertReq.java +++ b/src/main/java/io/milvus/v2/service/vector/request/InsertReq.java @@ -5,15 +5,13 @@ import lombok.Data; import lombok.experimental.SuperBuilder; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Data @SuperBuilder public class InsertReq { //private List<> fields; - private List insertData; + private List data; private String collectionName; @Builder.Default private String partitionName = ""; diff --git a/src/main/java/io/milvus/v2/service/vector/request/QueryReq.java b/src/main/java/io/milvus/v2/service/vector/request/QueryReq.java index 80137fcec..2b7b52eab 100644 --- a/src/main/java/io/milvus/v2/service/vector/request/QueryReq.java +++ b/src/main/java/io/milvus/v2/service/vector/request/QueryReq.java @@ -15,13 +15,10 @@ public class QueryReq { @Builder.Default private List partitionNames = new ArrayList<>(); private List outputFields; - private String expr; - private long travelTimestamp; - private long guaranteeTimestamp; - private long gracefulTime; + private List ids; + private String filter; @Builder.Default private ConsistencyLevel consistencyLevel = ConsistencyLevel.BOUNDED; private long offset; private long limit; - private boolean ignoreGrowing; } diff --git a/src/main/java/io/milvus/v2/service/vector/request/SearchReq.java b/src/main/java/io/milvus/v2/service/vector/request/SearchReq.java index 026c23988..8e906eaa0 100644 --- a/src/main/java/io/milvus/v2/service/vector/request/SearchReq.java +++ b/src/main/java/io/milvus/v2/service/vector/request/SearchReq.java @@ -16,9 +16,9 @@ public class SearchReq { private List partitionNames = new ArrayList<>(); private String vectorFieldName; private int topK; - private String expr; - private List outFields; - private List vectors; + private String filter; + private List outputFields; + private List data; private long offset; private long limit; @@ -26,7 +26,7 @@ public class SearchReq { @Builder.Default private int roundDecimal = -1; @Builder.Default - private String params = "{\"nprobe\": 10}"; + private String searchParams = "{}"; private long guaranteeTimestamp; @Builder.Default private Long gracefulTime = 5000L; diff --git a/src/main/java/io/milvus/v2/service/vector/request/UpsertReq.java b/src/main/java/io/milvus/v2/service/vector/request/UpsertReq.java index a4e828b98..2a64128aa 100644 --- a/src/main/java/io/milvus/v2/service/vector/request/UpsertReq.java +++ b/src/main/java/io/milvus/v2/service/vector/request/UpsertReq.java @@ -5,19 +5,13 @@ import lombok.Data; import lombok.experimental.SuperBuilder; -import java.util.ArrayList; import java.util.List; -import java.util.Map; @Data @SuperBuilder public class UpsertReq { - private List> upsertData; + private List data; private String collectionName; @Builder.Default private String partitionName = ""; - - public List getUpsertData() { - return new ArrayList(); - } } diff --git a/src/main/java/io/milvus/v2/service/vector/response/DeleteResp.java b/src/main/java/io/milvus/v2/service/vector/response/DeleteResp.java new file mode 100644 index 000000000..8a7202d94 --- /dev/null +++ b/src/main/java/io/milvus/v2/service/vector/response/DeleteResp.java @@ -0,0 +1,10 @@ +package io.milvus.v2.service.vector.response; + +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class DeleteResp { + private long deleteCnt; +} diff --git a/src/main/java/io/milvus/v2/service/vector/response/InsertResp.java b/src/main/java/io/milvus/v2/service/vector/response/InsertResp.java new file mode 100644 index 000000000..2b6994e62 --- /dev/null +++ b/src/main/java/io/milvus/v2/service/vector/response/InsertResp.java @@ -0,0 +1,10 @@ +package io.milvus.v2.service.vector.response; + +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class InsertResp { + private long InsertCnt; +} diff --git a/src/main/java/io/milvus/v2/service/vector/response/UpsertResp.java b/src/main/java/io/milvus/v2/service/vector/response/UpsertResp.java new file mode 100644 index 000000000..e42b1cba4 --- /dev/null +++ b/src/main/java/io/milvus/v2/service/vector/response/UpsertResp.java @@ -0,0 +1,10 @@ +package io.milvus.v2.service.vector.response; + +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class UpsertResp { + private long upsertCnt; +} diff --git a/src/main/java/io/milvus/v2/utils/ClientUtils.java b/src/main/java/io/milvus/v2/utils/ClientUtils.java index 900f94516..c236a66b1 100644 --- a/src/main/java/io/milvus/v2/utils/ClientUtils.java +++ b/src/main/java/io/milvus/v2/utils/ClientUtils.java @@ -30,8 +30,8 @@ public ManagedChannel getChannel(ConnectConfig connectConfig){ Metadata metadata = new Metadata(); metadata.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), Base64.getEncoder().encodeToString(connectConfig.getAuthorization().getBytes(StandardCharsets.UTF_8))); - if (StringUtils.isNotEmpty(connectConfig.getDatabaseName())) { - metadata.put(Metadata.Key.of("dbname", Metadata.ASCII_STRING_MARSHALLER), connectConfig.getDatabaseName()); + if (StringUtils.isNotEmpty(connectConfig.getDbName())) { + metadata.put(Metadata.Key.of("dbname", Metadata.ASCII_STRING_MARSHALLER), connectConfig.getDbName()); } try { diff --git a/src/main/java/io/milvus/v2/utils/ConvertUtils.java b/src/main/java/io/milvus/v2/utils/ConvertUtils.java index a5da5a109..76ce0318f 100644 --- a/src/main/java/io/milvus/v2/utils/ConvertUtils.java +++ b/src/main/java/io/milvus/v2/utils/ConvertUtils.java @@ -1,7 +1,6 @@ package io.milvus.v2.utils; import io.milvus.grpc.*; -import io.milvus.param.R; import io.milvus.response.QueryResultsWrapper; import io.milvus.response.SearchResultsWrapper; import io.milvus.v2.service.index.response.DescribeIndexResp; @@ -49,7 +48,7 @@ public List getEntities(SearchResults response) { .build()).collect(Collectors.toList()); } - public R convertToDescribeIndexResp(DescribeIndexResponse response) { + public DescribeIndexResp convertToDescribeIndexResp(DescribeIndexResponse response) { DescribeIndexResp describeIndexResp = DescribeIndexResp.builder() .indexName(response.getIndexDescriptions(0).getIndexName()) .fieldName(response.getIndexDescriptions(0).getFieldName()) @@ -62,6 +61,6 @@ public R convertToDescribeIndexResp(DescribeIndexResponse res describeIndexResp.setMetricType(param.getValue()); } } - return R.success(describeIndexResp); + return describeIndexResp; } } diff --git a/src/main/java/io/milvus/v2/utils/DataUtils.java b/src/main/java/io/milvus/v2/utils/DataUtils.java index 1c6a7e688..341f812dc 100644 --- a/src/main/java/io/milvus/v2/utils/DataUtils.java +++ b/src/main/java/io/milvus/v2/utils/DataUtils.java @@ -14,7 +14,6 @@ import io.milvus.v2.service.vector.request.InsertReq; import io.milvus.v2.service.vector.request.UpsertReq; import lombok.NonNull; -import org.apache.commons.lang3.StringUtils; import java.nio.ByteBuffer; import java.util.*; @@ -37,7 +36,7 @@ public InsertRequest convertGrpcInsertRequest(@NonNull InsertReq requestParam, insertBuilder = InsertRequest.newBuilder() .setCollectionName(collectionName) .setBase(msgBase) - .setNumRows(requestParam.getInsertData().size()); + .setNumRows(requestParam.getData().size()); // if (StringUtils.isNotEmpty(requestParam.getDatabaseName())) { // insertBuilder.setDbName(requestParam.getDatabaseName()); // } @@ -60,7 +59,7 @@ public UpsertRequest convertGrpcUpsertRequest(@NonNull UpsertReq requestParam, upsertBuilder = UpsertRequest.newBuilder() .setCollectionName(collectionName) .setBase(msgBase) - .setNumRows(requestParam.getUpsertData().size()); + .setNumRows(requestParam.getData().size()); // if (StringUtils.isNotEmpty(requestParam.getDatabaseName())) { // upsertBuilder.setDbName(requestParam.getDatabaseName()); // } @@ -104,7 +103,7 @@ private void fillFieldsData(UpsertReq requestParam, DescCollResponseWrapper wrap } // convert insert data - List rowFields = requestParam.getUpsertData(); + List rowFields = requestParam.getData(); checkAndSetRowData(wrapper, rowFields); @@ -130,7 +129,7 @@ private void fillFieldsData(InsertReq requestParam, DescCollResponseWrapper wrap } // convert insert data - List rowFields = requestParam.getInsertData(); + List rowFields = requestParam.getData(); checkAndSetRowData(wrapper, rowFields); diff --git a/src/main/java/io/milvus/v2/utils/RpcUtils.java b/src/main/java/io/milvus/v2/utils/RpcUtils.java index baabee922..28a3c5db2 100644 --- a/src/main/java/io/milvus/v2/utils/RpcUtils.java +++ b/src/main/java/io/milvus/v2/utils/RpcUtils.java @@ -1,8 +1,8 @@ package io.milvus.v2.utils; -import io.milvus.exception.ServerException; -import io.milvus.grpc.ErrorCode; import io.milvus.grpc.Status; +import io.milvus.v2.exception.ErrorCode; +import io.milvus.v2.exception.MilvusClientException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,17 +21,16 @@ public void handleResponse(String requestInfo, Status status) { // if we use 2.3.4 sdk to interact with 2.2.x server, getCode() is zero, getErrorCode() is non-zero // if we use <=2.3.3 sdk to interact with 2.2.x/2.3.x server, getCode() is not available, getErrorCode() is non-zero - if (status.getCode() != 0 || !status.getErrorCode().equals(ErrorCode.Success)) { - logger.error("{} failed, error code: {}, reason: {}", requestInfo, - status.getCode() > 0 ? status.getCode() : status.getErrorCode().getNumber(), - status.getReason()); + if (status.getCode() != 0 || !status.getErrorCode().equals(io.milvus.grpc.ErrorCode.Success)) { // 2.3.4 sdk to interact with 2.2.x server, the getCode() is zero, here we reset its value to getErrorCode() int code = status.getCode(); if (code == 0) { code = status.getErrorCode().getNumber(); } - throw new ServerException(status.getReason(), code, status.getErrorCode()); + logger.error("{} failed, error code: {}, reason: {}", requestInfo, ErrorCode.SERVER_ERROR.getCode(), + status.getReason()); + throw new MilvusClientException(ErrorCode.SERVER_ERROR, status.getReason()); } logger.debug("{} successfully!", requestInfo); diff --git a/src/main/java/io/milvus/v2/utils/VectorUtils.java b/src/main/java/io/milvus/v2/utils/VectorUtils.java index a828f80e4..8e8e45c75 100644 --- a/src/main/java/io/milvus/v2/utils/VectorUtils.java +++ b/src/main/java/io/milvus/v2/utils/VectorUtils.java @@ -2,7 +2,6 @@ import com.google.protobuf.ByteString; import io.milvus.common.clientenum.ConsistencyLevelEnum; -import io.milvus.common.utils.JacksonUtils; import io.milvus.exception.ParamException; import io.milvus.grpc.*; import io.milvus.param.Constant; @@ -11,23 +10,18 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; public class VectorUtils { public QueryRequest ConvertToGrpcQueryRequest(QueryReq request){ - long guaranteeTimestamp = getGuaranteeTimestamp(ConsistencyLevelEnum.valueOf(request.getConsistencyLevel().name()), - request.getGuaranteeTimestamp(), request.getGracefulTime()); +// long guaranteeTimestamp = getGuaranteeTimestamp(ConsistencyLevelEnum.valueOf(request.getConsistencyLevel().name()), +// request.getGuaranteeTimestamp(), request.getGracefulTime()); QueryRequest.Builder builder = QueryRequest.newBuilder() .setCollectionName(request.getCollectionName()) .addAllPartitionNames(request.getPartitionNames()) .addAllOutputFields(request.getOutputFields()) - .setExpr(request.getExpr()) - .setTravelTimestamp(request.getTravelTimestamp()) - .setGuaranteeTimestamp(guaranteeTimestamp); + .setExpr(request.getFilter()); // a new parameter from v2.2.9, if user didn't specify consistency level, set this parameter to true if (request.getConsistencyLevel() == null) { @@ -55,10 +49,10 @@ public QueryRequest ConvertToGrpcQueryRequest(QueryReq request){ } // ignore growing - builder.addQueryParams(KeyValuePair.newBuilder() - .setKey(Constant.IGNORE_GROWING) - .setValue(String.valueOf(request.isIgnoreGrowing())) - .build()); +// builder.addQueryParams(KeyValuePair.newBuilder() +// .setKey(Constant.IGNORE_GROWING) +// .setValue(String.valueOf(request.isIgnoreGrowing())) +// .build()); return builder.build(); @@ -101,7 +95,7 @@ public SearchRequest ConvertToGrpcSearchRequest(String metricType, SearchReq req // prepare target vectors // TODO: check target vector dimension(use DescribeCollection get schema to compare) PlaceholderType plType = PlaceholderType.None; - List vectors = request.getVectors(); + List vectors = request.getData(); List byteStrings = new ArrayList<>(); for (Object vector : vectors) { if (vector instanceof List) { @@ -168,26 +162,26 @@ public SearchRequest ConvertToGrpcSearchRequest(String metricType, SearchReq req .setValue(String.valueOf(request.getOffset())) .build()); - if (null != request.getParams() && !request.getParams().isEmpty()) { + if (null != request.getSearchParams() && !request.getSearchParams().isEmpty()) { try { builder.addSearchParams( KeyValuePair.newBuilder() .setKey(Constant.PARAMS) - .setValue(request.getParams()) + .setValue(request.getSearchParams()) .build()); } catch (IllegalArgumentException e) { throw new ParamException(e.getMessage() + e.getCause().getMessage()); } } - if (!request.getOutFields().isEmpty()) { - request.getOutFields().forEach(builder::addOutputFields); + if (!request.getOutputFields().isEmpty()) { + request.getOutputFields().forEach(builder::addOutputFields); } // always use expression since dsl is discarded builder.setDslType(DslType.BoolExprV1); - if (request.getExpr() != null && !request.getExpr().isEmpty()) { - builder.setDsl(request.getExpr()); + if (request.getFilter() != null && !request.getFilter().isEmpty()) { + builder.setDsl(request.getFilter()); } long guaranteeTimestamp = getGuaranteeTimestamp(ConsistencyLevelEnum.valueOf(request.getConsistencyLevel().name()), diff --git a/src/test/java/io/milvus/v2/BaseTest.java b/src/test/java/io/milvus/v2/BaseTest.java index 52b55eebc..4daf9e553 100644 --- a/src/test/java/io/milvus/v2/BaseTest.java +++ b/src/test/java/io/milvus/v2/BaseTest.java @@ -83,6 +83,7 @@ public void setUp() { when(blockingStub.describeCollection(any())).thenReturn(describeCollectionResponse); when(blockingStub.renameCollection(any())).thenReturn(successStatus); when(blockingStub.getLoadState(any())).thenReturn(GetLoadStateResponse.newBuilder().setStatus(successStatus).build()); + when(blockingStub.getCollectionStatistics(any())).thenReturn(GetCollectionStatisticsResponse.newBuilder().addStats(KeyValuePair.newBuilder().setKey("row_count").setValue("10").build()).setStatus(successStatus).build()); // index api when(blockingStub.createIndex(any())).thenReturn(successStatus); @@ -90,10 +91,10 @@ public void setUp() { when(blockingStub.dropIndex(any())).thenReturn(successStatus); //vector api - when(blockingStub.insert(any())).thenReturn(MutationResult.newBuilder().build()); - when(blockingStub.upsert(any())).thenReturn(MutationResult.newBuilder().build()); + when(blockingStub.insert(any())).thenReturn(MutationResult.newBuilder().setInsertCnt(2L).build()); + when(blockingStub.upsert(any())).thenReturn(MutationResult.newBuilder().setUpsertCnt(2L).build()); when(blockingStub.query(any())).thenReturn(QueryResults.newBuilder().build()); - when(blockingStub.delete(any())).thenReturn(MutationResult.newBuilder().build()); + when(blockingStub.delete(any())).thenReturn(MutationResult.newBuilder().setDeleteCnt(2L).build()); SearchResults searchResults = SearchResults.newBuilder() .setResults(SearchResultData.newBuilder().addScores(1L).addTopks(0L).build()) .build(); @@ -129,6 +130,7 @@ public void setUp() { when(blockingStub.dropAlias(any())).thenReturn(successStatus); when(blockingStub.alterAlias(any())).thenReturn(successStatus); when(blockingStub.describeAlias(any())).thenReturn(DescribeAliasResponse.newBuilder().setStatus(successStatus).build()); + when(blockingStub.listAliases(any())).thenReturn(ListAliasesResponse.newBuilder().setStatus(successStatus).addAliases("test").build()); } @AfterEach public void tearDown() throws InterruptedException { diff --git a/src/test/java/io/milvus/v2/service/collection/CollectionTest.java b/src/test/java/io/milvus/v2/service/collection/CollectionTest.java index 984902a2b..6a13a1f99 100644 --- a/src/test/java/io/milvus/v2/service/collection/CollectionTest.java +++ b/src/test/java/io/milvus/v2/service/collection/CollectionTest.java @@ -1,34 +1,24 @@ package io.milvus.v2.service.collection; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.v2.common.DataType; import io.milvus.v2.BaseTest; +import io.milvus.v2.common.DataType; +import io.milvus.v2.common.IndexParam; import io.milvus.v2.service.collection.request.*; import io.milvus.v2.service.collection.response.DescribeCollectionResp; +import io.milvus.v2.service.collection.response.GetCollectionStatsResp; import io.milvus.v2.service.collection.response.ListCollectionsResp; -import io.milvus.v2.common.IndexParam; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; - -import static org.mockito.ArgumentMatchers.any; class CollectionTest extends BaseTest { Logger logger = LoggerFactory.getLogger(CollectionTest.class); @Test void testListCollections() { - R a = client_v2.listCollections(); - - logger.info("resp: {}", a.getData()); - Assertions.assertEquals(R.Status.Success.getCode(), a.getStatus()); - Assertions.assertEquals("test", a.getData().getCollectionNames().get(0)); + ListCollectionsResp a = client_v2.listCollections(); } @Test @@ -37,42 +27,43 @@ void testCreateCollection() { .collectionName("test2") .dimension(2) .build(); - R resp = client_v2.createCollection(req); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.createCollection(req); } @Test void testCreateCollectionWithSchema() { - List fields = new ArrayList<>(); - CreateCollectionWithSchemaReq.FieldSchema idSchema = CreateCollectionWithSchemaReq.FieldSchema.builder() - .name("id") - .dataType(DataType.Int64) - .isPrimaryKey(Boolean.TRUE) - .autoID(Boolean.FALSE) - .build(); - CreateCollectionWithSchemaReq.FieldSchema metaSchema = CreateCollectionWithSchemaReq.FieldSchema.builder() - .name("meta") - .dataType(DataType.VarChar) - .build(); - CreateCollectionWithSchemaReq.FieldSchema vectorSchema = CreateCollectionWithSchemaReq.FieldSchema.builder() - .name("vector") - .dataType(DataType.FloatVector) - .dimension(2) - .build(); - - fields.add(idSchema); - fields.add(vectorSchema); - fields.add(metaSchema); +// List fields = new ArrayList<>(); +// CreateCollectionWithSchemaReq.FieldSchema idSchema = CreateCollectionWithSchemaReq.FieldSchema.builder() +// .name("id") +// .dataType(DataType.Int64) +// .isPrimaryKey(Boolean.TRUE) +// .autoID(Boolean.FALSE) +// .build(); +// CreateCollectionWithSchemaReq.FieldSchema metaSchema = CreateCollectionWithSchemaReq.FieldSchema.builder() +// .name("meta") +// .dataType(DataType.VarChar) +// .build(); +// CreateCollectionWithSchemaReq.FieldSchema vectorSchema = CreateCollectionWithSchemaReq.FieldSchema.builder() +// .name("vector") +// .dataType(DataType.FloatVector) +// .dimension(2) +// .build(); +// +// fields.add(idSchema); +// fields.add(vectorSchema); +// fields.add(metaSchema); CreateCollectionWithSchemaReq.CollectionSchema collectionSchema = CreateCollectionWithSchemaReq.CollectionSchema.builder() - .fieldSchemaList(fields) .enableDynamicField(Boolean.TRUE) .build(); + collectionSchema.addPrimaryField("id", DataType.Int64, null, Boolean.TRUE, Boolean.FALSE); + collectionSchema.addVectorField("vector", DataType.FloatVector,8); + collectionSchema.addScalarField("meta", DataType.VarChar, 100); + collectionSchema.addScalarField("age", DataType.Int64); IndexParam indexParam = IndexParam.builder() .fieldName("vector") .metricType(IndexParam.MetricType.L2) - .indexType(IndexParam.IndexType.AUTOINDEX) .build(); CreateCollectionWithSchemaReq request = CreateCollectionWithSchemaReq.builder() @@ -80,8 +71,7 @@ void testCreateCollectionWithSchema() { .collectionSchema(collectionSchema) .indexParams(Collections.singletonList(indexParam)) .build(); - R resp = client_v2.createCollectionWithSchema(request); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.createCollectionWithSchema(request); } @Test @@ -89,8 +79,7 @@ void testDropCollection() { DropCollectionReq req = DropCollectionReq.builder() .collectionName("test") .build(); - R resp = client_v2.dropCollection(req); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.dropCollection(req); } @Test @@ -98,18 +87,15 @@ void testHasCollection() { HasCollectionReq req = HasCollectionReq.builder() .collectionName("test") .build(); - R resp = client_v2.hasCollection(req); - logger.info("resp: {}", resp.getData()); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + Boolean resp = client_v2.hasCollection(req); } @Test void testDescribeCollection() { DescribeCollectionReq req = DescribeCollectionReq.builder() .collectionName("test2") .build(); - R resp = client_v2.describeCollection(req); + DescribeCollectionResp resp = client_v2.describeCollection(req); logger.info("resp: {}", resp); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); } @Test @@ -118,8 +104,7 @@ void testRenameCollection() { .collectionName("test2") .newCollectionName("test") .build(); - R resp = client_v2.renameCollection(req); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.renameCollection(req); } @Test @@ -127,8 +112,8 @@ void testLoadCollection() { LoadCollectionReq req = LoadCollectionReq.builder() .collectionName("test") .build(); - R resp = client_v2.loadCollection(req); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.loadCollection(req); + } @Test @@ -136,8 +121,7 @@ void testReleaseCollection() { ReleaseCollectionReq req = ReleaseCollectionReq.builder() .collectionName("test") .build(); - R resp = client_v2.releaseCollection(req); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.releaseCollection(req); } @Test @@ -145,18 +129,15 @@ void testGetLoadState() { GetLoadStateReq req = GetLoadStateReq.builder() .collectionName("test") .build(); - R resp = client_v2.getLoadState(req); - logger.info("resp: {}", resp.getData()); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + Boolean resp = client_v2.getLoadState(req); + logger.info("resp: {}", resp); } -// @Test -// void testGetCollectionStats() { -// GetCollectionStatsReq req = GetCollectionStatsReq.builder() -// .collectionName("test") -// .build(); -// R resp = clientv_2.getCollectionStats(req); -// logger.info("resp: {}", resp); -// Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); -// } + @Test + void testGetCollectionStats() { + GetCollectionStatsReq req = GetCollectionStatsReq.builder() + .collectionName("test") + .build(); + GetCollectionStatsResp resp = client_v2.getCollectionStats(req); + } } \ No newline at end of file diff --git a/src/test/java/io/milvus/v2/service/index/IndexTest.java b/src/test/java/io/milvus/v2/service/index/IndexTest.java index e554ac5be..a4c1379a3 100644 --- a/src/test/java/io/milvus/v2/service/index/IndexTest.java +++ b/src/test/java/io/milvus/v2/service/index/IndexTest.java @@ -1,32 +1,40 @@ package io.milvus.v2.service.index; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.v2.common.IndexParam; import io.milvus.v2.BaseTest; +import io.milvus.v2.common.IndexParam; import io.milvus.v2.service.index.request.CreateIndexReq; import io.milvus.v2.service.index.request.DescribeIndexReq; import io.milvus.v2.service.index.request.DropIndexReq; import io.milvus.v2.service.index.response.DescribeIndexResp; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + class IndexTest extends BaseTest { Logger logger = LoggerFactory.getLogger(IndexTest.class); @Test void testCreateIndex() { + // vector index IndexParam indexParam = IndexParam.builder() .metricType(IndexParam.MetricType.COSINE) .indexType(IndexParam.IndexType.AUTOINDEX) .fieldName("vector") .build(); - + // scalar index + IndexParam scalarIndexParam = IndexParam.builder() + .indexType(IndexParam.IndexType.AUTOINDEX) + .fieldName("age") + .build(); + List indexParams = new ArrayList<>(); + indexParams.add(indexParam); + indexParams.add(scalarIndexParam); CreateIndexReq createIndexReq = CreateIndexReq.builder() .collectionName("test") - .indexParam(indexParam) + .indexParams(indexParams) .build(); client_v2.createIndex(createIndexReq); } @@ -36,7 +44,7 @@ void testDescribeIndex() { .collectionName("test") .fieldName("vector") .build(); - R responseR = client_v2.describeIndex(describeIndexReq); + DescribeIndexResp responseR = client_v2.describeIndex(describeIndexReq); logger.info(responseR.toString()); } @Test @@ -45,7 +53,6 @@ void testDropIndex() { .collectionName("test") .fieldName("vector") .build(); - R resp = client_v2.dropIndex(dropIndexReq); - Assertions.assertEquals(R.Status.Success.getCode(), resp.getStatus()); + client_v2.dropIndex(dropIndexReq); } } \ No newline at end of file diff --git a/src/test/java/io/milvus/v2/service/partition/PartitionTest.java b/src/test/java/io/milvus/v2/service/partition/PartitionTest.java index c12653be7..18b80dea1 100644 --- a/src/test/java/io/milvus/v2/service/partition/PartitionTest.java +++ b/src/test/java/io/milvus/v2/service/partition/PartitionTest.java @@ -1,10 +1,7 @@ package io.milvus.v2.service.partition; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.BaseTest; import io.milvus.v2.service.partition.request.*; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,9 +18,7 @@ void testCreatePartition() { .collectionName("test") .partitionName("test") .build(); - R res = client_v2.createPartition(req); - logger.info("resp: {}", res); - Assertions.assertEquals(0, res.getStatus()); + client_v2.createPartition(req); } @Test @@ -32,9 +27,7 @@ void testDropPartition() { .collectionName("test") .partitionName("test") .build(); - R res = client_v2.dropPartition(req); - logger.info("resp: {}", res); - Assertions.assertEquals(0, res.getStatus()); + client_v2.dropPartition(req); } @Test @@ -43,9 +36,7 @@ void testHasPartition() { .collectionName("test") .partitionName("_default") .build(); - R res = client_v2.hasPartition(req); - logger.info("resp: {}", res); - Assertions.assertEquals(0, res.getStatus()); + Boolean res = client_v2.hasPartition(req); } @Test @@ -53,9 +44,8 @@ void testListPartitions() { ListPartitionsReq req = ListPartitionsReq.builder() .collectionName("test") .build(); - R> res = client_v2.listPartitions(req); + List res = client_v2.listPartitions(req); logger.info("resp: {}", res); - Assertions.assertEquals(0, res.getStatus()); } @Test @@ -66,9 +56,8 @@ void testLoadPartition() { .collectionName("test") .partitionNames(partitionNames) .build(); - R res = client_v2.loadPartitions(req); - logger.info("resp: {}", res); - Assertions.assertEquals(0, res.getStatus()); + client_v2.loadPartitions(req); + } @Test @@ -80,8 +69,7 @@ void testReleasePartition() { .collectionName("test") .partitionNames(partitionNames) .build(); - R res = client_v2.releasePartitions(req); - logger.info("resp: {}", res); - Assertions.assertEquals(0, res.getStatus()); + client_v2.releasePartitions(req); + } } \ No newline at end of file diff --git a/src/test/java/io/milvus/v2/service/rbac/RoleTest.java b/src/test/java/io/milvus/v2/service/rbac/RoleTest.java index ba6a90d2b..cb5a2715e 100644 --- a/src/test/java/io/milvus/v2/service/rbac/RoleTest.java +++ b/src/test/java/io/milvus/v2/service/rbac/RoleTest.java @@ -1,11 +1,7 @@ package io.milvus.v2.service.rbac; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.BaseTest; import io.milvus.v2.service.rbac.request.*; -import io.milvus.v2.service.rbac.response.DescribeRoleResp; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,9 +14,7 @@ class RoleTest extends BaseTest { @Test void testListRoles() { - R> roles = client_v2.listRoles(); - logger.info(roles.toString()); - Assertions.assertEquals(roles.getStatus(), R.Status.Success.getCode()); + List roles = client_v2.listRoles(); } @Test @@ -28,9 +22,7 @@ void testCreateRole() { CreateRoleReq request = CreateRoleReq.builder() .roleName("test") .build(); - R statusR = client_v2.createRole(request); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.createRole(request); } @Test @@ -38,9 +30,7 @@ void testDescribeRole() { DescribeRoleReq describeRoleReq = DescribeRoleReq.builder() .roleName("db_rw") .build(); - R statusR = client_v2.describeRole(describeRoleReq); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.describeRole(describeRoleReq); } @Test @@ -48,9 +38,7 @@ void testDropRole() { DropRoleReq request = DropRoleReq.builder() .roleName("test") .build(); - R statusR = client_v2.dropRole(request); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.dropRole(request); } @Test @@ -61,9 +49,7 @@ void testGrantPrivilege() { .objectType("") .privilege("") .build(); - R statusR = client_v2.grantPrivilege(request); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.grantPrivilege(request); } @Test @@ -74,9 +60,7 @@ void testRevokePrivilege() { .objectType("") .privilege("") .build(); - R statusR = client_v2.revokePrivilege(request); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.revokePrivilege(request); } @Test @@ -85,9 +69,7 @@ void testGrantRole() { .roleName("db_ro") .userName("test") .build(); - R statusR = client_v2.grantRole(request); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.grantRole(request); } @Test @@ -96,8 +78,6 @@ void testRevokeRole() { .roleName("db_ro") .userName("test") .build(); - R statusR = client_v2.revokeRole(request); - logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + client_v2.revokeRole(request); } } \ No newline at end of file diff --git a/src/test/java/io/milvus/v2/service/rbac/UserTest.java b/src/test/java/io/milvus/v2/service/rbac/UserTest.java index 4178a9690..e65c86ad3 100644 --- a/src/test/java/io/milvus/v2/service/rbac/UserTest.java +++ b/src/test/java/io/milvus/v2/service/rbac/UserTest.java @@ -1,11 +1,11 @@ package io.milvus.v2.service.rbac; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.BaseTest; -import io.milvus.v2.service.rbac.request.*; +import io.milvus.v2.service.rbac.request.CreateUserReq; +import io.milvus.v2.service.rbac.request.DescribeUserReq; +import io.milvus.v2.service.rbac.request.DropUserReq; +import io.milvus.v2.service.rbac.request.UpdatePasswordReq; import io.milvus.v2.service.rbac.response.DescribeUserResp; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,9 +17,8 @@ class UserTest extends BaseTest { @Test void listUsers() { - R> resp = client_v2.listUsers(); + List resp = client_v2.listUsers(); logger.info("resp: {}", resp); - Assertions.assertEquals(resp.getStatus(), R.Status.Success.getCode()); } @Test @@ -27,9 +26,8 @@ void testDescribeUser() { DescribeUserReq req = DescribeUserReq.builder() .userName("test") .build(); - R resp = client_v2.describeUser(req); + DescribeUserResp resp = client_v2.describeUser(req); logger.info("resp: {}", resp); - Assertions.assertEquals(resp.getStatus(), R.Status.Success.getCode()); } @Test @@ -38,9 +36,8 @@ void testCreateUser() { .userName("test") .password("Zilliz@2023") .build(); - R resp = client_v2.createUser(req); - logger.info("resp: {}", resp); - Assertions.assertEquals(resp.getStatus(), R.Status.Success.getCode()); + client_v2.createUser(req); + } @Test @@ -50,9 +47,7 @@ void testUpdatePassword() { .password("Zilliz@2023") .newPassword("Zilliz@2024") .build(); - R resp = client_v2.updatePassword(req); - logger.info("resp: {}", resp); - Assertions.assertEquals(resp.getStatus(), R.Status.Success.getCode()); + client_v2.updatePassword(req); } @Test @@ -60,8 +55,7 @@ void testDropUser() { DropUserReq req = DropUserReq.builder() .userName("test") .build(); - R resp = client_v2.dropUser(req); - logger.info("resp: {}", resp); - Assertions.assertEquals(resp.getStatus(), R.Status.Success.getCode()); + client_v2.dropUser(req); + } } \ No newline at end of file diff --git a/src/test/java/io/milvus/v2/service/utility/UtilityTest.java b/src/test/java/io/milvus/v2/service/utility/UtilityTest.java index d5bf0f3ae..b2a11247a 100644 --- a/src/test/java/io/milvus/v2/service/utility/UtilityTest.java +++ b/src/test/java/io/milvus/v2/service/utility/UtilityTest.java @@ -1,49 +1,33 @@ package io.milvus.v2.service.utility; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; -import io.milvus.v2.service.utility.request.FlushReq; import io.milvus.v2.BaseTest; import io.milvus.v2.service.utility.request.AlterAliasReq; import io.milvus.v2.service.utility.request.CreateAliasReq; import io.milvus.v2.service.utility.request.DropAliasReq; +import io.milvus.v2.service.utility.response.DescribeAliasResp; +import io.milvus.v2.service.utility.response.ListAliasResp; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.jupiter.api.Assertions.*; - class UtilityTest extends BaseTest { Logger logger = LoggerFactory.getLogger(UtilityTest.class); - @Test - void testFlush() { - FlushReq req = FlushReq.builder() - .collectionName("test") - .build(); - R statusR = client_v2.flush(req); - logger.info("resp: {}", statusR.getData()); - assertEquals(R.Status.Success.getCode(), statusR.getStatus()); - } - @Test void testCreateAlias() { CreateAliasReq req = CreateAliasReq.builder() .collectionName("test") .alias("test_alias") .build(); - R statusR = client_v2.createAlias(req); - logger.info("resp: {}", statusR.getData()); - assertEquals(R.Status.Success.getCode(), statusR.getStatus()); + client_v2.createAlias(req); } + @Test void testDropAlias() { DropAliasReq req = DropAliasReq.builder() .alias("test_alias") .build(); - R statusR = client_v2.dropAlias(req); - logger.info("resp: {}", statusR.getData()); - assertEquals(R.Status.Success.getCode(), statusR.getStatus()); + client_v2.dropAlias(req); } @Test void testAlterAlias() { @@ -51,20 +35,15 @@ void testAlterAlias() { .collectionName("test") .alias("test_alias") .build(); - R statusR = client_v2.alterAlias(req); - logger.info("resp: {}", statusR.getData()); - assertEquals(R.Status.Success.getCode(), statusR.getStatus()); + client_v2.alterAlias(req); + } + + @Test + void describeAlias() { + DescribeAliasResp statusR = client_v2.describeAlias("test_alias"); + } + @Test + void listAliases() { + ListAliasResp statusR = client_v2.listAliases(); } -// @Test -// void describeAlias() { -// R statusR = clientv_2.describeAlias("test_alias"); -// logger.info("resp: {}", statusR.getData()); -// assertEquals(R.Status.Success.getCode(), statusR.getStatus()); -// } -// @Test -// void listAliases() { -// R statusR = clientv_2.listAliases(); -// logger.info("resp: {}", statusR.getData()); -// assertEquals(R.Status.Success.getCode(), statusR.getStatus()); -// } } \ No newline at end of file diff --git a/src/test/java/io/milvus/v2/service/vector/VectorTest.java b/src/test/java/io/milvus/v2/service/vector/VectorTest.java index b9063f262..7a77f3760 100644 --- a/src/test/java/io/milvus/v2/service/vector/VectorTest.java +++ b/src/test/java/io/milvus/v2/service/vector/VectorTest.java @@ -1,19 +1,16 @@ package io.milvus.v2.service.vector; import com.alibaba.fastjson.JSONObject; -import io.milvus.param.R; -import io.milvus.param.RpcStatus; import io.milvus.v2.BaseTest; import io.milvus.v2.service.vector.request.*; -import io.milvus.v2.service.vector.response.GetResp; -import io.milvus.v2.service.vector.response.QueryResp; -import io.milvus.v2.service.vector.response.SearchResp; -import org.junit.jupiter.api.Assertions; +import io.milvus.v2.service.vector.response.*; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; class VectorTest extends BaseTest { @@ -30,11 +27,10 @@ void testInsert() { InsertReq request = InsertReq.builder() .collectionName("test2") - .insertData(Collections.singletonList(vector)) + .data(Collections.singletonList(vector)) .build(); - R statusR = client_v2.insert(request); + InsertResp statusR = client_v2.insert(request); logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); } @Test @@ -45,28 +41,27 @@ void testUpsert() { vectorList.add(2.0f); vectorList.add(3.0f); jsonObject.put("vector", vectorList); - //jsonObject.put("id", 0L); + jsonObject.put("id", 0L); UpsertReq request = UpsertReq.builder() .collectionName("test") - .upsertData(Collections.singletonList(jsonObject)) + .data(Collections.singletonList(jsonObject)) .build(); - R statusR = client_v2.upsert(request); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); + UpsertResp statusR = client_v2.upsert(request); + logger.info(statusR.toString()); } @Test void testQuery() { QueryReq req = QueryReq.builder() - .collectionName("test2") - .expr("") + .collectionName("book") + .ids(Collections.singletonList(0)) .limit(10) //.outputFields(Collections.singletonList("count(*)")) .build(); - R resultsR = client_v2.query(req); + QueryResp resultsR = client_v2.query(req); logger.info(resultsR.toString()); - Assertions.assertEquals(resultsR.getStatus(), R.Status.Success.getCode()); } @Test @@ -76,13 +71,12 @@ void testSearch() { vectorList.add(2.0f); SearchReq request = SearchReq.builder() .collectionName("test2") - .vectors(Collections.singletonList(vectorList)) + .data(Collections.singletonList(vectorList)) .topK(10) .offset(0L) .build(); - R statusR = client_v2.search(request); + SearchResp statusR = client_v2.search(request); logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); } @Test @@ -91,9 +85,8 @@ void testDelete() { .collectionName("test") .expr("id > 0") .build(); - R statusR = client_v2.delete(request); + DeleteResp statusR = client_v2.delete(request); logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); } @Test @@ -102,9 +95,8 @@ void testDeleteById(){ .collectionName("test") .ids(Collections.singletonList("0")) .build(); - R statusR = client_v2.delete(request); + DeleteResp statusR = client_v2.delete(request); logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); } @Test @@ -113,8 +105,7 @@ void testGet() { .collectionName("test2") .ids(Collections.singletonList("447198483337881033")) .build(); - R statusR = client_v2.get(request); + GetResp statusR = client_v2.get(request); logger.info(statusR.toString()); - Assertions.assertEquals(statusR.getStatus(), R.Status.Success.getCode()); } } \ No newline at end of file