Bläddra i källkod

Release 0.2.1

Zhiru Zhu 5 år sedan
förälder
incheckning
c457604a97

+ 9 - 0
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| Recommended SDK version|
+|:-----:|:-----:|
+| 0.5.0 | 0.2.1 | 
+| 0.5.1 | 0.2.1 | 
+
 ### Dependency 
 
 Apache Maven

+ 2 - 16
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.1</version>
     <build>
         <plugins>
             <plugin>
@@ -44,25 +44,11 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
-    <!-- For deploying SNAPSHOT -->
-    <repositories>
-        <repository>
-            <id>oss.sonatype.org-snapshot</id>
-            <url>http://oss.sonatype.org/content/repositories/snapshots</url>
-            <releases>
-                <enabled>false</enabled>
-            </releases>
-            <snapshots>
-                <enabled>true</enabled>
-            </snapshots>
-        </repository>
-    </repositories>
-
     <dependencies>
         <dependency>
             <groupId>io.milvus</groupId>
             <artifactId>milvus-sdk-java</artifactId>
-            <version>0.2.1-SNAPSHOT</version>
+            <version>0.2.1</version>
         </dependency>
     </dependencies>
 

+ 2 - 6
examples/src/main/java/MilvusClientExample.java

@@ -61,9 +61,7 @@ public class MilvusClientExample {
     MilvusClient client = new MilvusGrpcClient();
 
     // Connect to Milvus server
-    final long waitTime = 1000; // Wait 1000 ms for client to establish a connection
-    ConnectParam connectParam =
-        new ConnectParam.Builder().withHost(host).withPort(port).withWaitTime(waitTime).build();
+    ConnectParam connectParam = new ConnectParam.Builder().withHost(host).withPort(port).build();
     try {
       Response connectResponse = client.connect(connectParam);
     } catch (ConnectFailedException e) {
@@ -120,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);
@@ -170,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.1-SNAPSHOT</version>
+    <version>0.2.1</version>
     <packaging>jar</packaging>
 
     <name>io.milvus:milvus-sdk-java</name>

+ 9 - 10
src/main/java/io/milvus/client/ConnectParam.java

@@ -25,12 +25,12 @@ import javax.annotation.Nonnull;
 public class ConnectParam {
   private final String host;
   private final String port;
-  private final long waitTime;
+  private final long timeout;
 
   private ConnectParam(@Nonnull Builder builder) {
     this.host = builder.host;
     this.port = builder.port;
-    this.waitTime = builder.waitTime;
+    this.timeout = builder.timeout;
   }
 
   public String getHost() {
@@ -41,8 +41,8 @@ public class ConnectParam {
     return port;
   }
 
-  public long getWaitTime() {
-    return waitTime;
+  public long getTimeout() {
+    return timeout;
   }
 
   @Override
@@ -55,7 +55,7 @@ public class ConnectParam {
     // Optional parameters - initialized to default values
     private String host = "127.0.0.1";
     private String port = "19530";
-    private long waitTime = 500; // ms
+    private long timeout = 10000; // ms
 
     /**
      * Optional. Default to "127.0.0.1".
@@ -80,14 +80,13 @@ public class ConnectParam {
     }
 
     /**
-     * Optional. Default to 500 ms
+     * Optional. Default to 10000 ms
      *
-     * @param waitTime Wait time (in ms) for channel to establish a connection. BEWARE: this is not
-     *     timeout, so the program will essentially sleep for the entire duration
+     * @param timeout Timeout in ms for client to establish a connection to server
      * @return <code>Builder</code>
      */
-    public Builder withWaitTime(long waitTime) {
-      this.waitTime = waitTime;
+    public Builder withTimeout(long timeout) {
+      this.timeout = timeout;
       return this;
     }
 

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

@@ -40,9 +40,13 @@ 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.
+ *
+ * 6. IVF_PQ - Indexing method built based on product quantization. The input vectors are split into distinct
+ * sub-vectors which are then quantized separately. Vector size can be reduced to 1/8 or 1/16 of the original size.
+ * If you choose this index, note that there is an inevitable trade-off between memory and search accuracy.
  * </pre>
  */
 public enum IndexType {
@@ -51,7 +55,8 @@ public enum IndexType {
   IVFLAT(2),
   IVF_SQ8(3),
   NSG(4),
-  IVF_SQ8H(5),
+  IVF_SQ8_H(5),
+  IVF_PQ(6),
 
   UNKNOWN(-1);
 

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

@@ -39,7 +39,7 @@ public interface MilvusClient {
    * ConnectParam connectParam = new ConnectParam.Builder()
    *                                             .withHost("localhost")
    *                                             .withPort("19530")
-   *                                             .withWaitTime(500)
+   *                                             .withTimeout(10000)
    *                                             .build();
    * </code>
    * </pre>

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

@@ -70,16 +70,17 @@ public class MilvusGrpcClient implements MilvusClient {
       ConnectivityState connectivityState;
       connectivityState = channel.getState(true);
 
-      logInfo(
-          "Waiting for {0} ms for channel to establish connection...", connectParam.getWaitTime());
-      TimeUnit.MILLISECONDS.sleep(connectParam.getWaitTime());
-
-      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);