Browse Source

Fix binary preview (#137)

* fix binary preview

* fix preview

* remove console
ryjiang 2 years ago
parent
commit
6b60189aa3

+ 3 - 2
client/src/pages/preview/Preview.tsx

@@ -90,10 +90,11 @@ const Preview: FC<{
     const vectorField = schemaList.find(
       v => v.data_type === 'FloatVector' || v.data_type === 'BinaryVector'
     );
-
     const anns_field = vectorField?._fieldName!;
     const dim = Number(vectorField?._dimension);
-    const vectors = [generateVector(dim)];
+    const vectors = [
+      generateVector(vectorField?.data_type === 'FloatVector' ? dim : dim / 8),
+    ];
     // get search params
     const indexesInfo = await IndexHttp.getIndexInfo(collectionName);
     const indexType =

+ 4 - 1
client/src/pages/search/VectorSearch.tsx

@@ -33,6 +33,7 @@ import Filter from '../../components/advancedSearch';
 import { Field } from '../../components/advancedSearch/Types';
 import { useLocation } from 'react-router-dom';
 import { parseLocationSearch } from '../../utils/Format';
+import { cloneObj } from '../../utils/Common';
 import { CustomDatePicker } from '../../components/customDatePicker/CustomDatePicker';
 import { useTimeTravelHook } from '../../hooks/TimeTravel';
 
@@ -296,8 +297,10 @@ const VectorSearch = () => {
   };
 
   const handleSearch = async (topK: number, expr = expression) => {
+    const clonedSearchParams = cloneObj(searchParam);
+    delete clonedSearchParams.round_decimal;
     const searhParamPairs = {
-      params: JSON.stringify(searchParam),
+      params: JSON.stringify(clonedSearchParams),
       anns_field: selectedField,
       topk: topK,
       metric_type: selectedMetricType,

+ 5 - 1
client/src/utils/Common.ts

@@ -63,5 +63,9 @@ export const generateIdByHash = (salt?: string) => {
 };
 
 export const generateVector = (dim: number) => {
-  return Array.from({ length: dim }).map(() => Math.random());
+  return Array.from({ length: dim }).map(() => (Math.random() > 0.5 ? 1 : 0));
+};
+
+export const cloneObj = (obj: any) => {
+  return JSON.parse(JSON.stringify(obj));
 };

+ 1 - 1
server/src/utils/Helper.ts

@@ -22,7 +22,7 @@ export const genDataByType = ({ data_type, type_params }: FieldSchema) => {
       );
     case 'BinaryVector':
       return Array.from({ length: (type_params as any)[0].value / 8 }).map(() =>
-        Math.random()
+        Math.random() > 0.5 ? 1 : 0
       );
     case 'VarChar':
       return makeRandomId((type_params as any)[0].value);