|
@@ -2916,8 +2916,10 @@ class MilvusClientDockerTest {
|
|
|
Assertions.assertEquals(R.Status.Success.getCode(), dropResponse.getStatus().intValue());
|
|
|
}
|
|
|
|
|
|
- private static void createSimpleCollection(MilvusClient client, String collName, String pkName, boolean autoID, int dimension) {
|
|
|
+ private static void createSimpleCollection(MilvusClient client, String dbName, String collName, String pkName,
|
|
|
+ boolean autoID, int dimension, ConsistencyLevelEnum level) {
|
|
|
client.dropCollection(DropCollectionParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
.withCollectionName(collName)
|
|
|
.build());
|
|
|
|
|
@@ -2938,10 +2940,29 @@ class MilvusClientDockerTest {
|
|
|
|
|
|
// create collection
|
|
|
R<RpcStatus> createR = client.createCollection(CreateCollectionParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
.withCollectionName(collName)
|
|
|
.withFieldTypes(fieldsSchema)
|
|
|
+ .withConsistencyLevel(level)
|
|
|
.build());
|
|
|
Assertions.assertEquals(R.Status.Success.getCode(), createR.getStatus().intValue());
|
|
|
+
|
|
|
+ CreateIndexParam indexParam = CreateIndexParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
+ .withCollectionName(collName)
|
|
|
+ .withFieldName("vector")
|
|
|
+ .withIndexType(IndexType.FLAT)
|
|
|
+ .withMetricType(MetricType.L2)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ R<RpcStatus> createIndexR = client.createIndex(indexParam);
|
|
|
+ Assertions.assertEquals(R.Status.Success.getCode(), createIndexR.getStatus().intValue());
|
|
|
+
|
|
|
+ R<RpcStatus> loadR = client.loadCollection(LoadCollectionParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
+ .withCollectionName(collName)
|
|
|
+ .build());
|
|
|
+ Assertions.assertEquals(R.Status.Success.getCode(), loadR.getStatus().intValue());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -2958,7 +2979,7 @@ class MilvusClientDockerTest {
|
|
|
Assertions.assertEquals(R.Status.Success.getCode(), dbResponse.getStatus().intValue());
|
|
|
|
|
|
// create a collection in the default db
|
|
|
- createSimpleCollection(client, randomCollectionName, "pk", false, DIMENSION);
|
|
|
+ createSimpleCollection(client, "", randomCollectionName, "pk", false, DIMENSION, ConsistencyLevelEnum.BOUNDED);
|
|
|
|
|
|
// a temp client connect to the new db
|
|
|
ConnectParam connectParam = connectParamBuilder()
|
|
@@ -3019,7 +3040,7 @@ class MilvusClientDockerTest {
|
|
|
Assertions.assertTrue(ts12 > ts11);
|
|
|
|
|
|
// create a new collection with the same name, different schema, in the test db
|
|
|
- createSimpleCollection(tempClient, randomCollectionName, "aaa", false, 4);
|
|
|
+ createSimpleCollection(tempClient, "", randomCollectionName, "aaa", false, 4, ConsistencyLevelEnum.BOUNDED);
|
|
|
|
|
|
// use the temp client to insert wrong data, wrong dimension
|
|
|
row.addProperty("aaa", 22);
|
|
@@ -3315,4 +3336,109 @@ class MilvusClientDockerTest {
|
|
|
System.out.println(score);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testConsistencyLevel() {
|
|
|
+ String randomCollectionName = generator.generate(10);
|
|
|
+ String pkName = "pk";
|
|
|
+ String vectorName = "vector";
|
|
|
+ int dim = 4;
|
|
|
+ String defaultDbName = "default";
|
|
|
+ String tempDbName = "db_for_level";
|
|
|
+
|
|
|
+ // create a temp database
|
|
|
+ CreateDatabaseParam createDatabaseParam = CreateDatabaseParam.newBuilder()
|
|
|
+ .withDatabaseName(tempDbName)
|
|
|
+ .build();
|
|
|
+ R<RpcStatus> createResponse = client.createDatabase(createDatabaseParam);
|
|
|
+ Assertions.assertEquals(R.Status.Success.getCode(), createResponse.getStatus().intValue());
|
|
|
+
|
|
|
+ Function<String, Void> runTestFunc =
|
|
|
+ dbName -> {
|
|
|
+ // a client use the temp database
|
|
|
+ ConnectParam connectParam = connectParamBuilder()
|
|
|
+ .withDatabaseName(tempDbName)
|
|
|
+ .build();
|
|
|
+ MilvusClientForTest tempClient = new MilvusClientForTest(connectParam);
|
|
|
+
|
|
|
+ for (int i = 0; i < 20; i++) {
|
|
|
+ JsonObject row = new JsonObject();
|
|
|
+ row.addProperty(pkName, i);
|
|
|
+ row.add(vectorName, JsonUtils.toJsonTree(utils.generateFloatVector(dim)));
|
|
|
+ tempClient.insert(InsertParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
+ .withCollectionName(randomCollectionName)
|
|
|
+ .withRows(Collections.singletonList(row))
|
|
|
+ .build());
|
|
|
+
|
|
|
+ // query/search/hybridSearch immediately after insert, data must be visible
|
|
|
+ String expr = String.format("%s == %d", pkName, i);
|
|
|
+ if (i%3 == 0) {
|
|
|
+ R<QueryResults> fetchR = tempClient.query(QueryParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
+ .withCollectionName(randomCollectionName)
|
|
|
+ .withExpr(expr)
|
|
|
+ .withLimit(5L)
|
|
|
+ .addOutField(pkName)
|
|
|
+ .build());
|
|
|
+ Assertions.assertEquals(R.Status.Success.getCode(), fetchR.getStatus().intValue());
|
|
|
+ QueryResultsWrapper oneResult = new QueryResultsWrapper(fetchR.getData());
|
|
|
+ List<QueryResultsWrapper.RowRecord> records = oneResult.getRowRecords();
|
|
|
+ Assertions.assertEquals(1L, records.size());
|
|
|
+ } else if (i%2 == 0) {
|
|
|
+ R<SearchResults> searchOne = tempClient.search(SearchParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
+ .withCollectionName(randomCollectionName)
|
|
|
+ .withVectorFieldName(vectorName)
|
|
|
+ .withLimit(5L)
|
|
|
+ .withExpr(expr)
|
|
|
+ .withFloatVectors(Collections.singletonList(utils.generateFloatVector(dim)))
|
|
|
+ .addOutField(pkName)
|
|
|
+ .build());
|
|
|
+ Assertions.assertEquals(R.Status.Success.getCode(), searchOne.getStatus().intValue());
|
|
|
+
|
|
|
+ SearchResultsWrapper oneResult = new SearchResultsWrapper(searchOne.getData().getResults());
|
|
|
+ List<SearchResultsWrapper.IDScore> scores = oneResult.getIDScore(0);
|
|
|
+ Assertions.assertEquals(1, scores.size());
|
|
|
+ } else {
|
|
|
+ AnnSearchParam subReq = AnnSearchParam.newBuilder()
|
|
|
+ .withVectorFieldName(vectorName)
|
|
|
+ .withExpr(expr)
|
|
|
+ .withFloatVectors(Collections.singletonList(utils.generateFloatVector(dim)))
|
|
|
+ .withLimit(5L)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ R<SearchResults> searchR = tempClient.hybridSearch(HybridSearchParam.newBuilder()
|
|
|
+ .withDatabaseName(dbName)
|
|
|
+ .withCollectionName(randomCollectionName)
|
|
|
+ .addSearchRequest(subReq)
|
|
|
+ .withLimit(5L)
|
|
|
+ .withRanker(WeightedRanker.newBuilder()
|
|
|
+ .withWeights(Collections.singletonList(1.0f))
|
|
|
+ .build())
|
|
|
+ .withOutFields(Collections.singletonList(pkName))
|
|
|
+ .build());
|
|
|
+ Assertions.assertEquals(R.Status.Success.getCode(), searchR.getStatus().intValue());
|
|
|
+ SearchResultsWrapper oneResult = new SearchResultsWrapper(searchR.getData().getResults());
|
|
|
+ List<SearchResultsWrapper.IDScore> scores = oneResult.getIDScore(0);
|
|
|
+ Assertions.assertEquals(1, scores.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ };
|
|
|
+
|
|
|
+ // test SESSION level
|
|
|
+ createSimpleCollection(client, "", randomCollectionName, pkName, false, dim, ConsistencyLevelEnum.SESSION);
|
|
|
+ runTestFunc.apply(defaultDbName);
|
|
|
+
|
|
|
+ createSimpleCollection(client, tempDbName, randomCollectionName, pkName, false, dim, ConsistencyLevelEnum.SESSION);
|
|
|
+ runTestFunc.apply(tempDbName);
|
|
|
+
|
|
|
+ // test STRONG level
|
|
|
+ createSimpleCollection(client, "", randomCollectionName, pkName, false, dim, ConsistencyLevelEnum.STRONG);
|
|
|
+ runTestFunc.apply(defaultDbName);
|
|
|
+
|
|
|
+ createSimpleCollection(client, tempDbName, randomCollectionName, pkName, false, dim, ConsistencyLevelEnum.STRONG);
|
|
|
+ runTestFunc.apply(tempDbName);
|
|
|
+ }
|
|
|
}
|