未验证 提交 edd4c403 编写于 作者: D del-zhenwu 提交者: GitHub

[skip ci] add TestSearchEntities.java (#3433)

* [skip ci] add constants.java
Signed-off-by: Nzw <zw@milvus.io>

* [skip ci] add testIndex.java
Signed-off-by: Nzw <zw@milvus.io>

* [skip ci] add TestDeleteEntities.java
Signed-off-by: Nzw <zw@milvus.io>

* update TestSearchEntities.java
Signed-off-by: Nzw <zw@milvus.io>

* [skip ci] add TestSearchEntities.java
Signed-off-by: Nzw <zw@milvus.io>
Co-authored-by: Nzw <zw@milvus.io>
上级 30ecd17c
......@@ -10,8 +10,20 @@ public final class Constants {
public static final int n_list = 128;
public static final int n_probe = 64;
public static final int nq = 5;
public static final int topk = 10;
public static final int nb = 8000;
public static final double epsilon = 0.001;
public static final String vectorType = "float";
public static final String defaultMetricType = "L2";
public static final String indexType = "IVF_SQ8";
public static final String defaultIndexType = "FLAT";
......@@ -39,4 +51,9 @@ public final class Constants {
public static final List<Map<String,Object>> defaultEntities = Utils.genDefaultEntities(dimension, nb, vectors);
public static final List<Map<String,Object>> defaultBinaryEntities = Utils.genDefaultBinaryEntities(dimension, nb, vectorsBinary);
public static final String searchParam = Utils.setSearchParam(defaultMetricType, vectors.subList(0, nq), topk, n_probe);
public static final String binarySearchParam = Utils.setBinarySearchParam(defaultBinaryMetricType, vectorsBinary.subList(0, nq), topk, n_probe);
}
......@@ -69,7 +69,7 @@ public class MainClass {
private Object[][] genCollection(boolean isBinary, boolean autoId) throws ConnectFailedException {
Object[][] collection;
String collectionName = Utils.genUniqueStr("collection");
List<Map<String, Object>> defaultFields = Utils.genDefaultFields(dimension,isBinary);
List<Map<String, Object>> defaultFields = Utils.genDefaultFields(dimension, isBinary);
String jsonParams = String.format("{\"segment_row_count\": %s, \"auto_id\": %s}",segmentRowCount, autoId);
// Generate connection instance
MilvusClient client = new MilvusGrpcClient();
......@@ -86,6 +86,7 @@ public class MainClass {
collection = new Object[][]{{client, collectionName}};
return collection;
}
@DataProvider(name="Collection")
public Object[][] provideCollection() throws ConnectFailedException, InterruptedException {
Object[][] collection = genCollection(false,true);
......
package com;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import io.milvus.client.*;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomStringUtils;
......@@ -146,9 +148,44 @@ public class Utils {
return indexParams;
}
public static String setSearchParam(int nprobe) {
public static String setSearchParam(String metricType, List<List<Float>> queryVectors, int topk, int nprobe) {
JSONObject searchParam = new JSONObject();
searchParam.put("nprobe", nprobe);
JSONObject fieldParam = new JSONObject();
fieldParam.put("topk", topk);
fieldParam.put("metric_type", metricType);
fieldParam.put("query", queryVectors);
fieldParam.put("type", Constants.vectorType);
JSONObject tmpSearchParam = new JSONObject();
tmpSearchParam.put("nprobe", nprobe);
fieldParam.put("params", tmpSearchParam);
JSONObject vectorParams = new JSONObject();
vectorParams.put(Constants.floatFieldName, fieldParam);
searchParam.put("vector", vectorParams);
JSONObject param = new JSONObject();
JSONObject mustParam = new JSONObject();
JSONArray tmp = new JSONArray();
tmp.add(searchParam);
mustParam.put("must", tmp);
param.put("bool", mustParam);
return JSONObject.toJSONString(param);
}
public static String setBinarySearchParam(String metricType, List<ByteBuffer> queryVectors, int topk, int nprobe) {
JSONObject searchParam = new JSONObject();
JSONObject fieldParam = new JSONObject();
fieldParam.put("topk", topk);
fieldParam.put("metricType", metricType);
fieldParam.put("queryVectors", queryVectors);
JSONObject tmpSearchParam = new JSONObject();
tmpSearchParam.put("nprobe", nprobe);
fieldParam.put("params", tmpSearchParam);
JSONObject vectorParams = new JSONObject();
vectorParams.put(Constants.floatFieldName, fieldParam);
searchParam.put("vector", vectorParams);
JSONObject boolParam = new JSONObject();
JSONObject mustParam = new JSONObject();
mustParam.put("must", new JSONArray().add(searchParam));
boolParam.put("bool", mustParam);
return JSONObject.toJSONString(searchParam);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册