Ver Fonte

Rename searchByID to searchByIds

Signed-off-by: sahuang <xiaohai.xu@zilliz.com>
sahuang há 5 anos atrás
pai
commit
b83dc2f927

+ 4 - 4
examples/src/main/java/MilvusClientExample.java

@@ -190,15 +190,15 @@ public class MilvusClientExample {
     List<List<Long>> resultIds = searchResponse.getResultIdsList();
     List<List<Float>> resultDistances = searchResponse.getResultDistancesList();
 
-    // SearchByIDs
+    // SearchByIds
     // Searching the first 5 vectors of the vectors we just inserted by ID
-    SearchByIDParam searchByIDParam =
-            new SearchByIDParam.Builder(collectionName)
+    SearchByIdsParam searchByIdsParam =
+            new SearchByIdsParam.Builder(collectionName)
                     .withIDs(vectorIds.subList(0, searchBatchSize))
                     .withTopK(topK)
                     .withParamsInJson(searchParamsJson.toString())
                     .build();
-    SearchResponse searchByIDResponse = client.searchByID(searchByIDParam);
+    SearchResponse searchByIDResponse = client.searchByIds(searchByIdsParam);
     if (searchByIDResponse.ok()) {
       List<List<SearchResponse.QueryResult>> queryResultsList = searchResponse.getQueryResultsList();
       final double epsilon = 0.001;

+ 5 - 5
src/main/java/io/milvus/client/MilvusClient.java

@@ -265,13 +265,13 @@ public interface MilvusClient {
   SearchResponse search(SearchParam searchParam);
 
   /**
-   * Searches vectors specified by <code>searchByIDParam</code>
+   * Searches vectors specified by <code>searchByIdsParam</code>
    *
-   * @param searchByIDParam the <code>SearchByIDParam</code> object
+   * @param searchByIdsParam the <code>SearchByIdsParam</code> object
    *     <pre>
    * example usage:
    * <code>
-   * SearchByIDParam searchByIDParam = new SearchByIDParam.Builder(collectionName)
+   * SearchByIdsParam searchByIdsParam = new SearchByIdsParam.Builder(collectionName)
    *                                          .withIDs(ids)
    *                                          .withTopK(topK)
    *                                          .withPartitionTags(partitionTagsList)
@@ -281,12 +281,12 @@ public interface MilvusClient {
    * </pre>
    *
    * @return <code>SearchResponse</code>
-   * @see SearchByIDParam
+   * @see SearchByIdsParam
    * @see SearchResponse
    * @see SearchResponse.QueryResult
    * @see Response
    */
-  SearchResponse searchByID(SearchByIDParam searchByIDParam);
+  SearchResponse searchByIds(SearchByIdsParam searchByIdsParam);
 
   /**
    * Searches vectors specified by <code>searchParam</code> asynchronously

+ 6 - 6
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -634,7 +634,7 @@ public class MilvusGrpcClient implements MilvusClient {
   }
 
   @Override
-  public SearchResponse searchByID(@Nonnull SearchByIDParam searchByIDParam) {
+  public SearchResponse searchByIds(@Nonnull SearchByIdsParam searchByIdsParam) {
 
     if (!channelIsReadyOrIdle()) {
       logWarning("You are not connected to Milvus server");
@@ -643,20 +643,20 @@ public class MilvusGrpcClient implements MilvusClient {
       return searchResponse;
     }
 
-    List<Long> idList = searchByIDParam.getIds();
+    List<Long> idList = searchByIdsParam.getIds();
 
     KeyValuePair extraParam =
             KeyValuePair.newBuilder()
                     .setKey(extraParamKey)
-                    .setValue(searchByIDParam.getParamsInJson())
+                    .setValue(searchByIdsParam.getParamsInJson())
                     .build();
 
     io.milvus.grpc.SearchByIDParam request =
             io.milvus.grpc.SearchByIDParam.newBuilder()
-                    .setCollectionName(searchByIDParam.getCollectionName())
+                    .setCollectionName(searchByIdsParam.getCollectionName())
                     .addAllIdArray(idList)
-                    .addAllPartitionTagArray(searchByIDParam.getPartitionTags())
-                    .setTopk(searchByIDParam.getTopK())
+                    .addAllPartitionTagArray(searchByIdsParam.getPartitionTags())
+                    .setTopk(searchByIdsParam.getTopK())
                     .addExtraParams(extraParam)
                     .build();
 

+ 7 - 7
src/main/java/io/milvus/client/SearchByIDParam.java → src/main/java/io/milvus/client/SearchByIdsParam.java

@@ -23,8 +23,8 @@ import javax.annotation.Nonnull;
 import java.util.ArrayList;
 import java.util.List;
 
-/** Contains parameters for <code>searchByID</code> */
-public class SearchByIDParam {
+/** Contains parameters for <code>searchByIds</code> */
+public class SearchByIdsParam {
 
     private final String collectionName;
     private final List<String> partitionTags;
@@ -32,7 +32,7 @@ public class SearchByIDParam {
     private final long topK;
     private final String paramsInJson;
 
-    private SearchByIDParam(@Nonnull Builder builder) {
+    private SearchByIdsParam(@Nonnull Builder builder) {
         this.collectionName = builder.collectionName;
         this.partitionTags = builder.partitionTags;
         this.ids = builder.ids;
@@ -60,7 +60,7 @@ public class SearchByIDParam {
         return paramsInJson;
     }
 
-    /** Builder for <code>SearchByIDParam</code> */
+    /** Builder for <code>SearchByIdsParam</code> */
     public static class Builder {
         // Required parameters
         private final String collectionName;
@@ -133,13 +133,13 @@ public class SearchByIDParam {
          * @param paramsInJson extra parameters in JSON format
          * @return <code>Builder</code>
          */
-        public SearchByIDParam.Builder withParamsInJson(@Nonnull String paramsInJson) {
+        public SearchByIdsParam.Builder withParamsInJson(@Nonnull String paramsInJson) {
             this.paramsInJson = paramsInJson;
             return this;
         }
 
-        public SearchByIDParam build() {
-            return new SearchByIDParam(this);
+        public SearchByIdsParam build() {
+            return new SearchByIdsParam(this);
         }
     }
 }

+ 8 - 7
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -357,21 +357,21 @@ class MilvusClientTest {
 
   @org.junit.jupiter.api.Test
   void search() {
-    List<List<Float>> vectors = generateFloatVectors(size, dimension);
+    List<List<Float>> vectors = generateFloatVectors(100, dimension);
     vectors = vectors.stream().map(MilvusClientTest::normalizeVector).collect(Collectors.toList());
     InsertParam insertParam =
         new InsertParam.Builder(randomCollectionName).withFloatVectors(vectors).build();
     InsertResponse insertResponse = client.insert(insertParam);
     assertTrue(insertResponse.ok());
     List<Long> vectorIds = insertResponse.getVectorIds();
-    assertEquals(size, vectorIds.size());
+    assertEquals(100, vectorIds.size());
 
     assertTrue(client.flush(randomCollectionName).ok());
 
     final int searchSize = 5;
     List<List<Float>> vectorsToSearch = vectors.subList(0, searchSize);
 
-    final long topK = 10;
+    final long topK = 200;
     SearchParam searchParam =
         new SearchParam.Builder(randomCollectionName)
             .withFloatVectors(vectorsToSearch)
@@ -385,6 +385,7 @@ class MilvusClientTest {
     List<List<Float>> resultDistancesList = searchResponse.getResultDistancesList();
     assertEquals(searchSize, resultDistancesList.size());
     List<List<SearchResponse.QueryResult>> queryResultsList = searchResponse.getQueryResultsList();
+    System.out.println(queryResultsList.get(0).size());
     assertEquals(searchSize, queryResultsList.size());
     final double epsilon = 0.001;
     for (int i = 0; i < searchSize; i++) {
@@ -397,7 +398,7 @@ class MilvusClientTest {
   }
 
   @org.junit.jupiter.api.Test
-  void searchById() {
+  void searchByIds() {
     List<List<Float>> vectors = generateFloatVectors(size, dimension);
     vectors = vectors.stream().map(MilvusClientTest::normalizeVector).collect(Collectors.toList());
     InsertParam insertParam =
@@ -411,13 +412,13 @@ class MilvusClientTest {
 
     final long topK = 10;
     final int queryLength = 5;
-    SearchByIDParam searchByIDParam =
-            new SearchByIDParam.Builder(randomCollectionName)
+    SearchByIdsParam searchByIdsParam =
+            new SearchByIdsParam.Builder(randomCollectionName)
                     .withIDs(vectorIds.subList(0, queryLength))
                     .withTopK(topK)
                     .withParamsInJson("{\"nprobe\": 20}")
                     .build();
-    SearchResponse searchResponse = client.searchByID(searchByIDParam);
+    SearchResponse searchResponse = client.searchByIds(searchByIdsParam);
     assertTrue(searchResponse.ok());
     List<List<Long>> resultIdsList = searchResponse.getResultIdsList();
     assertEquals(queryLength, resultIdsList.size());