|
@@ -23,6 +23,7 @@ import io.milvus.client.MilvusServiceClient;
|
|
import io.milvus.grpc.*;
|
|
import io.milvus.grpc.*;
|
|
import io.milvus.param.*;
|
|
import io.milvus.param.*;
|
|
import io.milvus.param.collection.*;
|
|
import io.milvus.param.collection.*;
|
|
|
|
+import io.milvus.param.control.ManualCompactionParam;
|
|
import io.milvus.param.dml.*;
|
|
import io.milvus.param.dml.*;
|
|
import io.milvus.param.index.*;
|
|
import io.milvus.param.index.*;
|
|
import io.milvus.param.partition.*;
|
|
import io.milvus.param.partition.*;
|
|
@@ -62,6 +63,12 @@ public class GeneralExample {
|
|
private static final Integer SEARCH_K = 5;
|
|
private static final Integer SEARCH_K = 5;
|
|
private static final String SEARCH_PARAM = "{\"nprobe\":10}";
|
|
private static final String SEARCH_PARAM = "{\"nprobe\":10}";
|
|
|
|
|
|
|
|
+ private void handleResponseStatus(R<?> r) {
|
|
|
|
+ if (r.getStatus() != R.Status.Success.getCode()) {
|
|
|
|
+ throw new RuntimeException(r.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private R<RpcStatus> createCollection() {
|
|
private R<RpcStatus> createCollection() {
|
|
System.out.println("========== createCollection() ==========");
|
|
System.out.println("========== createCollection() ==========");
|
|
FieldType fieldType1 = FieldType.newBuilder()
|
|
FieldType fieldType1 = FieldType.newBuilder()
|
|
@@ -102,7 +109,7 @@ public class GeneralExample {
|
|
// .addFieldType(fieldType4)
|
|
// .addFieldType(fieldType4)
|
|
.build();
|
|
.build();
|
|
R<RpcStatus> response = milvusClient.createCollection(createCollectionReq);
|
|
R<RpcStatus> response = milvusClient.createCollection(createCollectionReq);
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -121,7 +128,7 @@ public class GeneralExample {
|
|
R<Boolean> response = milvusClient.hasCollection(HasCollectionParam.newBuilder()
|
|
R<Boolean> response = milvusClient.hasCollection(HasCollectionParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -131,6 +138,7 @@ public class GeneralExample {
|
|
R<RpcStatus> response = milvusClient.loadCollection(LoadCollectionParam.newBuilder()
|
|
R<RpcStatus> response = milvusClient.loadCollection(LoadCollectionParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -140,6 +148,7 @@ public class GeneralExample {
|
|
R<RpcStatus> response = milvusClient.releaseCollection(ReleaseCollectionParam.newBuilder()
|
|
R<RpcStatus> response = milvusClient.releaseCollection(ReleaseCollectionParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -149,6 +158,7 @@ public class GeneralExample {
|
|
R<DescribeCollectionResponse> response = milvusClient.describeCollection(DescribeCollectionParam.newBuilder()
|
|
R<DescribeCollectionResponse> response = milvusClient.describeCollection(DescribeCollectionParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
DescCollResponseWrapper wrapper = new DescCollResponseWrapper(response.getData());
|
|
DescCollResponseWrapper wrapper = new DescCollResponseWrapper(response.getData());
|
|
System.out.println(wrapper.toString());
|
|
System.out.println(wrapper.toString());
|
|
return response;
|
|
return response;
|
|
@@ -160,6 +170,7 @@ public class GeneralExample {
|
|
GetCollectionStatisticsParam.newBuilder()
|
|
GetCollectionStatisticsParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
GetCollStatResponseWrapper wrapper = new GetCollStatResponseWrapper(response.getData());
|
|
GetCollStatResponseWrapper wrapper = new GetCollStatResponseWrapper(response.getData());
|
|
System.out.println("Collection row count: " + wrapper.getRowCount());
|
|
System.out.println("Collection row count: " + wrapper.getRowCount());
|
|
return response;
|
|
return response;
|
|
@@ -169,6 +180,7 @@ public class GeneralExample {
|
|
System.out.println("========== showCollections() ==========");
|
|
System.out.println("========== showCollections() ==========");
|
|
R<ShowCollectionsResponse> response = milvusClient.showCollections(ShowCollectionsParam.newBuilder()
|
|
R<ShowCollectionsResponse> response = milvusClient.showCollections(ShowCollectionsParam.newBuilder()
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -179,7 +191,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withPartitionName(partitionName)
|
|
.withPartitionName(partitionName)
|
|
.build());
|
|
.build());
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -190,7 +202,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withPartitionName(partitionName)
|
|
.withPartitionName(partitionName)
|
|
.build());
|
|
.build());
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -201,7 +213,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withPartitionName(partitionName)
|
|
.withPartitionName(partitionName)
|
|
.build());
|
|
.build());
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -212,7 +224,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.addPartitionName(partitionName)
|
|
.addPartitionName(partitionName)
|
|
.build());
|
|
.build());
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -222,6 +234,7 @@ public class GeneralExample {
|
|
R<ShowPartitionsResponse> response = milvusClient.showPartitions(ShowPartitionsParam.newBuilder()
|
|
R<ShowPartitionsResponse> response = milvusClient.showPartitions(ShowPartitionsParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -236,6 +249,7 @@ public class GeneralExample {
|
|
.withExtraParam(INDEX_PARAM)
|
|
.withExtraParam(INDEX_PARAM)
|
|
.withSyncMode(Boolean.TRUE)
|
|
.withSyncMode(Boolean.TRUE)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -246,6 +260,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withFieldName(VECTOR_FIELD)
|
|
.withFieldName(VECTOR_FIELD)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -256,6 +271,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withFieldName(VECTOR_FIELD)
|
|
.withFieldName(VECTOR_FIELD)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -266,6 +282,7 @@ public class GeneralExample {
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withFieldName(VECTOR_FIELD)
|
|
.withFieldName(VECTOR_FIELD)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -276,6 +293,7 @@ public class GeneralExample {
|
|
GetIndexBuildProgressParam.newBuilder()
|
|
GetIndexBuildProgressParam.newBuilder()
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.withCollectionName(COLLECTION_NAME)
|
|
.build());
|
|
.build());
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -288,6 +306,7 @@ public class GeneralExample {
|
|
.withExpr(expr)
|
|
.withExpr(expr)
|
|
.build();
|
|
.build();
|
|
R<MutationResult> response = milvusClient.delete(build);
|
|
R<MutationResult> response = milvusClient.delete(build);
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response.getData());
|
|
System.out.println(response.getData());
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -309,9 +328,8 @@ public class GeneralExample {
|
|
.withParams(SEARCH_PARAM)
|
|
.withParams(SEARCH_PARAM)
|
|
.build();
|
|
.build();
|
|
|
|
|
|
-
|
|
|
|
R<SearchResults> response = milvusClient.search(searchParam);
|
|
R<SearchResults> response = milvusClient.search(searchParam);
|
|
-
|
|
|
|
|
|
+ handleResponseStatus(response);
|
|
SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
|
|
SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
|
|
for (int i = 0; i < vectors.size(); ++i) {
|
|
for (int i = 0; i < vectors.size(); ++i) {
|
|
System.out.println("Search result of No." + i);
|
|
System.out.println("Search result of No." + i);
|
|
@@ -343,7 +361,7 @@ public class GeneralExample {
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// R<SearchResults> response = milvusClient.search(searchParam);
|
|
// R<SearchResults> response = milvusClient.search(searchParam);
|
|
-//
|
|
|
|
|
|
+// handleResponseStatus(response);
|
|
// SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
|
|
// SearchResultsWrapper wrapper = new SearchResultsWrapper(response.getData().getResults());
|
|
// for (int i = 0; i < vectors.size(); ++i) {
|
|
// for (int i = 0; i < vectors.size(); ++i) {
|
|
// System.out.println("Search result of No." + i);
|
|
// System.out.println("Search result of No." + i);
|
|
@@ -372,6 +390,7 @@ public class GeneralExample {
|
|
.withMetricType(MetricType.L2)
|
|
.withMetricType(MetricType.L2)
|
|
.build();
|
|
.build();
|
|
R<CalcDistanceResults> response = milvusClient.calcDistance(calcDistanceParam);
|
|
R<CalcDistanceResults> response = milvusClient.calcDistance(calcDistanceParam);
|
|
|
|
+ handleResponseStatus(response);
|
|
System.out.println(response);
|
|
System.out.println(response);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
@@ -385,6 +404,7 @@ public class GeneralExample {
|
|
.withOutFields(fields)
|
|
.withOutFields(fields)
|
|
.build();
|
|
.build();
|
|
R<QueryResults> response = milvusClient.query(test);
|
|
R<QueryResults> response = milvusClient.query(test);
|
|
|
|
+ handleResponseStatus(response);
|
|
QueryResultsWrapper wrapper = new QueryResultsWrapper(response.getData());
|
|
QueryResultsWrapper wrapper = new QueryResultsWrapper(response.getData());
|
|
System.out.println(ID_FIELD + ":" + wrapper.getFieldWrapper(ID_FIELD).getFieldData().toString());
|
|
System.out.println(ID_FIELD + ":" + wrapper.getFieldWrapper(ID_FIELD).getFieldData().toString());
|
|
System.out.println(AGE_FIELD + ":" + wrapper.getFieldWrapper(AGE_FIELD).getFieldData().toString());
|
|
System.out.println(AGE_FIELD + ":" + wrapper.getFieldWrapper(AGE_FIELD).getFieldData().toString());
|
|
@@ -392,6 +412,15 @@ public class GeneralExample {
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private R<ManualCompactionResponse> compact() {
|
|
|
|
+ System.out.println("========== compact() ==========");
|
|
|
|
+ R<ManualCompactionResponse> response = milvusClient.manualCompaction(ManualCompactionParam.newBuilder()
|
|
|
|
+ .withCollectionName(COLLECTION_NAME)
|
|
|
|
+ .build());
|
|
|
|
+ handleResponseStatus(response);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
private R<MutationResult> insert(String partitionName, int count) {
|
|
private R<MutationResult> insert(String partitionName, int count) {
|
|
System.out.println("========== insert() ==========");
|
|
System.out.println("========== insert() ==========");
|
|
List<List<Float>> vectors = generateFloatVectors(count);
|
|
List<List<Float>> vectors = generateFloatVectors(count);
|
|
@@ -414,7 +443,9 @@ public class GeneralExample {
|
|
.withFields(fields)
|
|
.withFields(fields)
|
|
.build();
|
|
.build();
|
|
|
|
|
|
- return milvusClient.insert(insertParam);
|
|
|
|
|
|
+ R<MutationResult> response = milvusClient.insert(insertParam);
|
|
|
|
+ handleResponseStatus(response);
|
|
|
|
+ return response;
|
|
}
|
|
}
|
|
|
|
|
|
private List<List<Float>> generateFloatVectors(int count) {
|
|
private List<List<Float>> generateFloatVectors(int count) {
|
|
@@ -443,7 +474,6 @@ public class GeneralExample {
|
|
// vectors.add(vector);
|
|
// vectors.add(vector);
|
|
// }
|
|
// }
|
|
// return vectors;
|
|
// return vectors;
|
|
-//
|
|
|
|
// }
|
|
// }
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
@@ -486,8 +516,10 @@ public class GeneralExample {
|
|
// searchExpr = AGE_FIELD + " <= 30";
|
|
// searchExpr = AGE_FIELD + " <= 30";
|
|
// example.searchProfile(searchExpr);
|
|
// example.searchProfile(searchExpr);
|
|
example.calDistance();
|
|
example.calDistance();
|
|
|
|
+ example.compact();
|
|
|
|
+ example.getCollectionStatistics();
|
|
|
|
|
|
- example.releasePartition(partitionName);
|
|
|
|
|
|
+// example.releasePartition(partitionName); // releasing partitions after loading collection is not supported currently
|
|
example.releaseCollection();
|
|
example.releaseCollection();
|
|
example.dropPartition(partitionName);
|
|
example.dropPartition(partitionName);
|
|
example.dropIndex();
|
|
example.dropIndex();
|