2
0
Эх сурвалжийг харах

Merge pull request #55 from milvus-io/0.5.1

0.5.1
Jin Hai 5 жил өмнө
parent
commit
979477bdb0

+ 17 - 0
CHANGELOG.md

@@ -1,5 +1,22 @@
 # Changelog     
 
+## milvus-sdk-java 0.2.2 (2018-11-4)
+
+### Bug
+---
+
+### Improvement
+---
+- \#49 - Add waitTime option in ConnectParam
+- \#51 - Change connect waitTime to timeout
+- \#52 - Change IVF_SQ8H to IVF_SQ8_H
+
+### Feature
+---
+
+### Task
+---
+
 ## milvus-sdk-java 0.2.0 (2019-10-21)
 
 ### Bug

+ 11 - 2
README.md

@@ -7,6 +7,15 @@ If you want to contribute to this repo, please read our [contribution guidelines
 
 ## Getting started
 
+You will need Java 8 or higher.
+
+Milvus version compatibility:
+
+|Milvus version| SDK version|
+|:-----:|:-----:|
+| 0.5.0 | 0.2.2 | 
+| 0.5.1 | 0.2.2 | 
+
 ### Dependency 
 
 Apache Maven
@@ -14,13 +23,13 @@ Apache Maven
 <dependency>
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java</artifactId>
-    <version>0.2.0</version>
+    <version>0.2.2</version>
 </dependency>
 ```
 
 Gradle/Grails 
 
-`compile 'io.milvus:milvus-sdk-java:0.2.0'`
+`compile 'io.milvus:milvus-sdk-java:0.2.2'`
 
 ### Examples
 

+ 0 - 2
examples/examples.iml

@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4" />

+ 2 - 2
examples/pom.xml

@@ -25,7 +25,7 @@
 
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java-examples</artifactId>
-    <version>0.1.1</version>
+    <version>0.2.2</version>
     <build>
         <plugins>
             <plugin>
@@ -48,7 +48,7 @@
         <dependency>
             <groupId>io.milvus</groupId>
             <artifactId>milvus-sdk-java</artifactId>
-            <version>0.2.0</version>
+            <version>0.2.2</version>
         </dependency>
     </dependencies>
 

+ 3 - 5
examples/src/main/java/MilvusClientExample.java

@@ -42,7 +42,7 @@ public class MilvusClientExample {
     return vectors;
   }
 
-  // Helper function that normalizes a vector if you are using IP (Inner product) as your metric
+  // Helper function that normalizes a vector if you are using IP (Inner Product) as your metric
   // type
   static List<Float> normalizeVector(List<Float> vector) {
     float squareSum = vector.stream().map(x -> x * x).reduce((float) 0, Float::sum);
@@ -77,7 +77,7 @@ public class MilvusClientExample {
     final String tableName = "example"; // table name
     final long dimension = 128; // dimension of each vector
     final long indexFileSize = 1024; // maximum size (in MB) of each index file
-    final MetricType metricType = MetricType.IP; // we choose IP (Inner project) as our metric type
+    final MetricType metricType = MetricType.IP; // we choose IP (Inner Product) as our metric type
     TableSchema tableSchema =
         new TableSchema.Builder(tableName, dimension)
             .withIndexFileSize(indexFileSize)
@@ -118,7 +118,7 @@ public class MilvusClientExample {
     // 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;
-    Index index = new Index.Builder().withIndexType(IndexType.IVF_SQ8).build();
+    Index index = new Index.Builder().withIndexType(indexType).build();
     CreateIndexParam createIndexParam =
         new CreateIndexParam.Builder(tableName).withIndex(index).build();
     Response createIndexResponse = client.createIndex(createIndexParam);
@@ -168,7 +168,5 @@ public class MilvusClientExample {
       System.out.println("Failed to disconnect: " + e.toString());
       throw e;
     }
-
-    return;
   }
 }

+ 1 - 1
pom.xml

@@ -25,7 +25,7 @@
 
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java</artifactId>
-    <version>0.2.0</version>
+    <version>0.2.2</version>
     <packaging>jar</packaging>
 
     <name>io.milvus:milvus-sdk-java</name>

+ 18 - 0
src/main/java/io/milvus/client/ConnectParam.java

@@ -25,10 +25,12 @@ import javax.annotation.Nonnull;
 public class ConnectParam {
   private final String host;
   private final String port;
+  private final long timeout;
 
   private ConnectParam(@Nonnull Builder builder) {
     this.host = builder.host;
     this.port = builder.port;
+    this.timeout = builder.timeout;
   }
 
   public String getHost() {
@@ -39,6 +41,10 @@ public class ConnectParam {
     return port;
   }
 
+  public long getTimeout() {
+    return timeout;
+  }
+
   @Override
   public String toString() {
     return "ConnectParam{" + "host='" + host + '\'' + ", port='" + port + '\'' + '}';
@@ -49,6 +55,7 @@ public class ConnectParam {
     // Optional parameters - initialized to default values
     private String host = "127.0.0.1";
     private String port = "19530";
+    private long timeout = 10000; // ms
 
     /**
      * Optional. Default to "127.0.0.1".
@@ -72,6 +79,17 @@ public class ConnectParam {
       return this;
     }
 
+    /**
+     * Optional. Default to 10000 ms
+     *
+     * @param timeout Timeout in ms for client to establish a connection to server
+     * @return <code>Builder</code>
+     */
+    public Builder withTimeout(long timeout) {
+      this.timeout = timeout;
+      return this;
+    }
+
     public ConnectParam build() {
       return new ConnectParam(this);
     }

+ 3 - 2
src/main/java/io/milvus/client/IndexType.java

@@ -40,9 +40,10 @@ import java.util.Optional;
  * search performance at high precision, and needs much less memory. Compared to non-graph-based
  * algorithms, it is faster to achieve the same search precision.
  *
- * 5. IVF_SQ8H - An enhanced index algorithm of IVF_SQ8. It supports hybrid computation on both CPU and GPU,
+ * 5. IVF_SQ8_H - An enhanced index algorithm of IVF_SQ8. It supports hybrid computation on both CPU and GPU,
  * which significantly improves the search performance. To use this index type, make sure both cpu and gpu are added as
  * resources for search usage in the Milvus configuration file.
+ *
  * </pre>
  */
 public enum IndexType {
@@ -51,7 +52,7 @@ public enum IndexType {
   IVFLAT(2),
   IVF_SQ8(3),
   NSG(4),
-  IVF_SQ8H(5),
+  IVF_SQ8_H(5),
 
   UNKNOWN(-1);
 

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

@@ -22,7 +22,7 @@ package io.milvus.client;
 /** The Milvus Client Interface */
 public interface MilvusClient {
 
-  String clientVersion = "0.2.0";
+  String clientVersion = "0.2.2";
 
   /** @return the current Milvus client version */
   default String getClientVersion() {
@@ -39,6 +39,7 @@ public interface MilvusClient {
    * ConnectParam connectParam = new ConnectParam.Builder()
    *                                             .withHost("localhost")
    *                                             .withPort("19530")
+   *                                             .withTimeout(10000)
    *                                             .build();
    * </code>
    * </pre>

+ 11 - 9
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -70,15 +70,17 @@ public class MilvusGrpcClient implements MilvusClient {
       ConnectivityState connectivityState;
       connectivityState = channel.getState(true);
 
-      logInfo("Waiting to connect...");
-      TimeUnit.MILLISECONDS.sleep(500);
-
-      connectivityState = channel.getState(false);
-      if (connectivityState != ConnectivityState.READY) {
-        logSevere(
-            "Connect failed! {0}\nConnectivity state = {1}",
-            connectParam.toString(), connectivityState);
-        throw new ConnectFailedException("Connectivity state = " + connectivityState);
+      long timeout = connectParam.getTimeout();
+      logInfo("Trying to connect...Timeout in {0} ms", timeout);
+
+      final long checkFrequency = 100; // ms
+      while (channel.getState(false) != ConnectivityState.READY) {
+        if (timeout <= 0) {
+          logSevere("Connect timeout! {0}", connectParam.toString());
+          throw new ConnectFailedException("Connect timeout");
+        }
+        TimeUnit.MILLISECONDS.sleep(checkFrequency);
+        timeout -= checkFrequency;
       }
 
       blockingStub = io.milvus.grpc.MilvusServiceGrpc.newBlockingStub(channel);

+ 1 - 1
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -52,7 +52,7 @@ class MilvusClientTest {
     return vectors;
   }
 
-  // Helper function that normalizes a vector if you are using IP (Inner product) as your metric
+  // Helper function that normalizes a vector if you are using IP (Inner Product) as your metric
   // type
   static List<Float> normalizeVector(List<Float> vector) {
     float squareSum = vector.stream().map(x -> x * x).reduce((float) 0, Float::sum);