Browse Source

init 0.9.0 sdk

Signed-off-by: sahuang <xiaohai.xu@zilliz.com>
sahuang 4 years ago
parent
commit
013cab9f97
34 changed files with 2020 additions and 1239 deletions
  1. 0 6
      CHANGELOG.md
  2. 3 3
      README.md
  3. 2 2
      examples/pom.xml
  4. 126 49
      examples/src/main/java/MilvusClientExample.java
  5. 3 40
      pom.xml
  6. 62 33
      src/main/java/io/milvus/client/CollectionMapping.java
  7. 71 0
      src/main/java/io/milvus/client/CompactParam.java
  8. 1 41
      src/main/java/io/milvus/client/ConnectParam.java
  9. 1 0
      src/main/java/io/milvus/client/CountEntitiesResponse.java
  10. 20 17
      src/main/java/io/milvus/client/DataType.java
  11. 68 0
      src/main/java/io/milvus/client/FieldBuilder.java
  12. 1 2
      src/main/java/io/milvus/client/GetCollectionInfoResponse.java
  13. 13 18
      src/main/java/io/milvus/client/GetEntityByIDResponse.java
  14. 0 61
      src/main/java/io/milvus/client/GetIndexInfoResponse.java
  15. 1 0
      src/main/java/io/milvus/client/HasCollectionResponse.java
  16. 1 0
      src/main/java/io/milvus/client/HasPartitionResponse.java
  17. 34 36
      src/main/java/io/milvus/client/Index.java
  18. 49 38
      src/main/java/io/milvus/client/InsertParam.java
  19. 7 7
      src/main/java/io/milvus/client/InsertResponse.java
  20. 68 0
      src/main/java/io/milvus/client/JsonBuilder.java
  21. 1 2
      src/main/java/io/milvus/client/ListCollectionsResponse.java
  22. 8 2
      src/main/java/io/milvus/client/ListPartitionsResponse.java
  23. 0 64
      src/main/java/io/milvus/client/MetricType.java
  24. 119 107
      src/main/java/io/milvus/client/MilvusClient.java
  25. 510 193
      src/main/java/io/milvus/client/MilvusGrpcClient.java
  26. 52 71
      src/main/java/io/milvus/client/SearchParam.java
  27. 26 13
      src/main/java/io/milvus/client/SearchResponse.java
  28. 0 16
      src/main/java/io/milvus/client/exception/InitializationException.java
  29. 0 24
      src/main/java/io/milvus/client/exception/MilvusException.java
  30. 0 22
      src/main/java/io/milvus/client/exception/UnsupportedServerVersion.java
  31. 300 84
      src/main/proto/milvus.proto
  32. 0 3
      src/main/resources/milvus-client.properties
  33. 473 217
      src/test/java/io/milvus/client/MilvusGrpcClientTest.java
  34. 0 68
      src/test/java/io/milvus/client/StaticNameResolverProvider.java

+ 0 - 6
CHANGELOG.md

@@ -1,11 +1,5 @@
 # Changelog   
 
-## milvus-sdk-java 0.8.5 (2020-08-26)
-
-### Feature
-
-- \#128 - GRPC timeout support
-
 ## milvus-sdk-java 0.8.3 (2020-07-15)
 
 ### Improvement

+ 3 - 3
README.md

@@ -15,7 +15,7 @@ The following table shows compatibilities between Milvus and Java SDK.
 
 | Milvus version | Java SDK version |
 | :------------: | :--------------: |
-|     0.10.x     |    0.8.5         |
+|     0.11.0     |    0.9.0         |
 |     0.10.2     |    0.8.4         |
 |     0.10.1     |    0.8.3         |
 |     0.10.0     |    0.8.2         |
@@ -37,14 +37,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
         <dependency>
             <groupId>io.milvus</groupId>
             <artifactId>milvus-sdk-java</artifactId>
-            <version>0.8.5</version>
+            <version>0.9.0</version>
         </dependency>
        ```
 
    - Gradle/Grails
 
         ```gradle
-        compile 'io.milvus:milvus-sdk-java:0.8.5'
+        compile 'io.milvus:milvus-sdk-java:0.9.0'
         ```
 
 ### Examples

+ 2 - 2
examples/pom.xml

@@ -25,7 +25,7 @@
 
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java-examples</artifactId>
-    <version>0.8.5</version>
+    <version>0.9.0</version>
     <build>
         <plugins>
             <plugin>
@@ -63,7 +63,7 @@
         <dependency>
             <groupId>io.milvus</groupId>
             <artifactId>milvus-sdk-java</artifactId>
-            <version>0.8.5</version>
+            <version>0.9.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>

+ 126 - 49
examples/src/main/java/MilvusClientExample.java

@@ -18,28 +18,30 @@
  */
 
 import com.google.common.util.concurrent.ListenableFuture;
-import com.google.gson.JsonObject;
 import io.milvus.client.*;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.SplittableRandom;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 import java.util.stream.DoubleStream;
+import org.json.JSONObject;
 
-// This is a simple example demonstrating how to use Milvus Java SDK.
-// For detailed API document, please refer to
+// This is a simple example demonstrating how to use Milvus Java SDK v0.9.0.
+// For detailed API documentation, please refer to
 // https://milvus-io.github.io/milvus-sdk-java/javadoc/io/milvus/client/package-summary.html
-// You can also find more information on https://milvus.io/
+// You can also find more information on https://milvus.io/docs/overview.md
 public class MilvusClientExample {
 
   // Helper function that generates random vectors
   static List<List<Float>> generateVectors(int vectorCount, int dimension) {
-    SplittableRandom splitcollectionRandom = new SplittableRandom();
+    SplittableRandom splitCollectionRandom = new SplittableRandom();
     List<List<Float>> vectors = new ArrayList<>(vectorCount);
     for (int i = 0; i < vectorCount; ++i) {
-      splitcollectionRandom = splitcollectionRandom.split();
-      DoubleStream doubleStream = splitcollectionRandom.doubles(dimension);
+      splitCollectionRandom = splitCollectionRandom.split();
+      DoubleStream doubleStream = splitCollectionRandom.doubles(dimension);
       List<Float> vector =
           doubleStream.boxed().map(Double::floatValue).collect(Collectors.toList());
       vectors.add(vector);
@@ -56,7 +58,65 @@ public class MilvusClientExample {
     return vector;
   }
 
-  public static void main(String[] args) throws InterruptedException {
+  // Helper function that generates default fields list for a collection
+  // In this example, we have 3 fields with names "int64", "float" and "float_vec".
+  // Their DataType must also be defined.
+  static List<Map<String, Object>> generateDefaultFields(int dimension) {
+    List<Map<String, Object>> fieldList = new ArrayList<>();
+    Map<String, Object> intField = new HashMap<>();
+    intField.put("field", "int64");
+    intField.put("type", DataType.INT64);
+
+    Map<String, Object> floatField = new HashMap<>();
+    floatField.put("field", "float");
+    floatField.put("type", DataType.FLOAT);
+
+    Map<String, Object> vecField = new HashMap<>();
+    vecField.put("field", "float_vec");
+    vecField.put("type", DataType.VECTOR_FLOAT);
+    JSONObject jsonObject = new JSONObject();
+    jsonObject.put("dim", dimension);
+    vecField.put("params", jsonObject.toString());
+
+    fieldList.add(intField);
+    fieldList.add(floatField);
+    fieldList.add(vecField);
+    return fieldList;
+  }
+
+  // Helper function that generates entity field values for inserting into a collection
+  // This corresponds to the above function that initializes fields.
+  static List<Map<String, Object>> generateDefaultFieldValues(int vectorCount, List<List<Float>> vectors) {
+    List<Map<String, Object>> fieldList = new ArrayList<>();
+    Map<String, Object> intField = new HashMap<>();
+    intField.put("field", "int64");
+    intField.put("type", DataType.INT64);
+
+    Map<String, Object> floatField = new HashMap<>();
+    floatField.put("field", "float");
+    floatField.put("type", DataType.FLOAT);
+
+    Map<String, Object> vecField = new HashMap<>();
+    vecField.put("field", "float_vec");
+    vecField.put("type", DataType.VECTOR_FLOAT);
+
+    List<Long> intValues = new ArrayList<>(vectorCount);
+    List<Float> floatValues = new ArrayList<>(vectorCount);
+    for (int i = 0; i < vectorCount; i++) {
+      intValues.add((long) i);
+      floatValues.add((float) i);
+    }
+    intField.put("values", intValues);
+    floatField.put("values", floatValues);
+    vecField.put("values", vectors);
+
+    fieldList.add(intField);
+    fieldList.add(floatField);
+    fieldList.add(vecField);
+    return fieldList;
+  }
+
+  public static void main(String[] args) throws InterruptedException, ConnectFailedException {
 
     // You may need to change the following to the host and port of your Milvus server
     String host = "localhost";
@@ -66,18 +126,26 @@ public class MilvusClientExample {
       port = Integer.parseInt(args[1]);
     }
 
+    // Create Milvus client
+    MilvusClient client = new MilvusGrpcClient();
+
+    // Connect to Milvus server
     ConnectParam connectParam = new ConnectParam.Builder().withHost(host).withPort(port).build();
-    MilvusClient client = new MilvusGrpcClient(connectParam);
+    try {
+      Response connectResponse = client.connect(connectParam);
+    } catch (ConnectFailedException e) {
+      System.out.println("Failed to connect to Milvus server: " + e.toString());
+      throw e;
+    }
 
     // Create a collection with the following collection mapping
     final String collectionName = "example"; // collection name
     final int dimension = 128; // dimension of each vector
-    final int indexFileSize = 1024; // maximum size (in MB) of each index file
-    final MetricType metricType = MetricType.IP; // we choose IP (Inner Product) as our metric type
+    // we choose IP (Inner Product) as our metric type
     CollectionMapping collectionMapping =
-        new CollectionMapping.Builder(collectionName, dimension)
-            .withIndexFileSize(indexFileSize)
-            .withMetricType(metricType)
+        new CollectionMapping.Builder(collectionName)
+            .withFields(generateDefaultFields(dimension))
+            .withParamsInJson("{\"segment_row_count\": 50000, \"auto_id\": true}")
             .build();
     Response createCollectionResponse = client.createCollection(collectionMapping);
 
@@ -87,42 +155,37 @@ public class MilvusClientExample {
     // Get collection info
     GetCollectionInfoResponse getCollectionInfoResponse = client.getCollectionInfo(collectionName);
 
-    // Insert randomly generated vectors to collection
+    // Insert randomly generated field values to collection
     final int vectorCount = 100000;
     List<List<Float>> vectors = generateVectors(vectorCount, dimension);
     vectors =
         vectors.stream().map(MilvusClientExample::normalizeVector).collect(Collectors.toList());
+    List<Map<String, Object>> defaultFieldValues = generateDefaultFieldValues(vectorCount, vectors);
     InsertParam insertParam =
-        new InsertParam.Builder(collectionName).withFloatVectors(vectors).build();
+        new InsertParam.Builder(collectionName)
+            .withFields(defaultFieldValues)
+            .build();
     InsertResponse insertResponse = client.insert(insertParam);
-    // Insert returns a list of vector ids that you will be using (if you did not supply them
-    // yourself) to reference the vectors you just inserted
-    List<Long> vectorIds = insertResponse.getVectorIds();
+    // Insert returns a list of entity ids that you will be using (if you did not supply them
+    // yourself) to reference the entities you just inserted
+    List<Long> vectorIds = insertResponse.getEntityIds();
 
     // Flush data in collection
     Response flushResponse = client.flush(collectionName);
 
     // Get current entity count of collection
-    CountEntitiesResponse ountEntitiesResponse = client.countEntities(collectionName);
+    CountEntitiesResponse countEntitiesResponse = client.countEntities(collectionName);
 
     // Create index for the collection
-    // We choose IVF_SQ8 as our index type here. Refer to IndexType javadoc for a
-    // complete explanation of different index types
-    final IndexType indexType = IndexType.IVF_SQ8;
-    // Each index type has its optional parameters you can set. Refer to the Milvus documentation
-    // for how to set the optimal parameters based on your needs.
-    JsonObject indexParamsJson = new JsonObject();
-    indexParamsJson.addProperty("nlist", 16384);
+    // We choose IVF_SQ8 as our index type here. Refer to Milvus documentation for a
+    // complete explanation of different index types and their relative parameters.
     Index index =
-        new Index.Builder(collectionName, indexType)
-            .withParamsInJson(indexParamsJson.toString())
+        new Index.Builder(collectionName, "float_vec")
+            .withParamsInJson("{\"index_type\": \"IVF_SQ8\", \"metric_type\": \"L2\", "
+                + "\"params\": {\"nlist\": 2048}}")
             .build();
     Response createIndexResponse = client.createIndex(index);
 
-    // Get index info for your collection
-    GetIndexInfoResponse getIndexInfoResponse = client.getIndexInfo(collectionName);
-    System.out.format("Index Info: %s\n", getIndexInfoResponse.getIndex().get().toString());
-
     // Get collection info
     Response getCollectionStatsResponse = client.getCollectionStats(collectionName);
     if (getCollectionStatsResponse.ok()) {
@@ -138,32 +201,41 @@ public class MilvusClientExample {
       throw new AssertionError("Wrong results!");
     }
 
-    // Search vectors
-    // Searching the first 5 vectors of the vectors we just inserted
+    // Search entities using DSL statement.
+    // Searching the first 5 entities we just inserted by including them in DSL.
     final int searchBatchSize = 5;
     List<List<Float>> vectorsToSearch = vectors.subList(0, searchBatchSize);
     final long topK = 10;
     // Based on the index you created, the available search parameters will be different. Refer to
     // the Milvus documentation for how to set the optimal parameters based on your needs.
-    JsonObject searchParamsJson = new JsonObject();
-    searchParamsJson.addProperty("nprobe", 20);
+    String dsl = String.format(
+        "{\"bool\": {"
+            + "\"must\": [{"
+            + "    \"range\": {"
+            + "        \"float\": {\"GT\": -10, \"LT\": 100}"
+            + "    }},{"
+            + "    \"vector\": {"
+            + "        \"float_vec\": {"
+            + "            \"topk\": %d, \"metric_type\": \"IP\", \"type\": \"float\", \"query\": "
+            + "%s, \"params\": {\"nprobe\": 50}"
+            + "    }}}]}}",
+        topK, vectorsToSearch.toString());
     SearchParam searchParam =
         new SearchParam.Builder(collectionName)
-            .withFloatVectors(vectorsToSearch)
-            .withTopK(topK)
-            .withParamsInJson(searchParamsJson.toString())
+            .withDSL(dsl)
+            .withParamsInJson("{\"fields\": [\"int64\", \"float\"]}")
             .build();
     SearchResponse searchResponse = client.search(searchParam);
     if (searchResponse.ok()) {
       List<List<SearchResponse.QueryResult>> queryResultsList =
           searchResponse.getQueryResultsList();
-      final double epsilon = 0.001;
+      final double epsilon = 0.01;
       for (int i = 0; i < searchBatchSize; i++) {
         // Since we are searching for vector that is already present in the collection,
         // the first result vector should be itself and the distance (inner product) should be
         // very close to 1 (some precision is lost during the process)
         SearchResponse.QueryResult firstQueryResult = queryResultsList.get(i).get(0);
-        if (firstQueryResult.getVectorId() != vectorIds.get(i)
+        if (firstQueryResult.getEntityId() != vectorIds.get(i)
             || Math.abs(1 - firstQueryResult.getDistance()) > epsilon) {
           throw new AssertionError("Wrong results!");
         }
@@ -183,31 +255,36 @@ public class MilvusClientExample {
       e.printStackTrace();
     }
 
-    // Delete the first 5 vectors you just searched
+    // Delete the first 5 entities you just searched
     Response deleteByIdsResponse =
         client.deleteEntityByID(collectionName, vectorIds.subList(0, searchBatchSize));
     flushResponse = client.flush(collectionName);
 
-    // Try to get the corresponding vector of the first id you just deleted.
+    // After deleting them, we call getEntityByID and obviously all 5 entities should not be returned.
     GetEntityByIDResponse getEntityByIDResponse =
         client.getEntityByID(collectionName, vectorIds.subList(0, searchBatchSize));
-    // Obviously you won't get anything
-    if (!getEntityByIDResponse.getFloatVectors().get(0).isEmpty()) {
+    if (getEntityByIDResponse.getValidIds().size() > 0) {
       throw new AssertionError("This can never happen!");
     }
 
     // Compact the collection, erase deleted data from disk and rebuild index in background (if
     // the data size after compaction is still larger than indexFileSize). Data was only
     // soft-deleted until you call compact.
-    Response compactResponse = client.compact(collectionName);
+    Response compactResponse = client.compact(
+        new CompactParam.Builder(collectionName).withThreshold(0.2).build());
 
     // Drop index for the collection
-    Response dropIndexResponse = client.dropIndex(collectionName);
+    Response dropIndexResponse = client.dropIndex(collectionName, "float_vec");
 
     // Drop collection
     Response dropCollectionResponse = client.dropCollection(collectionName);
 
     // Disconnect from Milvus server
-    client.close();
+    try {
+      Response disconnectResponse = client.disconnect();
+    } catch (InterruptedException e) {
+      System.out.println("Failed to disconnect: " + e.toString());
+      throw e;
+    }
   }
 }

+ 3 - 40
pom.xml

@@ -25,7 +25,7 @@
 
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java</artifactId>
-    <version>0.8.5</version>
+    <version>0.9.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
     <name>io.milvus:milvus-sdk-java</name>
@@ -135,7 +135,7 @@
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter</artifactId>
-            <version>5.6.2</version>
+            <version>5.5.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -163,18 +163,7 @@
             <artifactId>log4j-slf4j-impl</artifactId>
             <version>2.12.1</version>
         </dependency>
-        <dependency>
-            <groupId>org.testcontainers</groupId>
-            <artifactId>testcontainers</artifactId>
-            <version>1.14.3</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.testcontainers</groupId>
-            <artifactId>junit-jupiter</artifactId>
-            <version>1.14.3</version>
-            <scope>test</scope>
-        </dependency>
+
     </dependencies>
 
     <profiles>
@@ -231,12 +220,6 @@
     </profiles>
 
     <build>
-        <resources>
-            <resource>
-                <directory>src/main/resources</directory>
-                <filtering>true</filtering>
-            </resource>
-        </resources>
         <extensions>
             <extension>
                 <groupId>kr.motd.maven</groupId>
@@ -305,26 +288,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <!-- JUnit5 tests are not running with maven 3.6.x
-            https://dzone.com/articles/why-your-junit-5-tests-are-not-running-under-maven
-            -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <version>2.19.1</version>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.junit.platform</groupId>
-                        <artifactId>junit-platform-surefire-provider</artifactId>
-                        <version>1.1.0</version>
-                    </dependency>
-                    <dependency>
-                        <groupId>org.junit.jupiter</groupId>
-                        <artifactId>junit-jupiter-engine</artifactId>
-                        <version>5.1.0</version>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 

+ 62 - 33
src/main/java/io/milvus/client/CollectionMapping.java

@@ -19,85 +19,114 @@
 
 package io.milvus.client;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 import javax.annotation.Nonnull;
 
 /** Represents a collection mapping */
-// Builder Pattern
 public class CollectionMapping {
   private final String collectionName;
-  private final long dimension;
-  private final long indexFileSize;
-  private final MetricType metricType;
+  private final List<? extends Map<String, Object>> fields;
+  private final String paramsInJson;
 
   private CollectionMapping(@Nonnull Builder builder) {
     collectionName = builder.collectionName;
-    dimension = builder.dimension;
-    indexFileSize = builder.indexFileSize;
-    metricType = builder.metricType;
+    fields = builder.fields;
+    paramsInJson = builder.paramsInJson;
   }
 
   public String getCollectionName() {
     return collectionName;
   }
 
-  public long getDimension() {
-    return dimension;
+  public List<? extends Map<String, Object>> getFields() {
+    return fields;
   }
 
-  public long getIndexFileSize() {
-    return indexFileSize;
-  }
-
-  public MetricType getMetricType() {
-    return metricType;
+  public String getParamsInJson() {
+    return paramsInJson;
   }
 
   @Override
   public String toString() {
     return String.format(
-        "CollectionMapping = {collectionName = %s, dimension = %d, indexFileSize = %d, metricType = %s}",
-        collectionName, dimension, indexFileSize, metricType.name());
+        "CollectionMapping = {collectionName = %s, fields = %s, params = %s}",
+        collectionName, fields.toString(), paramsInJson);
   }
 
   /** Builder for <code>CollectionMapping</code> */
   public static class Builder {
     // Required parameters
     private final String collectionName;
-    private final long dimension;
 
-    // Optional parameters - initialized to default values
-    private long indexFileSize = 1024;
-    private MetricType metricType = MetricType.L2;
+    // Optional parameters. Default to empty.
+    private List<Map<String, Object>> fields = new ArrayList<>();
+    private String paramsInJson = "{}";
 
     /**
      * @param collectionName collection name
-     * @param dimension vector dimension
      */
-    public Builder(@Nonnull String collectionName, long dimension) {
+    public Builder(@Nonnull String collectionName) {
       this.collectionName = collectionName;
-      this.dimension = dimension;
     }
 
     /**
-     * Optional. Default to 1024 MB.
+     * Build with fields. Example fields:
+     * <pre>
+     *   <code>
+     *  [
+     *      {"field": "A", "type": DataType.INT64},
+     *      {"field": "B", "type": DataType.INT32},
+     *      {"field": "C", "type": DataType.FLOAT},
+     *      {"field": "Vec", "type": DataType.VECTOR_FLOAT, "params": {"dim": 128}}
+     *  ]
+     *   </code>
+     * </pre>
+     *
+     * @param fields a list of hashmap listing each field. A field must have keys "field" and
+     *               "type". A vector field must have "dim" in "params". "params" should be in json
+     *               format.
+     * @return <code>Builder</code>
+     */
+    public Builder withFields(@Nonnull List<Map<String, Object>> fields) {
+      this.fields = fields;
+      return this;
+    }
+
+    /**
+     * Add a single field to collection. Example field:
+     * <pre>
+     *   <code>
+     *      {"field": "A", "type": DataType.INT64}, or
+     *      {"field": "B", "type": DataType.INT32}, or
+     *      {"field": "C", "type": DataType.FLOAT}, or
+     *      {"field": "Vec", "type": DataType.VECTOR_FLOAT, "params": {"dim": 128}}
+     *   </code>
+     * </pre>
      *
-     * @param indexFileSize in megabytes.
+     * @param field A field must have keys "field" and "type". A vector field must have
+     *              "dim" in "params". <code>FieldBuilder</code> can be used to create a field.
+     * @see FieldBuilder
      * @return <code>Builder</code>
      */
-    public Builder withIndexFileSize(long indexFileSize) {
-      this.indexFileSize = indexFileSize;
+    public Builder field(@Nonnull Map<String, Object> field) {
+      this.fields.add(field);
       return this;
     }
 
     /**
-     * Optional. Default to MetricType.L2
+     * Build with extra params in json string format.
      *
-     * @param metricType a <code>MetricType</code> value
+     * @param paramsInJson Two optional parameters can be included. "segment_row_count" is default
+     *                     to 100,000. Merge will be triggered if more than this number of entities
+     *                     are inserted into collection. "auto_id" is default to <code>true</code>.
+     *                     Entity ids will be auto-generated by Milvus if set to true.
+     * @see JsonBuilder
      * @return <code>Builder</code>
-     * @see MetricType
      */
-    public Builder withMetricType(@Nonnull MetricType metricType) {
-      this.metricType = metricType;
+    public Builder withParamsInJson(String paramsInJson) {
+      this.paramsInJson = paramsInJson;
       return this;
     }
 

+ 71 - 0
src/main/java/io/milvus/client/CompactParam.java

@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.milvus.client;
+
+import javax.annotation.Nonnull;
+
+/** Contains parameters for <code>compact</code> */
+public class CompactParam {
+  private final String collectionName;
+  private final double threshold;
+
+  private CompactParam(@Nonnull Builder builder) {
+    this.collectionName = builder.collectionName;
+    this.threshold = builder.threshold;
+  }
+
+  public String getCollectionName() {
+    return collectionName;
+  }
+
+  public double getThreshold() {
+    return threshold;
+  }
+
+  /** Builder for <code>CompactParam</code> */
+  public static class Builder {
+    // Required parameter
+    private final String collectionName;
+
+    // Optional parameter - initialized to default value
+    private double threshold = 0.2;
+
+    /** @param collectionName collection to compact */
+    public Builder(@Nonnull String collectionName) {
+      this.collectionName = collectionName;
+    }
+
+    /**
+     * Optional. Default to 0.2. Segment will compact if and only if the percentage of entities
+     * deleted exceeds the threshold.
+     *
+     * @param threshold The threshold
+     * @return <code>Builder</code>
+     */
+    public Builder withThreshold(double threshold) {
+      this.threshold = threshold;
+      return this;
+    }
+
+    public CompactParam build() {
+      return new CompactParam(this);
+    }
+  }
+}

+ 1 - 41
src/main/java/io/milvus/client/ConnectParam.java

@@ -19,17 +19,13 @@
 
 package io.milvus.client;
 
-import io.grpc.ManagedChannelBuilder;
-
 import javax.annotation.Nonnull;
 import java.util.concurrent.TimeUnit;
 
 /** Contains parameters for connecting to Milvus server */
 public class ConnectParam {
-  private final String target;
   private final String host;
   private final int port;
-  private final String defaultLoadBalancingPolicy;
   private final long connectTimeoutNanos;
   private final long keepAliveTimeNanos;
   private final long keepAliveTimeoutNanos;
@@ -37,10 +33,8 @@ public class ConnectParam {
   private final long idleTimeoutNanos;
 
   private ConnectParam(@Nonnull Builder builder) {
-    this.target = builder.target;
     this.host = builder.host;
     this.port = builder.port;
-    this.defaultLoadBalancingPolicy = builder.defaultLoadBalancingPolicy;
     this.connectTimeoutNanos = builder.connectTimeoutNanos;
     this.keepAliveTimeNanos = builder.keepAliveTimeNanos;
     this.keepAliveTimeoutNanos = builder.keepAliveTimeoutNanos;
@@ -48,10 +42,6 @@ public class ConnectParam {
     this.idleTimeoutNanos = builder.idleTimeoutNanos;
   }
 
-  public String getTarget() {
-    return target;
-  }
-
   public String getHost() {
     return host;
   }
@@ -60,10 +50,6 @@ public class ConnectParam {
     return port;
   }
 
-  public String getDefaultLoadBalancingPolicy() {
-    return defaultLoadBalancingPolicy;
-  }
-
   public long getConnectTimeout(@Nonnull TimeUnit timeUnit) {
     return timeUnit.convert(connectTimeoutNanos, TimeUnit.NANOSECONDS);
   }
@@ -87,29 +73,14 @@ public class ConnectParam {
   /** Builder for <code>ConnectParam</code> */
   public static class Builder {
     // Optional parameters - initialized to default values
-    private String target = null;
     private String host = "localhost";
     private int port = 19530;
-    private String defaultLoadBalancingPolicy = "round_robin";
     private long connectTimeoutNanos = TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
     private long keepAliveTimeNanos = Long.MAX_VALUE; // Disabling keepalive
     private long keepAliveTimeoutNanos = TimeUnit.NANOSECONDS.convert(20, TimeUnit.SECONDS);
     private boolean keepAliveWithoutCalls = false;
     private long idleTimeoutNanos = TimeUnit.NANOSECONDS.convert(24, TimeUnit.HOURS);
 
-    /**
-     * Optional. Defaults to null. Will be used in precedence to host and port.
-     *
-     * @param target a GRPC target string
-     * @return <code>Builder</code>
-     *
-     * @see ManagedChannelBuilder#forTarget(String)
-     */
-    public Builder withTarget(@Nonnull String target) {
-      this.target = target;
-      return this;
-    }
-
     /**
      * Optional. Defaults to "localhost".
      *
@@ -135,17 +106,6 @@ public class ConnectParam {
       return this;
     }
 
-    /**
-     * Optional. Defaults to "round_robin".
-     *
-     * @param defaultLoadBalancingPolicy the default load-balancing policy name
-     * @return <code>Builder</code>
-     */
-    public Builder withDefaultLoadBalancingPolicy(String defaultLoadBalancingPolicy) {
-      this.defaultLoadBalancingPolicy = defaultLoadBalancingPolicy;
-      return this;
-    }
-
     /**
      * Optional. Defaults to 10 seconds.
      *
@@ -187,7 +147,7 @@ public class ConnectParam {
      * expires without any read activity on the connection, the connection is considered dead. An
      * unreasonably small value might be increased. Defaults to 20 seconds.
      *
-     * <p>This value should be at least multiple times the RTT to allow for lost packets.
+     * <p>This value should be at least multiple times the RTT to allow for lost packets.</p>
      *
      * @see <a
      *     href="https://grpc.github.io/grpc-java/javadoc/io/grpc/ManagedChannelBuilder.html#keepAliveTimeout-long-java.util.concurrent.TimeUnit-">

+ 1 - 0
src/main/java/io/milvus/client/CountEntitiesResponse.java

@@ -32,6 +32,7 @@ public class CountEntitiesResponse {
     this.collectionEntityCount = collectionEntityCount;
   }
 
+  /** @return collection entity count */
   public long getCollectionEntityCount() {
     return collectionEntityCount;
   }

+ 20 - 17
src/main/java/io/milvus/client/IndexType.java → src/main/java/io/milvus/client/DataType.java

@@ -23,32 +23,35 @@ import java.util.Arrays;
 import java.util.Optional;
 
 /**
- * Represents different types of indexing method to query the collection. Refer to <a
- * href="https://milvus.io/docs/index.md">https://milvus.io/docs/index.md</a>
- * for more information.
+ * Represents available data types.
  */
-public enum IndexType {
-  INVALID(0),
-  FLAT(1),
-  IVFLAT(2),
-  IVF_SQ8(3),
-  RNSG(4),
-  IVF_SQ8_H(5),
-  IVF_PQ(6),
-  HNSW(11),
-  ANNOY(12),
+public enum DataType {
+  NONE(0),
+  BOOL(1),
+  INT8(2),
+  INT16(3),
+  INT32(4),
+  INT64(5),
+
+  FLOAT(10),
+  DOUBLE(11),
+
+  STRING(20),
+
+  VECTOR_BINARY(100),
+  VECTOR_FLOAT(101),
 
   UNKNOWN(-1);
 
   private final int val;
 
-  IndexType(int val) {
+  DataType(int val) {
     this.val = val;
   }
 
-  public static IndexType valueOf(int val) {
-    Optional<IndexType> search =
-        Arrays.stream(values()).filter(indexType -> indexType.val == val).findFirst();
+  public static DataType valueOf(int val) {
+    Optional<DataType> search =
+        Arrays.stream(values()).filter(dataType -> dataType.val == val).findFirst();
     return search.orElse(UNKNOWN);
   }
 

+ 68 - 0
src/main/java/io/milvus/client/FieldBuilder.java

@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.milvus.client;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.json.JSONObject;
+
+/** Contains Field Parameter Builder */
+public class FieldBuilder {
+  private Map<String, Object> fields;
+
+  /** Initialize required field information: field name and data type */
+  public FieldBuilder(String fieldName, DataType fieldType) {
+    this.fields = new HashMap<>();
+    this.fields.put("field", fieldName);
+    this.fields.put("type", fieldType);
+  }
+
+  /**
+   * Add key-value pair to <code>fields</code>.
+   *
+   * @param key The param key
+   * @param value The param value
+   * @return <code>FieldBuilder</code>
+   */
+  public FieldBuilder param(String key, Object value) {
+    if (!fields.containsKey("params")) {
+      fields.put("params", new JSONObject().put(key, value));
+    } else {
+      ((JSONObject) fields.get("params")).put(key, value);
+    }
+    return this;
+  }
+
+  /**
+   * Add values to fields. Used for insert operation. This should be a list of object whose type
+   * corresponds to relative field DataType.
+   *
+   * @param value The value
+   * @return <code>FieldBuilder</code>
+   */
+  public FieldBuilder values(Object value) {
+    this.fields.put("values", value);
+    return this;
+  }
+
+  public Map<String, Object> build() {
+    return this.fields;
+  }
+}

+ 1 - 2
src/main/java/io/milvus/client/GetCollectionInfoResponse.java

@@ -24,8 +24,7 @@ import java.util.Optional;
 
 /**
  * Contains the returned <code>response</code> and <code>collectionMapping</code> for <code>
- * getCollectionInfo
- * </code>
+ * getCollectionInfo</code>
  */
 public class GetCollectionInfoResponse {
   private final Response response;

+ 13 - 18
src/main/java/io/milvus/client/GetEntityByIDResponse.java

@@ -1,34 +1,29 @@
 package io.milvus.client;
 
-import java.nio.ByteBuffer;
 import java.util.List;
+import java.util.Map;
 
 /**
- * Contains the returned <code>response</code> and either a <code>List</code> of <code>floatVectors
- * </code> or <code>
- * binaryVectors</code> for <code>getEntityByID</code>. If the id does not exist, both float and
- * binary vectors corresponding to the id will be empty.
+ * Contains the returned <code>response</code>, valid ids within query and a <code>List</code> of
+ * fields map for <code>getEntityByID</code>.
  */
 public class GetEntityByIDResponse {
   private final Response response;
-  private final List<List<Float>> floatVectors;
-  private final List<ByteBuffer> binaryVectors;
+  private List<Map<String, Object>> fieldsMap;
 
   GetEntityByIDResponse(
-      Response response, List<List<Float>> floatVectors, List<ByteBuffer> binaryVectors) {
+      Response response, List<Map<String, Object>> fieldsMap) {
     this.response = response;
-    this.floatVectors = floatVectors;
-    this.binaryVectors = binaryVectors;
+    this.fieldsMap = fieldsMap;
   }
 
-  public List<List<Float>> getFloatVectors() {
-    return floatVectors;
-  }
-
-  /** @return a <code>List</code> of <code>ByteBuffer</code> object */
-  public List<ByteBuffer> getBinaryVectors() {
-    return binaryVectors;
-  }
+  /**
+   * @return A <code>List</code> of map with fields information. The list order corresponds
+   * to query IDs. Each <code>Map</code> maps field names to records in a row.
+   * The record object can be one of int, long, float, double, List<Float> or List<Byte>
+   * depending on the field's <code>DataType</code> you specified.
+   */
+  public List<Map<String, Object>> getFieldsMap() { return fieldsMap; }
 
   public Response getResponse() {
     return response;

+ 0 - 61
src/main/java/io/milvus/client/GetIndexInfoResponse.java

@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package io.milvus.client;
-
-import javax.annotation.Nullable;
-import java.util.Optional;
-
-/**
- * Contains the returned <code>response</code> and <code>index</code> for <code>getIndexInfo</code>
- */
-public class GetIndexInfoResponse {
-  private final Response response;
-  private final Index index;
-
-  GetIndexInfoResponse(Response response, @Nullable Index index) {
-    this.response = response;
-    this.index = index;
-  }
-
-  /**
-   * @return an <code>Optional</code> object which may or may not contain an <code>Index</code>
-   *     object
-   * @see Optional
-   */
-  public Optional<Index> getIndex() {
-    return Optional.ofNullable(index);
-  }
-
-  public Response getResponse() {
-    return response;
-  }
-
-  /** @return <code>true</code> if the response status equals SUCCESS */
-  public boolean ok() {
-    return response.ok();
-  }
-
-  @Override
-  public String toString() {
-    return String.format(
-        "GetIndexInfoResponse {%s, %s}",
-        response.toString(), index == null ? "Index = Null" : index.toString());
-  }
-}

+ 1 - 0
src/main/java/io/milvus/client/HasCollectionResponse.java

@@ -32,6 +32,7 @@ public class HasCollectionResponse {
     this.hasCollection = hasCollection;
   }
 
+  /** @return <code>true</code> if the collection is present */
   public boolean hasCollection() {
     return hasCollection;
   }

+ 1 - 0
src/main/java/io/milvus/client/HasPartitionResponse.java

@@ -32,6 +32,7 @@ public class HasPartitionResponse {
         this.hasPartition = hasPartition;
     }
 
+    /** @return <code>true</code> if the partition is present */
     public boolean hasPartition() {
         return hasPartition;
     }

+ 34 - 36
src/main/java/io/milvus/client/Index.java

@@ -21,15 +21,19 @@ package io.milvus.client;
 
 import javax.annotation.Nonnull;
 
-/** Represents an index containing <code>indexType</code> and <code>nList</code> */
+/** Represents an index containing <code>fieldName</code>, <code>indexName</code> and
+ * <code>paramsInJson</code>, which contains index_type, params etc.
+ */
 public class Index {
   private final String collectionName;
-  private final IndexType indexType;
+  private final String fieldName;
+  private final String indexName;
   private final String paramsInJson;
 
   private Index(@Nonnull Builder builder) {
     this.collectionName = builder.collectionName;
-    this.indexType = builder.indexType;
+    this.fieldName = builder.fieldName;
+    this.indexName = builder.indexName;
     this.paramsInJson = builder.paramsInJson;
   }
 
@@ -37,8 +41,12 @@ public class Index {
     return collectionName;
   }
 
-  public IndexType getIndexType() {
-    return indexType;
+  public String getFieldName() {
+    return fieldName;
+  }
+
+  public String getIndexName() {
+    return indexName;
   }
 
   public String getParamsInJson() {
@@ -50,8 +58,8 @@ public class Index {
     return "Index {"
         + "collectionName="
         + collectionName
-        + ", indexType="
-        + indexType
+        + ", fieldName="
+        + fieldName
         + ", params="
         + paramsInJson
         + '}';
@@ -61,49 +69,39 @@ public class Index {
   public static class Builder {
     // Required parameters
     private final String collectionName;
-    private final IndexType indexType;
+    private final String fieldName;
 
     // Optional parameters - initialized to default values
-    private String paramsInJson;
+    private String paramsInJson = "{}";
+    private String indexName = "";
 
     /**
-     * @param collectionName collection to create index on
-     * @param indexType a <code>IndexType</code> object
+     * @param collectionName collection to create index for
+     * @param fieldName name of the field on which index is built.
      */
-    public Builder(@Nonnull String collectionName, @Nonnull IndexType indexType) {
+    public Builder(@Nonnull String collectionName, @Nonnull String fieldName) {
       this.collectionName = collectionName;
-      this.indexType = indexType;
+      this.fieldName = fieldName;
     }
 
     /**
-     * Optional. Default to empty <code>String</code>. Index parameters are different for different
-     * index types. Refer to <a
-     * href="https://milvus.io/docs/milvus_operation.md">https://milvus.io/docs/milvus_operation.md</a>
-     * for more information.
-     *
+     * Optional. The parameters for building an index. Index parameters are different for different
+     * index types. Refer to Milvus documentation for more information.
      * <pre>
-     * FLAT/IVFLAT/SQ8: {"nlist": 16384}
-     * nlist range:[1, 999999]
-     *
-     * IVFPQ: {"nlist": 16384, "m": 12}
-     * nlist range:[1, 999999]
-     * m is decided by dim and have a couple of results.
-     *
-     * NSG: {"search_length": 45, "out_degree": 50, "candidate_pool_size": 300, "knng": 100}
-     * search_length range:[10, 300]
-     * out_degree range:[5, 300]
-     * candidate_pool_size range:[50, 1000]
-     * knng range:[5, 300]
-     *
-     * HNSW: {"M": 16, "efConstruction": 500}
-     * M range:[5, 48]
-     * efConstruction range:[100, 500]
+     * "index_type": one of the values: FLAT, IVF_FLAT, IVF_SQ8, NSG, IVF_SQ8_HYBRID, IVF_PQ,
+     *                                  HNSW, RHNSW_FLAT, RHNSW_PQ, RHNSW_SQ, ANNOY
+     * "metric_type": one of the values: L2, IP, HAMMING, JACCARD, TANIMOTO,
+     *                                   SUBSTRUCTURE, SUPERSTRUCTURE
+     * "params": optional parameters for index, including <code>nlist</code>
      *
-     * ANNOY: {"n_trees": 4}
-     * n_trees range: [1, 16384)
+     * Example param:
+     * <code>
+     *   {"index_type": "IVF_FLAT", "metric_type": "IP", "params": {nlist": 2048}}
+     * </code>
      * </pre>
      *
      * @param paramsInJson extra parameters in JSON format
+     * @see JsonBuilder
      * @return <code>Builder</code>
      */
     public Builder withParamsInJson(@Nonnull String paramsInJson) {

+ 49 - 38
src/main/java/io/milvus/client/InsertParam.java

@@ -19,24 +19,22 @@
 
 package io.milvus.client;
 
+import java.util.Map;
 import javax.annotation.Nonnull;
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 
 /** Contains parameters for <code>insert</code> */
 public class InsertParam {
   private final String collectionName;
-  private final List<List<Float>> floatVectors;
-  private final List<ByteBuffer> binaryVectors;
-  private final List<Long> vectorIds;
+  private final List<? extends Map<String, Object>> fields;
+  private final List<Long> entityIds;
   private final String partitionTag;
 
   private InsertParam(@Nonnull Builder builder) {
     this.collectionName = builder.collectionName;
-    this.floatVectors = builder.floatVectors;
-    this.binaryVectors = builder.binaryVectors;
-    this.vectorIds = builder.vectorIds;
+    this.fields = builder.fields;
+    this.entityIds = builder.entityIds;
     this.partitionTag = builder.partitionTag;
   }
 
@@ -44,16 +42,10 @@ public class InsertParam {
     return collectionName;
   }
 
-  public List<List<Float>> getFloatVectors() {
-    return floatVectors;
-  }
-
-  public List<ByteBuffer> getBinaryVectors() {
-    return binaryVectors;
-  }
+  public List<? extends Map<String, Object>> getFields() { return fields; }
 
-  public List<Long> getVectorIds() {
-    return vectorIds;
+  public List<Long> getEntityIds() {
+    return entityIds;
   }
 
   public String getPartitionTag() {
@@ -62,55 +54,74 @@ public class InsertParam {
 
   /** Builder for <code>InsertParam</code> */
   public static class Builder {
-    // Required parameters
+    // Required parameter
     private final String collectionName;
 
     // Optional parameters - initialized to default values
-    private List<List<Float>> floatVectors = new ArrayList<>();
-    private List<ByteBuffer> binaryVectors = new ArrayList<>();
-    private List<Long> vectorIds = new ArrayList<>();
+    private List<Map<String, Object>> fields = new ArrayList<>();
+    private List<Long> entityIds = new ArrayList<>();
     private String partitionTag = "";
 
-    /** @param collectionName collection to insert vectors to */
+    /** @param collectionName collection to insert entities to */
     public Builder(@Nonnull String collectionName) {
       this.collectionName = collectionName;
     }
 
     /**
-     * Default to an empty <code>ArrayList</code>. You can only insert either float or binary
-     * vectors to a collection, not both.
+     * The data you wish to insert into collections. Default to an empty <code>ArrayList</code>
+     *
+     * @param fields a <code>List</code> of <code>Map</code> that contains data to insert for each
+     *     field name. "field", "values" and "type" must be present in each map. The size of
+     *     map["values"] must match for all maps in the list, which is equivalent to entity count.
+     *     Example fields:
+     * <pre>
+     *     <code>
+     *   [
+     *         {"field": "A", "values": A_list, "type": DataType.INT32},
+     *         {"field": "B", "values": B_list, "type": DataType.INT32},
+     *         {"field": "C", "values": C_list, "type": DataType.INT64},
+     *         {"field": "Vec", "values": vecs, "type": DataType.VECTOR_FLOAT}
+     *   ]
+     *     </code>
+     * </pre>
      *
-     * @param floatVectors a <code>List</code> of float vectors to insert. Each inner <code>List
-     *     </code> represents a float vector.
      * @return <code>Builder</code>
      */
-    public Builder withFloatVectors(@Nonnull List<List<Float>> floatVectors) {
-      this.floatVectors = floatVectors;
+    public Builder withFields(@Nonnull List<Map<String, Object>> fields) {
+      this.fields = fields;
       return this;
     }
 
     /**
-     * Default to an empty <code>ArrayList</code>. You can only insert either float or binary
-     * vectors to a collection, not both.
+     * Add a single field to collection. Example field:
+     * <pre>
+     *   <code>
+     *      {"field": "A", "values": A_list, "type": DataType.INT64}, or
+     *      {"field": "B", "values": B_list, "type": DataType.INT32}, or
+     *      {"field": "C", "values": C_list, "type": DataType.FLOAT}, or
+     *      {"field": "Vec", "values": vecs, "type": DataType.VECTOR_FLOAT}
+     *   </code>
+     * </pre>
      *
-     * @param binaryVectors a <code>List</code> of binary vectors to insert. Each <code>ByteBuffer
-     *     </code> object represents a binary vector, with every 8 bits constituting a byte.
+     * @param field A field must have keys "field", "values" and "type".
+     *              <code>FieldBuilder</code> can be used to create a field.
+     * @see FieldBuilder
      * @return <code>Builder</code>
-     * @see ByteBuffer
      */
-    public Builder withBinaryVectors(@Nonnull List<ByteBuffer> binaryVectors) {
-      this.binaryVectors = binaryVectors;
+    public Builder field(@Nonnull Map<String, Object> field) {
+      this.fields.add(field);
       return this;
     }
 
     /**
-     * Optional. Default to an empty <code>ArrayList</code>
+     * Optional. Default to an empty <code>ArrayList</code>. Only needed when entity ids are not
+     * auto-generated by milvus. This is specified when creating collection.
      *
-     * @param vectorIds a <code>List</code> of ids associated with the vectors to insert
+     * @param entityIds a <code>List</code> of ids associated with the entities to insert.
      * @return <code>Builder</code>
      */
-    public Builder withVectorIds(@Nonnull List<Long> vectorIds) {
-      this.vectorIds = vectorIds;
+    public Builder withEntityIds(@Nonnull List<Long> entityIds) {
+      this.entityIds = entityIds;
       return this;
     }
 

+ 7 - 7
src/main/java/io/milvus/client/InsertResponse.java

@@ -22,19 +22,19 @@ package io.milvus.client;
 import java.util.List;
 
 /**
- * Contains the returned <code>response</code> and <code>vectorIds</code> for <code>insert</code>
+ * Contains the returned <code>response</code> and <code>entityIds</code> for <code>insert</code>
  */
 public class InsertResponse {
   private final Response response;
-  private final List<Long> vectorIds;
+  private final List<Long> entityIds;
 
-  InsertResponse(Response response, List<Long> vectorIds) {
+  InsertResponse(Response response, List<Long> entityIds) {
     this.response = response;
-    this.vectorIds = vectorIds;
+    this.entityIds = entityIds;
   }
 
-  public List<Long> getVectorIds() {
-    return vectorIds;
+  public List<Long> getEntityIds() {
+    return entityIds;
   }
 
   public Response getResponse() {
@@ -49,6 +49,6 @@ public class InsertResponse {
   @Override
   public String toString() {
     return String.format(
-        "InsertResponse {%s, returned %d vector ids}", response.toString(), this.vectorIds.size());
+        "InsertResponse {%s, returned %d entity ids}", response.toString(), this.entityIds.size());
   }
 }

+ 68 - 0
src/main/java/io/milvus/client/JsonBuilder.java

@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.milvus.client;
+
+import javax.annotation.Nonnull;
+import org.json.JSONObject;
+
+/** Contains Json Parameter Builder */
+public class JsonBuilder {
+  private String paramsInJson;
+
+  public JsonBuilder() {
+    this.paramsInJson = "{}";
+  }
+
+  /**
+   * Add key-value pair to paramsInJson.
+   *
+   * @param key The param key
+   * @param value The param value
+   * @return <code>JsonBuilder</code>
+   */
+  public JsonBuilder param(String key, Object value) {
+    JSONObject jsonObject = new JSONObject(this.paramsInJson);
+    jsonObject.put(key, value);
+    this.paramsInJson = jsonObject.toString();
+    return this;
+  }
+
+  /**
+   * Add key-value pair to "params" in paramsInJson. Used by index.
+   *
+   * @param key The param key
+   * @param value The param value
+   * @return <code>JsonBuilder</code>
+   */
+  public JsonBuilder indexParam(String key, Object value) {
+    JSONObject jsonObject = new JSONObject(this.paramsInJson);
+    if (!jsonObject.has("params")) {
+      jsonObject.put("params", new JSONObject().put(key, value));
+    } else {
+      ((JSONObject) jsonObject.get("params")).put(key, value);
+    }
+    this.paramsInJson = jsonObject.toString();
+    return this;
+  }
+
+  public String build() {
+    return this.paramsInJson;
+  }
+}

+ 1 - 2
src/main/java/io/milvus/client/ListCollectionsResponse.java

@@ -23,8 +23,7 @@ import java.util.List;
 
 /**
  * Contains the returned <code>response</code> and <code>collectionNames</code> for <code>
- * listCollections
- * </code>
+ * listCollections</code>
  */
 public class ListCollectionsResponse {
   private final Response response;

+ 8 - 2
src/main/java/io/milvus/client/ListPartitionsResponse.java

@@ -23,8 +23,7 @@ import java.util.List;
 
 /**
  * Contains the returned <code>response</code> and <code>partitionList</code> for <code>
- * listPartitions
- * </code>
+ * listPartitions</code>
  */
 public class ListPartitionsResponse {
   private final Response response;
@@ -48,4 +47,11 @@ public class ListPartitionsResponse {
   public boolean ok() {
     return response.ok();
   }
+
+  @Override
+  public String toString() {
+    return String.format(
+        "ListPartitionsResponse {%s, partition names = %s}",
+        response, partitionList.toString());
+  }
 }

+ 0 - 64
src/main/java/io/milvus/client/MetricType.java

@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package io.milvus.client;
-
-import java.util.Arrays;
-import java.util.Optional;
-
-/**
- * Represents available metric types. Refer to <a
- * href="https://milvus.io/docs/metric.md">https://milvus.io/docs/metric.md</a>
- * for more information.
- */
-public enum MetricType {
-  INVALID(0),
-  /** Euclidean distance. For float vectors only */
-  L2(1),
-  /** Inner product. For float vectors only */
-  IP(2),
-  /** Hamming distance. For binary vectors only */
-  HAMMING(3),
-  /** Jaccard distance. For binary vectors only */
-  JACCARD(4),
-  /** Tanimoto distance. For binary vectors only */
-  TANIMOTO(5),
-  /** Substructure. For binary vectors only */
-  SUBSTRUCTURE(6),
-  /** Superstructure. For binary vectors only */
-  SUPERSTRUCTURE(7),
-
-  UNKNOWN(-1);
-
-  private final int val;
-
-  MetricType(int val) {
-    this.val = val;
-  }
-
-  public static MetricType valueOf(int val) {
-    Optional<MetricType> search =
-        Arrays.stream(values()).filter(metricType -> metricType.val == val).findFirst();
-    return search.orElse(UNKNOWN);
-  }
-
-  public int getVal() {
-    return val;
-  }
-}

+ 119 - 107
src/main/java/io/milvus/client/MilvusClient.java

@@ -20,85 +20,71 @@
 package io.milvus.client;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import io.grpc.Metadata;
-import org.apache.commons.lang3.exception.ExceptionUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Supplier;
 
 /** The Milvus Client Interface */
 public interface MilvusClient {
 
-  String clientVersion = new Supplier<String>() {
-    @Override
-    public String get() {
-      Properties properties = new Properties();
-      InputStream inputStream = MilvusClient.class
-          .getClassLoader().getResourceAsStream("milvus-client.properties");
-      try {
-        properties.load(inputStream);
-      } catch (IOException ex) {
-        ExceptionUtils.wrapAndThrow(ex);
-      } finally {
-        try {
-          inputStream.close();
-        } catch (IOException ex) {
-        }
-      }
-      return properties.getProperty("version");
-    }
-  }.get();
-
-  Metadata commonHeaders = new Supplier<Metadata>() {
-    @Override
-    public Metadata get() {
-      Metadata metadata = new Metadata();
-      Metadata.Key<String> key = Metadata.Key.of("Milvus-Client-Version", Metadata.ASCII_STRING_MARSHALLER);
-      metadata.put(key, clientVersion);
-      return metadata;
-    }
-  }.get();
-
-  /** @return current Milvus client version */
+  String clientVersion = "0.9.0";
+
+  /** @return current Milvus client version: 0.9.0 */
   default String getClientVersion() {
     return clientVersion;
   }
 
   /**
-   * Close this MilvusClient. Wait at most 1 minute for graceful shutdown.
+   * Connects to Milvus server
+   *
+   * @param connectParam the <code>ConnectParam</code> object
+   * <pre>
+   * example usage:
+   * <code>
+   * ConnectParam connectParam = new ConnectParam.Builder()
+   *                                             .withHost("localhost")
+   *                                             .withPort(19530)
+   *                                             .withConnectTimeout(10, TimeUnit.SECONDS)
+   *                                             .withKeepAliveTime(Long.MAX_VALUE, TimeUnit.NANOSECONDS)
+   *                                             .withKeepAliveTimeout(20, TimeUnit.SECONDS)
+   *                                             .keepAliveWithoutCalls(false)
+   *                                             .withIdleTimeout(24, TimeUnit.HOURS)
+   *                                             .build();
+   * </code>
+   * </pre>
+   *
+   * @return <code>Response</code>
+   * @throws ConnectFailedException if client failed to connect
+   * @see ConnectParam
+   * @see Response
+   * @see ConnectFailedException
    */
-  default void close() {
-    close(TimeUnit.MINUTES.toSeconds(1));
-  }
+  Response connect(ConnectParam connectParam) throws ConnectFailedException;
 
   /**
-   * Close this MilvusClient. Wait at most `maxWaitSeconds` for graceful shutdown.
+   * Disconnects from Milvus server
+   *
+   * @return <code>Response</code>
+   * @throws InterruptedException if disconnect interrupted
+   * @see Response
    */
-  void close(long maxWaitSeconds);
-
-  MilvusClient withTimeout(long timeout, TimeUnit timeoutUnit);
+  Response disconnect() throws InterruptedException;
 
   /**
    * Creates collection specified by <code>collectionMapping</code>
    *
    * @param collectionMapping the <code>CollectionMapping</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
-   * CollectionMapping collectionMapping = new CollectionMapping.Builder(collectionName, dimension)
-   *                                          .withIndexFileSize(1024)
-   *                                          .withMetricType(MetricType.IP)
-   *                                          .build();
+   * CollectionMapping collectionMapping = new CollectionMapping.Builder(collectionName)
+   *                                                            .withFields(fields)
+   *                                                            .withParamsInJson("{"segment_row_count": 100000}")
+   *                                                            .build();
    * </code>
+   * Refer to <code>withFields</code> method for example <code>fields</code> usage.
    * </pre>
    *
    * @return <code>Response</code>
    * @see CollectionMapping
-   * @see MetricType
    * @see Response
    */
   Response createCollection(CollectionMapping collectionMapping);
@@ -126,18 +112,19 @@ public interface MilvusClient {
    * Creates index specified by <code>index</code>
    *
    * @param index the <code>Index</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
-   * Index index = new Index.Builder(collectionName, IndexType.IVF_SQ8)
-   *                        .withParamsInJson("{\"nlist\": 16384}")
+   * Index index = new Index.Builder(collectionName, fieldName)
+   *                        .withParamsInJson(
+   *                            "{"index_type": "IVF_FLAT", "metric_type": "L2",
+   *                              "params": {"nlist": 16384}}")
    *                        .build();
    * </code>
    * </pre>
    *
    * @return <code>Response</code>
    * @see Index
-   * @see IndexType
    * @see Response
    */
   Response createIndex(Index index);
@@ -146,18 +133,19 @@ public interface MilvusClient {
    * Creates index specified by <code>index</code> asynchronously
    *
    * @param index the <code>Index</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
-   * Index index = new Index.Builder(collectionName, IndexType.IVF_SQ8)
-   *                        .withParamsInJson("{\"nlist\": 16384}")
+   * Index index = new Index.Builder(collectionName, fieldName)
+   *                        .withParamsInJson(
+   *                            "{"index_type": "IVF_FLAT", "metric_type": "L2",
+   *                              "params\": {"nlist": 16384}}")
    *                        .build();
    * </code>
    * </pre>
    *
    * @return a <code>ListenableFuture</code> object which holds the <code>Response</code>
    * @see Index
-   * @see IndexType
    * @see Response
    * @see ListenableFuture
    */
@@ -206,12 +194,12 @@ public interface MilvusClient {
    * Inserts data specified by <code>insertParam</code>
    *
    * @param insertParam the <code>InsertParam</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
    * InsertParam insertParam = new InsertParam.Builder(collectionName)
-   *                                          .withFloatVectors(floatVectors)
-   *                                          .withVectorIds(vectorIds)
+   *                                          .withFields(fields)
+   *                                          .withEntityIds(entityIds)
    *                                          .withPartitionTag(tag)
    *                                          .build();
    * </code>
@@ -228,12 +216,12 @@ public interface MilvusClient {
    * Inserts data specified by <code>insertParam</code> asynchronously
    *
    * @param insertParam the <code>InsertParam</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
    * InsertParam insertParam = new InsertParam.Builder(collectionName)
-   *                                          .withFloatVectors(floatVectors)
-   *                                          .withVectorIds(vectorIds)
+   *                                          .withFields(fields)
+   *                                          .withEntityIds(entityIds)
    *                                          .withPartitionTag(tag)
    *                                          .build();
    * </code>
@@ -248,17 +236,16 @@ public interface MilvusClient {
   ListenableFuture<InsertResponse> insertAsync(InsertParam insertParam);
 
   /**
-   * Searches vectors specified by <code>searchParam</code>
+   * Searches entities specified by <code>searchParam</code>
    *
    * @param searchParam the <code>SearchParam</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
    * SearchParam searchParam = new SearchParam.Builder(collectionName)
-   *                                          .withFloatVectors(floatVectors)
-   *                                          .withTopK(topK)
+   *                                          .withDSL(dslStatement)
    *                                          .withPartitionTags(partitionTagsList)
-   *                                          .withParamsInJson("{\"nprobe\": 20}")
+   *                                          .withParamsInJson("{"fields": ["B"]}")
    *                                          .build();
    * </code>
    * </pre>
@@ -272,17 +259,16 @@ public interface MilvusClient {
   SearchResponse search(SearchParam searchParam);
 
   /**
-   * Searches vectors specified by <code>searchParam</code> asynchronously
+   * Searches entities specified by <code>searchParam</code> asynchronously
    *
    * @param searchParam the <code>SearchParam</code> object
-   *     <pre>
+   * <pre>
    * example usage:
    * <code>
    * SearchParam searchParam = new SearchParam.Builder(collectionName)
-   *                                          .withFloatVectors(floatVectors)
-   *                                          .withTopK(topK)
+   *                                          .withDSL(dslStatement)
    *                                          .withPartitionTags(partitionTagsList)
-   *                                          .withParamsInJson("{\"nprobe\": 20}")
+   *                                          .withParamsInJson("{"fields": ["B"]}")
    *                                          .build();
    * </code>
    * </pre>
@@ -300,6 +286,7 @@ public interface MilvusClient {
    * Gets collection info
    *
    * @param collectionName collection to describe
+   * @return <code>GetCollectionInfoResponse</code>
    * @see GetCollectionInfoResponse
    * @see CollectionMapping
    * @see Response
@@ -318,7 +305,7 @@ public interface MilvusClient {
   /**
    * Gets current entity count of a collection
    *
-   * @param collectionName collection to count entities
+   * @param collectionName collection name
    * @return <code>CountEntitiesResponse</code>
    * @see CountEntitiesResponse
    * @see Response
@@ -326,7 +313,7 @@ public interface MilvusClient {
   CountEntitiesResponse countEntities(String collectionName);
 
   /**
-   * Get server status
+   * Gets server status
    *
    * @return <code>Response</code>
    * @see Response
@@ -334,7 +321,7 @@ public interface MilvusClient {
   Response getServerStatus();
 
   /**
-   * Get server version
+   * Gets server version
    *
    * @return <code>Response</code>
    * @see Response
@@ -358,24 +345,16 @@ public interface MilvusClient {
    */
   Response loadCollection(String collectionName);
 
-  /**
-   * Gets collection index information
-   *
-   * @param collectionName collection to get info from
-   * @see GetIndexInfoResponse
-   * @see Index
-   * @see Response
-   */
-  GetIndexInfoResponse getIndexInfo(String collectionName);
-
   /**
    * Drops collection index
    *
-   * @param collectionName collection to drop index of
+   * @param collectionName The collection to drop index.
+   * @param fieldName Name of the field to drop index for. If this is set to empty string,
+   *                  index of all fields in the collection will be dropped.
    * @return <code>Response</code>
    * @see Response
    */
-  Response dropIndex(String collectionName);
+  Response dropIndex(String collectionName, String fieldName);
 
   /**
    * Shows collection information. A collection consists of one or multiple partitions (including
@@ -390,10 +369,23 @@ public interface MilvusClient {
   Response getCollectionStats(String collectionName);
 
   /**
-   * Gets vectors data by id array
+   * Gets entities data by id array
    *
-   * @param collectionName collection to get vectors from
-   * @param ids a <code>List</code> of vector ids
+   * @param collectionName collection to get entities from
+   * @param ids a <code>List</code> of entity ids
+   * @param fieldNames  a <code>List</code> of field names. Server will only return entity
+   *                    information for these fields.
+   * @return <code>GetEntityByIDResponse</code>
+   * @see GetEntityByIDResponse
+   * @see Response
+   */
+  GetEntityByIDResponse getEntityByID(String collectionName, List<Long> ids, List<String> fieldNames);
+
+  /**
+   * Gets entities data by id array
+   *
+   * @param collectionName collection to get entities from
+   * @param ids a <code>List</code> of entity ids
    * @return <code>GetEntityByIDResponse</code>
    * @see GetEntityByIDResponse
    * @see Response
@@ -401,21 +393,21 @@ public interface MilvusClient {
   GetEntityByIDResponse getEntityByID(String collectionName, List<Long> ids);
 
   /**
-   * Gets all vector ids in a segment
+   * Gets all entity ids in a segment
    *
-   * @param collectionName collection to get vector ids from
-   * @param segmentName segment name in the collection
+   * @param collectionName collection to get entity ids from
+   * @param segmentId segment id in the collection
    * @return <code>ListIDInSegmentResponse</code>
    * @see ListIDInSegmentResponse
    * @see Response
    */
-  ListIDInSegmentResponse listIDInSegment(String collectionName, String segmentName);
+  ListIDInSegmentResponse listIDInSegment(String collectionName, Long segmentId);
 
   /**
    * Deletes data in a collection by a list of ids
    *
    * @param collectionName collection to delete ids from
-   * @param ids a <code>List</code> of vector ids to delete
+   * @param ids a <code>List</code> of entity ids to delete
    * @return <code>Response</code>
    * @see Response
    */
@@ -468,21 +460,41 @@ public interface MilvusClient {
    * data size after compaction is still larger than indexFileSize). Data was only soft-deleted
    * until you call compact.
    *
-   * @param collectionName name of collection to compact
+   * @param compactParam the <code>CompactParam</code> object
+   * <pre>
+   * example usage:
+   * <code>
+   * CompactParam compactParam = new CompactParam.Builder(collectionName)
+   *                                             .withThreshold(0.3)
+   *                                             .build();
+   * </code>
+   * </pre>
+   *
    * @return <code>Response</code>
+   * @see CompactParam
    * @see Response
    */
-  Response compact(String collectionName);
+  Response compact(CompactParam compactParam);
 
   /**
-   * Compacts the collection asynchronously, erasing deleted data from disk and rebuild index in
-   * background (if the data size after compaction is still larger than indexFileSize). Data was
-   * only soft-deleted until you call compact.
+   * Compacts the collection, erasing deleted data from disk and rebuild index in background (if the
+   * data size after compaction is still larger than indexFileSize). Data was only soft-deleted
+   * until you call compact.
+   *
+   * @param compactParam the <code>CompactParam</code> object
+   * <pre>
+   * example usage:
+   * <code>
+   * CompactParam compactParam = new CompactParam.Builder(collectionName)
+   *                                             .withThreshold(0.3)
+   *                                             .build();
+   * </code>
+   * </pre>
    *
-   * @param collectionName name of collection to compact
    * @return a <code>ListenableFuture</code> object which holds the <code>Response</code>
+   * @see CompactParam
    * @see Response
    * @see ListenableFuture
    */
-  ListenableFuture<Response> compactAsync(String collectionName);
+  ListenableFuture<Response> compactAsync(CompactParam compactParam);
 }

File diff suppressed because it is too large
+ 510 - 193
src/main/java/io/milvus/client/MilvusGrpcClient.java


+ 52 - 71
src/main/java/io/milvus/client/SearchParam.java

@@ -19,27 +19,24 @@
 
 package io.milvus.client;
 
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import javax.annotation.Nonnull;
 
 /** Contains parameters for <code>search</code> */
 public class SearchParam {
 
   private final String collectionName;
-  private final List<List<Float>> floatVectors;
-  private final List<ByteBuffer> binaryVectors;
+  private final String dsl;
   private final List<String> partitionTags;
-  private final long topK;
   private final String paramsInJson;
 
   private SearchParam(@Nonnull Builder builder) {
     this.collectionName = builder.collectionName;
-    this.floatVectors = builder.floatVectors;
-    this.binaryVectors = builder.binaryVectors;
+    this.dsl = builder.dsl;
     this.partitionTags = builder.partitionTags;
-    this.topK = builder.topK;
     this.paramsInJson = builder.paramsInJson;
   }
 
@@ -47,37 +44,25 @@ public class SearchParam {
     return collectionName;
   }
 
-  public List<List<Float>> getFloatVectors() {
-    return floatVectors;
-  }
-
-  public List<ByteBuffer> getBinaryVectors() {
-    return binaryVectors;
-  }
+  public String getDSL() { return dsl; }
 
   public List<String> getPartitionTags() {
     return partitionTags;
   }
 
-  public long getTopK() {
-    return topK;
-  }
-
   public String getParamsInJson() {
     return paramsInJson;
   }
 
   /** Builder for <code>SearchParam</code> */
   public static class Builder {
-    // Required parameters
+    // Required parameter
     private final String collectionName;
 
     // Optional parameters - initialized to default values
-    private List<List<Float>> floatVectors = new ArrayList<>();
-    private List<ByteBuffer> binaryVectors = new ArrayList<>();
     private List<String> partitionTags = new ArrayList<>();
-    private long topK = 1024;
-    private String paramsInJson;
+    private String dsl = "{}";
+    private String paramsInJson = "{}";
 
     /** @param collectionName collection to search from */
     public Builder(@Nonnull String collectionName) {
@@ -85,30 +70,49 @@ public class SearchParam {
     }
 
     /**
-     * Default to an empty <code>ArrayList</code>. You can search either float or binary vectors,
-     * not both.
+     * The DSL statement for search. DSL provides a more convenient and idiomatic way to write and
+     * manipulate queries. It is in JSON format (passed into builder as String), and an example of
+     * DSL statement is as follows.
      *
-     * @param floatVectors a <code>List</code> of float vectors to be queries. Each inner <code>List
-     *     </code> represents a float vector.
-     * @return <code>Builder</code>
-     */
-    public SearchParam.Builder withFloatVectors(@Nonnull List<List<Float>> floatVectors) {
-      this.floatVectors = floatVectors;
-      return this;
-    }
-
-    /**
-     * Default to an empty <code>ArrayList</code>. You can search either float or binary vectors,
-     * not both.
+     * <pre>
+     *   <code>
+     * {
+     *     "bool": {
+     *         "must": [
+     *             {
+     *                 "term": {
+     *                     "A": [1, 2, 5]
+     *                 }
+     *             },
+     *             {
+     *                 "range": {
+     *                     "B": {"GT": 1, "LT": 100}
+     *                 }
+     *             },
+     *             {
+     *                 "vector": {
+     *                     "Vec": {
+     *                         "topk": 10, "type": "float", "query": list_of_vecs, "params": {"nprobe": 10}
+     *                     }
+     *                 }
+     *             }
+     *         ],
+     *     },
+     * }
+     *   </code>
+     * </pre>
      *
-     * @param binaryVectors a <code>List</code> of binary vectors to be queried. Each <code>
-     *     ByteBuffer</code> object represents a binary vector, with every 8 bits constituting a
-     *     byte.
+     * <p>Note that "vector" must be included in DSL. The "params" in "Vec" is different for different
+     * index types. Refer to Milvus documentation for more information about DSL.</p>
+     *
+     * <p>A "type" key must be present in "Vec" field to indicate whether your query vectors are
+     * "float" or "binary".</p>
+     *
+     * @param dsl The DSL String in JSON format
      * @return <code>Builder</code>
-     * @see ByteBuffer
      */
-    public SearchParam.Builder withBinaryVectors(@Nonnull List<ByteBuffer> binaryVectors) {
-      this.binaryVectors = binaryVectors;
+    public SearchParam.Builder withDSL(@Nonnull String dsl) {
+      this.dsl = dsl;
       return this;
     }
 
@@ -119,40 +123,17 @@ public class SearchParam {
      * @param partitionTags a <code>List</code> of partition tags
      * @return <code>Builder</code>
      */
-    public Builder withPartitionTags(@Nonnull List<String> partitionTags) {
+    public SearchParam.Builder withPartitionTags(@Nonnull List<String> partitionTags) {
       this.partitionTags = partitionTags;
       return this;
     }
 
     /**
-     * Optional. Limits search result to <code>topK</code>. Default to 1024.
-     *
-     * @param topK a topK number
-     * @return <code>Builder</code>
-     */
-    public Builder withTopK(long topK) {
-      this.topK = topK;
-      return this;
-    }
-
-    /**
-     * Optional. Default to empty <code>String</code>. Search parameters are different for different
-     * index types. Refer to <a
-     * href="https://milvus.io/docs/milvus_operation.md">https://milvus.io/docs/milvus_operation.md</a>
-     * for more information.
-     *
+     * Optional. Default to empty <code>String</code>. This is to specify the fields you would like
+     * Milvus server to return from query results. No field information will be returned if this
+     * is not specified. Example:
      * <pre>
-     *   FLAT/IVFLAT/SQ8/IVFPQ: {"nprobe": 32}
-     *   nprobe range:[1,999999]
-     *
-     *   NSG: {"search_length": 100}
-     *   search_length range:[10, 300]
-     *
-     *   HNSW: {"ef": 64}
-     *   ef range:[topk, 4096]
-     *
-     *   ANNOY: {search_k", 0.05 * totalDataCount}
-     *   search_k range: none
+     *   {"fields": ["B", "D"]}
      * </pre>
      *
      * @param paramsInJson extra parameters in JSON format

+ 26 - 13
src/main/java/io/milvus/client/SearchResponse.java

@@ -20,13 +20,13 @@
 package io.milvus.client;
 
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import java.util.stream.LongStream;
 
 /**
- * Contains the returned <code>response</code> and <code>queryResultsList</code> for <code>search
- * </code>
+ * Contains the returned <code>response</code> and query results for <code>search</code>
  */
 public class SearchResponse {
 
@@ -35,6 +35,7 @@ public class SearchResponse {
   private long topK;
   private List<List<Long>> resultIdsList;
   private List<List<Float>> resultDistancesList;
+  private List<List<Map<String, Object>>> fieldsMap;
 
   public int getNumQueries() {
     return numQueries;
@@ -54,7 +55,7 @@ public class SearchResponse {
 
   /**
    * @return a <code>List</code> of <code>QueryResult</code>s. Each inner <code>List</code> contains
-   *     the query result of a vector.
+   *     the query result of an entity.
    */
   public List<List<QueryResult>> getQueryResultsList() {
     return IntStream.range(0, numQueries)
@@ -72,7 +73,7 @@ public class SearchResponse {
 
   /**
    * @return a <code>List</code> of result ids. Each inner <code>List</code> contains the result ids
-   *     of a vector.
+   *     of an entity.
    */
   public List<List<Long>> getResultIdsList() {
     return resultIdsList;
@@ -83,8 +84,8 @@ public class SearchResponse {
   }
 
   /**
-   * @return @return a <code>List</code> of result distances. Each inner <code>List</code> contains
-   *     the result distances of a vector.
+   * @return a <code>List</code> of result distances. Each inner <code>List</code> contains
+   *     the result distances of an entity.
    */
   public List<List<Float>> getResultDistancesList() {
     return resultDistancesList;
@@ -102,6 +103,18 @@ public class SearchResponse {
     this.response = response;
   }
 
+  /**
+   * @return A <code>List</code> of map with fields information. Each inner <code>List</code> contains
+   * a <code>Map</code> of field names to records in a row.
+   * The record object can be one of int, long, float, double, List<Float> or List<Byte>
+   * depending on the field's <code>DataType</code> you specified.
+   */
+  public List<List<Map<String, Object>>> getFieldsMap() { return fieldsMap; }
+
+  void setFieldsMap(List<List<Map<String, Object>>> fieldsMap) {
+    this.fieldsMap = fieldsMap;
+  }
+
   /** @return <code>true</code> if the response status equals SUCCESS */
   public boolean ok() {
     return response.ok();
@@ -114,20 +127,20 @@ public class SearchResponse {
   }
 
   /**
-   * Represents a single result of a vector query. Contains the result <code>vectorId</code> and its
-   * <code>distance</code> to the vector being queried
+   * Represents a single result of an entity query. Contains the result <code>entityId</code> and its
+   * <code>distance</code> to the entity being queried
    */
   public static class QueryResult {
-    private final long vectorId;
+    private final long entityId;
     private final float distance;
 
-    QueryResult(long vectorId, float distance) {
-      this.vectorId = vectorId;
+    QueryResult(long entityId, float distance) {
+      this.entityId = entityId;
       this.distance = distance;
     }
 
-    public long getVectorId() {
-      return vectorId;
+    public long getEntityId() {
+      return entityId;
     }
 
     public float getDistance() {

+ 0 - 16
src/main/java/io/milvus/client/exception/InitializationException.java

@@ -1,16 +0,0 @@
-package io.milvus.client.exception;
-
-public class InitializationException extends MilvusException {
-  private String host;
-  private Throwable cause;
-
-  public InitializationException(String host, Throwable cause) {
-    super(false, cause);
-    this.host = host;
-  }
-
-  public InitializationException(String host, String message) {
-    super(false, message);
-    this.host = host;
-  }
-}

+ 0 - 24
src/main/java/io/milvus/client/exception/MilvusException.java

@@ -1,24 +0,0 @@
-package io.milvus.client.exception;
-
-public class MilvusException extends RuntimeException {
-  private boolean fillInStackTrace;
-
-  MilvusException(boolean fillInStackTrace) {
-    this.fillInStackTrace = fillInStackTrace;
-  }
-
-  MilvusException(boolean fillInStackTrace, Throwable cause) {
-    super(cause);
-    this.fillInStackTrace = fillInStackTrace;
-  }
-
-  MilvusException(boolean fillInStackTrace, String message) {
-    super(message);
-    this.fillInStackTrace = fillInStackTrace;
-  }
-
-  @Override
-  public synchronized Throwable fillInStackTrace() {
-    return fillInStackTrace ? super.fillInStackTrace() : this;
-  }
-}

+ 0 - 22
src/main/java/io/milvus/client/exception/UnsupportedServerVersion.java

@@ -1,22 +0,0 @@
-package io.milvus.client.exception;
-
-import io.milvus.client.MilvusClient;
-
-public class UnsupportedServerVersion extends MilvusException {
-  private String host;
-  private String expect;
-  private String actual;
-
-  public UnsupportedServerVersion(String host, String expect, String actual) {
-    super(false);
-    this.host = host;
-    this.expect = expect;
-    this.actual = actual;
-  }
-
-  @Override
-  public String getMessage() {
-    return String.format("%s: Milvus client %s is expected to work with Milvus server %s, but the version of the connected server is %s",
-        host, MilvusClient.clientVersion, expect, actual);
-  }
-}

+ 300 - 84
src/main/proto/milvus.proto

@@ -8,6 +8,26 @@ option java_outer_classname = "MilvusProto";
 
 package milvus.grpc;
 
+/**
+ * @brief Field data type
+ */
+enum DataType {
+    NONE = 0;
+    BOOL = 1;
+    INT8 = 2;
+    INT16 = 3;
+    INT32 = 4;
+    INT64 = 5;
+
+    FLOAT = 10;
+    DOUBLE = 11;
+
+    STRING = 20;
+
+    VECTOR_BINARY = 100;
+    VECTOR_FLOAT = 101;
+}
+
 /**
  * @brief general usage
  */
@@ -32,20 +52,39 @@ message CollectionNameList {
 }
 
 /**
- * @brief Collection schema
- * metric_type: 1-L2, 2-IP
+ * @brief Field name
  */
-message CollectionSchema {
+message FieldName {
+    string collection_name = 1;
+    string field_name = 2;
+}
+
+/**
+ * @brief Collection mapping
+ * @extra_params: key-value pair for extra parameters of the collection
+ *    typically usage:
+ *        extra_params["params"] = {segment_row_count: 1000000, auto_id: true}
+ *    Note:
+ *        the segment_row_count specify segment row count limit for merging
+ *        the auto_id = true means entity id is auto-generated by milvus
+ */
+message Mapping {
     Status status = 1;
     string collection_name = 2;
-    int64 dimension = 3;
-    int64 index_file_size = 4;
-    int32 metric_type = 5;
-    repeated KeyValuePair extra_params = 6;
+    repeated FieldParam fields = 3;
+    repeated KeyValuePair extra_params = 4;
 }
 
 /**
- * @brief Params of partition
+ * @brief Collection mapping list
+ */
+message MappingList {
+    Status status = 1;
+    repeated Mapping mapping_list = 2;
+}
+
+/**
+ * @brief Parameters of partition
  */
 message PartitionParam {
     string collection_name = 1;
@@ -61,70 +100,106 @@ message PartitionList {
 }
 
 /**
- * @brief Record inserted
+ * @brief Vector row record
  */
-message RowRecord {
+message VectorRowRecord {
     repeated float float_data = 1;             //float vector data
     bytes binary_data = 2;                      //binary vector data
 }
 
 /**
- * @brief Params to be inserted
+ * @brief Attribute record
+ */
+message AttrRecord {
+    repeated int32 int32_value = 1;
+    repeated int64 int64_value = 2;
+    repeated float float_value = 3;
+    repeated double double_value = 4;
+}
+
+/**
+ * @brief Vector records
+ */
+message VectorRecord {
+    repeated VectorRowRecord records = 1;
+}
+
+/**
+ * @brief Field values
+ */
+message FieldValue {
+    string field_name = 1;
+    DataType type = 2;
+    AttrRecord attr_record = 3;
+    VectorRecord vector_record = 4;
+}
+
+/**
+ * @brief Parameters for insert action
  */
 message InsertParam {
     string collection_name = 1;
-    repeated RowRecord row_record_array = 2;
-    repeated int64 row_id_array = 3;            //optional
+    repeated FieldValue fields = 2;
+    repeated int64 entity_id_array = 3;            //optional
     string partition_tag = 4;
     repeated KeyValuePair extra_params = 5;
 }
 
 /**
- * @brief Vector ids
+ * @brief Entity ids
  */
-message VectorIds {
+message EntityIds {
     Status status = 1;
-    repeated int64 vector_id_array = 2;
+    repeated int64 entity_id_array = 2;
 }
 
 /**
- * @brief Params for searching vector
+ * @brief Search vector parameters
+ */
+message VectorParam {
+    string json = 1;
+    VectorRecord row_record = 2;
+}
+
+/**
+ * @brief Parameters for search action
  */
 message SearchParam {
     string collection_name = 1;
     repeated string partition_tag_array = 2;
-    repeated RowRecord query_record_array = 3;
-    int64 topk = 4;
+    repeated VectorParam vector_param = 3;
+    string dsl = 4;
     repeated KeyValuePair extra_params = 5;
 }
 
 /**
- * @brief Params for searching vector in files
+ * @brief Parameters for searching in segments
  */
-message SearchInFilesParam {
+message SearchInSegmentParam {
     repeated string file_id_array = 1;
     SearchParam search_param = 2;
 }
 
 /**
- * @brief Params for searching vector by ID
+ * @brief Entities
  */
-message SearchByIDParam {
-    string collection_name = 1;
-    repeated string partition_tag_array = 2;
-    repeated int64 id_array = 3;
-    int64 topk = 4;
-    repeated KeyValuePair extra_params = 5;
+message Entities {
+    Status status = 1;
+    repeated int64 ids = 2;
+    repeated bool valid_row = 3;
+    repeated FieldValue fields = 4;
 }
 
 /**
- * @brief Query result params
+ * @brief Query result
  */
-message TopKQueryResult {
+message QueryResult {
     Status status = 1;
-    int64 row_num = 2;
-    repeated int64 ids = 3;
-    repeated float distances = 4;
+    Entities entities = 2;
+    int64 row_num = 3;
+    repeated float scores = 4;
+    repeated float distances = 5;
+    repeated KeyValuePair extra_params = 6;
 }
 
 /**
@@ -152,7 +227,7 @@ message CollectionRowCount {
 }
 
 /**
- * @brief Give server Command
+ * @brief Server command parameters
  */
 message Command {
     string cmd = 1;
@@ -160,24 +235,44 @@ message Command {
 
 /**
  * @brief Index params
- * @index_type: 0-invalid, 1-idmap, 2-ivflat, 3-ivfsq8, 4-nsgmix
+ * @collection_name: target collection
+ * @field_name: target field
+ * @index_name: a name for index provided by user, unique within this field
+ * @extra_params: index parameters in json format
+ *    for vector field:
+ *        extra_params["index_type"] = one of the values: IDMAP, IVFLAT, IVFSQ8, NSGMIX, IVFSQ8H,
+ *                                                        PQ, HNSW, HNSW_SQ8NM, ANNOY
+ *        extra_params["metric_type"] = one of the values: L2, IP, HAMMING, JACCARD, TANIMOTO
+ *                                                         SUBSTRUCTURE, SUPERSTRUCTURE
+ *        extra_params["params"] = extra parameters for index, for example ivflat: {nlist: 2048}
+ *    for structured field:
+ *        extra_params["index_type"] = one of the values: SORTED
  */
 message IndexParam {
     Status status = 1;
     string collection_name = 2;
-    int32 index_type = 3;
-    repeated KeyValuePair extra_params = 4;
+    string field_name = 3;
+    string index_name = 4;
+    repeated KeyValuePair extra_params = 5;
 }
 
 /**
- * @brief Flush params
+ * @brief Parameters for flush action
  */
 message FlushParam {
     repeated string collection_name_array = 1;
 }
 
 /**
- * @brief Flush params
+ * @brief Parameters for flush action
+ */
+message CompactParam {
+    string collection_name = 1;
+    double threshold = 2;
+}
+
+/**
+ * @brief Parameters for deleting entities by id
  */
 message DeleteByIDParam {
     string collection_name = 1;
@@ -185,7 +280,36 @@ message DeleteByIDParam {
 }
 
 /**
- * @brief collection information
+ * @brief Return collection stats
+ * @json_info: collection stats in json format, typically, the format is like:
+ *     {
+ *        row_count: xxx,
+ *        data_size: xxx,
+ *        partitions: [
+ *          {
+ *            tag: xxx,
+ *            id: xxx,
+ *            row_count: xxx,
+ *            data_size: xxx,
+ *            segments: [
+ *              {
+ *                 id: xxx,
+ *                 row_count: xxx,
+ *                 data_size: xxx,
+ *                 files: [
+ *                    {
+ *                       field: xxx,
+ *                       name: xxx,
+ *                       index_type: xxx,
+ *                       path: xxx,
+ *                       data_size: xxx,
+ *                    }
+ *                 ]
+ *              }
+ *            ]
+ *          }
+ *        ]
+ *     }
  */
 message CollectionInfo {
     Status status = 1;
@@ -193,38 +317,135 @@ message CollectionInfo {
 }
 
 /**
- * @brief vectors identity
+ * @brief Parameters for returning entities id of a segment
  */
-message VectorsIdentity {
+message GetEntityIDsParam {
+    string collection_name = 1;
+    int64 segment_id = 2;
+}
+
+/**
+ * @brief Entities identity
+ */
+message EntityIdentity {
     string collection_name = 1;
     repeated int64 id_array = 2;
+    repeated string field_names = 3;
 }
 
+/********************************************SearchPB interface***************************************************/
 /**
- * @brief vector data
+ * @brief Vector field parameters
  */
-message VectorsData {
-    Status status = 1;
-    repeated RowRecord vectors_data = 2;
+message VectorFieldParam {
+    int64 dimension = 1;
+}
+
+/**
+ * @brief Field type
+ */
+message FieldType {
+    oneof value {
+        DataType data_type = 1;
+        VectorFieldParam vector_param = 2;
+    }
+}
+
+/**
+ * @brief Field parameters
+ */
+message FieldParam {
+    uint64 id = 1;
+    string name = 2;
+    DataType type = 3;
+    repeated KeyValuePair index_params = 4;
+    repeated KeyValuePair extra_params = 5;
 }
 
 /**
- * @brief get vector ids from a segment parameters
+ * @brief Vector field record
  */
-message GetVectorIDsParam {
+message VectorFieldRecord {
+    repeated VectorRowRecord value = 1;
+}
+
+///////////////////////////////////////////////////////////////////
+
+message TermQuery {
+    string field_name = 1;
+    repeated int64 int_value = 2;
+    repeated double double_value = 3;
+    int64 value_num = 4;
+    float boost = 5;
+    repeated KeyValuePair extra_params = 6;
+}
+
+enum CompareOperator {
+    LT = 0;
+    LTE = 1;
+    EQ = 2;
+    GT = 3;
+    GTE = 4;
+    NE = 5;
+}
+
+message CompareExpr {
+    CompareOperator operator = 1;
+    string operand = 2;
+}
+
+message RangeQuery {
+    string field_name = 1;
+    repeated CompareExpr operand = 2;
+    float boost = 3;
+    repeated KeyValuePair extra_params = 4;
+}
+
+message VectorQuery {
+    string field_name = 1;
+    float query_boost = 2;
+    repeated VectorRowRecord records = 3;
+    int64 topk = 4;
+    repeated KeyValuePair extra_params = 5;
+}
+
+enum Occur {
+    INVALID = 0;
+    MUST = 1;
+    SHOULD = 2;
+    MUST_NOT = 3;
+}
+
+message BooleanQuery {
+    Occur occur = 1;
+    repeated GeneralQuery general_query = 2;
+}
+
+message GeneralQuery {
+    oneof query {
+        BooleanQuery boolean_query = 1;
+        TermQuery term_query = 2;
+        RangeQuery range_query = 3;
+        VectorQuery vector_query = 4;
+    }
+}
+
+message SearchParamPB {
     string collection_name = 1;
-    string segment_name = 2;
+    repeated string partition_tag_array = 2;
+    GeneralQuery general_query = 3;
+    repeated KeyValuePair extra_params = 4;
 }
 
 service MilvusService {
     /**
      * @brief This method is used to create collection
      *
-     * @param CollectionSchema, use to provide collection information to be created.
+     * @param Mapping, use to provide collection information to be created.
      *
      * @return Status
      */
-    rpc CreateCollection(CollectionSchema) returns (Status){}
+    rpc CreateCollection(Mapping) returns (Status){}
 
     /**
      * @brief This method is used to test collection existence.
@@ -242,7 +463,7 @@ service MilvusService {
      *
      * @return CollectionSchema
      */
-    rpc DescribeCollection(CollectionName) returns (CollectionSchema) {}
+    rpc DescribeCollection(CollectionName) returns (Mapping) {}
 
     /**
      * @brief This method is used to get collection schema.
@@ -276,7 +497,7 @@ service MilvusService {
      *
      * @param CollectionName, collection name is going to be deleted.
      *
-     * @return CollectionNameList
+     * @return Status
      */
     rpc DropCollection(CollectionName) returns (Status) {}
 
@@ -292,20 +513,20 @@ service MilvusService {
     /**
      * @brief This method is used to describe index
      *
-     * @param CollectionName, target collection name.
+     * @param IndexParam, target index.
      *
      * @return IndexParam
      */
-    rpc DescribeIndex(CollectionName) returns (IndexParam) {}
+    rpc DescribeIndex(IndexParam) returns (IndexParam) {}
 
     /**
      * @brief This method is used to drop index
      *
-     * @param CollectionName, target collection name.
+     * @param IndexParam, target field. if the IndexParam.field_name is empty, will drop all index of the collection
      *
      * @return Status
      */
-    rpc DropIndex(CollectionName) returns (Status) {}
+    rpc DropIndex(IndexParam) returns (Status) {}
 
     /**
      * @brief This method is used to create partition
@@ -348,54 +569,45 @@ service MilvusService {
      *
      * @param InsertParam, insert parameters.
      *
-     * @return VectorIds
+     * @return EntityIds
      */
-    rpc Insert(InsertParam) returns (VectorIds) {}
+    rpc Insert(InsertParam) returns (EntityIds) {}
 
     /**
-     * @brief This method is used to get vectors data by id array.
+     * @brief This method is used to get entities data by id array.
      *
-     * @param VectorsIdentity, target vector id array.
+     * @param EntitiesIdentity, target entity id array.
      *
-     * @return VectorsData
+     * @return Entities
      */
-    rpc GetVectorsByID(VectorsIdentity) returns (VectorsData) {}
+    rpc GetEntityByID(EntityIdentity) returns (Entities) {}
 
     /**
-     * @brief This method is used to get vector ids from a segment
+     * @brief This method is used to get entity ids from a segment
      *
-     * @param GetVectorIDsParam, target collection and segment
+     * @param GetEntityIDsParam, target collection and segment
      *
-     * @return VectorIds
+     * @return EntityIds
      */
-    rpc GetVectorIDs(GetVectorIDsParam) returns (VectorIds) {}
+    rpc GetEntityIDs(GetEntityIDsParam) returns (EntityIds) {}
 
     /**
      * @brief This method is used to query vector in collection.
      *
      * @param SearchParam, search parameters.
      *
-     * @return TopKQueryResult
-     */
-    rpc Search(SearchParam) returns (TopKQueryResult) {}
-
-    /**
-     * @brief This method is used to query vector by id.
-     *
-     * @param SearchByIDParam, search parameters.
-     *
-     * @return TopKQueryResult
+     * @return QueryResult
      */
-    rpc SearchByID(SearchByIDParam) returns (TopKQueryResult) {}
+    rpc Search(SearchParam) returns (QueryResult) {}
 
     /**
-     * @brief This method is used to query vector in specified files.
+     * @brief This method is used to query vector in specified segment.
      *
-     * @param SearchInFilesParam, search in files paremeters.
+     * @param SearchInSegmentParam, target segments to search.
      *
-     * @return TopKQueryResult
+     * @return QueryResult
      */
-    rpc SearchInFiles(SearchInFilesParam) returns (TopKQueryResult) {}
+    rpc SearchInSegment(SearchInSegmentParam) returns (QueryResult) {}
 
     /**
      * @brief This method is used to give the server status.
@@ -436,9 +648,13 @@ service MilvusService {
     /**
      * @brief This method is used to compact collection
      *
-     * @param CollectionName, target collection name.
+     * @param CompactParam, compact parameters
      *
      * @return Status
      */
-    rpc Compact(CollectionName) returns (Status) {}
+    rpc Compact(CompactParam) returns (Status) {}
+
+    /********************************New Interface********************************************/
+
+    rpc SearchPB(SearchParamPB) returns (QueryResult) {}
 }

+ 0 - 3
src/main/resources/milvus-client.properties

@@ -1,3 +0,0 @@
-groupId=${project.groupId}
-artifactId=${project.artifactId}
-version=${project.version}

File diff suppressed because it is too large
+ 473 - 217
src/test/java/io/milvus/client/MilvusGrpcClientTest.java


+ 0 - 68
src/test/java/io/milvus/client/StaticNameResolverProvider.java

@@ -1,68 +0,0 @@
-package io.milvus.client;
-
-import io.grpc.Attributes;
-import io.grpc.EquivalentAddressGroup;
-import io.grpc.NameResolver;
-import io.grpc.NameResolverProvider;
-
-import java.net.SocketAddress;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class StaticNameResolverProvider extends NameResolverProvider {
-  private String name;
-  private List<SocketAddress> addresses;
-
-  public StaticNameResolverProvider(String name, SocketAddress... addresses) {
-    this.name = name;
-    this.addresses = Arrays.asList(addresses);
-  }
-
-  @Override
-  public String getDefaultScheme() {
-    return "static";
-  }
-
-  @Override
-  protected boolean isAvailable() {
-    return true;
-  }
-
-  @Override
-  protected int priority() {
-    return 0;
-  }
-
-  @Override
-  public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
-    if (!getDefaultScheme().equals(targetUri.getScheme())) {
-      return null;
-    }
-    return new NameResolver() {
-      @Override
-      public String getServiceAuthority() {
-        return "localhost";
-      }
-
-      @Override
-      public void start(Listener2 listener) {
-        List<EquivalentAddressGroup> addrs = addresses.stream()
-            .map(addr -> new EquivalentAddressGroup(Collections.singletonList(addr)))
-            .collect(Collectors.toList());
-
-        listener.onResult(
-            ResolutionResult.newBuilder()
-                .setAddresses(addrs)
-                .setAttributes(Attributes.EMPTY)
-                .build());
-      }
-
-      @Override
-      public void shutdown() {
-      }
-    };
-  }
-}

Some files were not shown because too many files changed in this diff