Просмотр исходного кода

Fix setting data type for array of template expression (#1146) (#1151)

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
Co-authored-by: cai.zhang <cai.zhang@zilliz.com>
groot 6 месяцев назад
Родитель
Сommit
7714cda7e3

+ 29 - 1
examples/main/java/io/milvus/v2/SimpleExample.java

@@ -103,7 +103,35 @@ public class SimpleExample {
                 System.out.printf("ID: %d, Score: %f, %s\n", (long)result.getId(), result.getScore(), result.getEntity().toString());
             }
         }
-
+        // search with template expression
+        // Map<String, Map<String, Object>> expressionTemplateValues = new HashMap<>();
+        // Map<String, Object> params = new HashMap<>();
+        // params.put("max", 10);
+        // expressionTemplateValues.put("id < {max}", params);
+        //
+        // List<Object> list = Arrays.asList(1, 2, 3);
+        // Map<String, Object> params2 = new HashMap<>();
+        // params2.put("list", list);
+        // expressionTemplateValues.put("id in {list}", params2);
+        //
+        // expressionTemplateValues.forEach((key, value) -> {
+        //     SearchReq request = SearchReq.builder()
+        //             .collectionName(collectionName)
+        //             .data(Collections.singletonList(new FloatVec(new float[]{1.0f, 1.0f, 1.0f, 1.0f})))
+        //             .topK(10)
+        //             .filter(key)
+        //             .filterTemplateValues(value)
+        //             .outputFields(Collections.singletonList("*"))
+        //             .build();
+        //  SearchResp statusR = client.search(request);
+        //  List<List<SearchResp.SearchResult>> searchResults2 = statusR.getSearchResults();
+        //  System.out.println("\nSearch results:");
+        //  for (List<SearchResp.SearchResult> results : searchResults2) {
+        //      for (SearchResp.SearchResult result : results) {
+        //          System.out.printf("ID: %d, Score: %f, %s\n", (long)result.getId(), result.getScore(), result.getEntity().toString());
+        //      }
+        //  }
+        // });
         client.close();
     }
 }

+ 1 - 1
src/main/java/io/milvus/v2/utils/VectorUtils.java

@@ -248,8 +248,8 @@ public class VectorUtils {
             builder.setSameType(sameType);
 
             return TemplateValue.newBuilder()
+                    .setType(DataType.Array)
                     .setArrayVal(builder.build())
-                    .setType(builder.getElementType())
                     .build();
         } else {
             throw new ParamException("Unsupported value type for expression template.");