Browse Source

Merge pull request #39 from milvus-io/branch-0.1.0

Branch 0.1.0
Jin Hai 5 years ago
parent
commit
aae503ebfa

+ 0 - 30
.github/ISSUE_TEMPLATE/bug-report.md

@@ -1,30 +0,0 @@
----
-name: "\U0001F41B Bug report"
-about: Create a report to help us improve milvus-sdk-java
-title: "[BUG]"
-labels: ''
-assignees: ''
-
----
-
-**Describe the bug**
-A clear and concise description of what the bug is.
-
-**Steps/Code to reproduce behavior**
-Follow this [guide](http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) to craft a minimal bug report. This helps us reproduce the issue you're having and resolve the issue more quickly.
-
-**Expected behavior**
-A clear and concise description of what you expected to happen.
-
-**Environment details**
-
-- Hardware/Softward conditions (OS, CPU, GPU, Memory)
-- Method of installation (Docker, or from source)
-- Milvus version (v0.3.1, or v0.4.0)
-- Milvus configuration (Settings you made in `server_config.yaml`)
-
-**Screenshots**
-If applicable, add screenshots to help explain your problem.
-
-**Additional context**
-Add any other context about the problem here.

+ 0 - 19
.github/ISSUE_TEMPLATE/feature-request.md

@@ -1,19 +0,0 @@
----
-name: "\U0001F680 Feature request"
-about: Suggest an idea for milvus-sdk-java
-title: "[FEATURE]"
-labels: ''
-assignees: ''
-
----
-
-**Is your feature request related to a problem? Please describe.**
-A clear and concise description of what the problem is. E.g. I wish I could use Milvus to do [...]
-**Describe the solution you'd like**
-A clear and concise description of what you want to happen.
-
-**Describe alternatives you've considered**
-A clear and concise description of any alternative solutions or features you've considered.
-
-**Additional context**
-Add any other context, code examples, or references to existing implementations about the feature request here.

+ 0 - 10
.github/ISSUE_TEMPLATE/general-question.md

@@ -1,10 +0,0 @@
----
-name: "\U0001F914 General question"
-about: Ask a general question about milvus-sdk-java
-title: "[QUESTION]"
-labels: ''
-assignees: ''
-
----
-
-**What is your question?**

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@
 - \#27: change proto package to io.milvus.grpc
 - \#27: change proto package to io.milvus.grpc
 - \#32: fix README format
 - \#32: fix README format
 - \#35: Fix client version in readme and src code
 - \#35: Fix client version in readme and src code
+- \#38: Update examples
     
     
 ### New Feature
 ### New Feature
 ---
 ---

+ 25 - 15
examples/src/main/java/MilvusClientExample.java

@@ -19,12 +19,26 @@ import io.milvus.client.*;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
-import java.util.Random;
+import java.util.SplittableRandom;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
+import java.util.stream.DoubleStream;
 
 
 public class MilvusClientExample {
 public class MilvusClientExample {
 
 
+  // Helper function that generates random vectors
+  static List<List<Float>> generateRandomVectors(long vectorCount, long dimension) {
+    SplittableRandom splittableRandom = new SplittableRandom();
+    List<List<Float>> vectors = new ArrayList<>();
+    for (int i = 0; i < vectorCount; ++i) {
+      DoubleStream doubleStream = splittableRandom.doubles(dimension);
+      List<Float> vector =
+          doubleStream.boxed().map(Double::floatValue).collect(Collectors.toList());
+      vectors.add(vector);
+    }
+    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
   // type
   static List<Float> normalize(List<Float> vector) {
   static List<Float> normalize(List<Float> vector) {
@@ -77,17 +91,9 @@ public class MilvusClientExample {
     System.out.println(describeTableResponse);
     System.out.println(describeTableResponse);
 
 
     // Insert randomly generated vectors to table
     // Insert randomly generated vectors to table
-    final int vectorCount = 1024;
-    Random random = new Random();
-    List<List<Float>> vectors = new ArrayList<>();
-    for (int i = 0; i < vectorCount; ++i) {
-      List<Float> vector = new ArrayList<>();
-      for (int j = 0; j < dimension; ++j) {
-        vector.add(random.nextFloat());
-      }
-      vector = normalize(vector);
-      vectors.add(vector);
-    }
+    final int vectorCount = 100000;
+    List<List<Float>> vectors = generateRandomVectors(vectorCount, dimension);
+    vectors.forEach(MilvusClientExample::normalize);
     InsertParam insertParam = new InsertParam.Builder(tableName, vectors).withTimeout(10).build();
     InsertParam insertParam = new InsertParam.Builder(tableName, vectors).withTimeout(10).build();
     InsertResponse insertResponse = client.insert(insertParam);
     InsertResponse insertResponse = client.insert(insertParam);
     System.out.println(insertResponse);
     System.out.println(insertResponse);
@@ -130,9 +136,13 @@ public class MilvusClientExample {
     final double epsilon = 0.001;
     final double epsilon = 0.001;
     for (int i = 0; i < searchSize; i++) {
     for (int i = 0; i < searchSize; i++) {
       // Since we are searching for vector that is already present in the table,
       // Since we are searching for vector that is already present in the table,
-      // the first result vector should be itself and the distance should be less than epsilon
-      assert queryResultsList.get(i).get(0).getVectorId() == vectorIds.get(0);
-      assert queryResultsList.get(i).get(0).getDistance() < epsilon;
+      // 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)
+          || firstQueryResult.getDistance() <= (1 - epsilon)) {
+        throw new AssertionError();
+      }
     }
     }
 
 
     // Drop index for the table
     // Drop index for the table