Browse Source

add consistency_level on search page (#366)

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 year ago
parent
commit
d375886043

+ 19 - 0
client/src/consts/Milvus.ts

@@ -297,6 +297,25 @@ export enum ConsistencyLevelEnum {
   Customized = 'Customized', // Users pass their own `guarantee_timestamp`.
   Customized = 'Customized', // Users pass their own `guarantee_timestamp`.
 }
 }
 
 
+export const CONSISTENCY_LEVEL_OPTIONS = [
+  {
+    value: ConsistencyLevelEnum.Bounded,
+    label: ConsistencyLevelEnum.Bounded,
+  },
+  {
+    value: ConsistencyLevelEnum.Strong,
+    label: ConsistencyLevelEnum.Strong,
+  },
+  {
+    value: ConsistencyLevelEnum.Session,
+    label: ConsistencyLevelEnum.Session,
+  },
+  {
+    value: ConsistencyLevelEnum.Eventually,
+    label: ConsistencyLevelEnum.Eventually,
+  },
+];
+
 export enum DataTypeStringEnum {
 export enum DataTypeStringEnum {
   Bool = 'Bool',
   Bool = 'Bool',
   Int8 = 'Int8',
   Int8 = 'Int8',

+ 16 - 0
client/src/pages/search/SearchParams.tsx

@@ -11,6 +11,7 @@ import {
   INDEX_CONFIG,
   INDEX_CONFIG,
   METRIC_OPTIONS_MAP,
   METRIC_OPTIONS_MAP,
   searchKeywordsType,
   searchKeywordsType,
+  CONSISTENCY_LEVEL_OPTIONS,
 } from '@/consts';
 } from '@/consts';
 import { rootContext } from '@/context';
 import { rootContext } from '@/context';
 import { useFormValidation } from '@/hooks';
 import { useFormValidation } from '@/hooks';
@@ -40,13 +41,16 @@ const SearchParams: FC<SearchParamsProps> = ({
   searchParamsForm,
   searchParamsForm,
   handleFormChange,
   handleFormChange,
   handleMetricTypeChange,
   handleMetricTypeChange,
+  handleConsistencyChange,
   embeddingType,
   embeddingType,
   metricType,
   metricType,
+  consistency_level,
   topK,
   topK,
   setParamsDisabled,
   setParamsDisabled,
   wrapperClass = '',
   wrapperClass = '',
 }) => {
 }) => {
   const { t: indexTrans } = useTranslation('index');
   const { t: indexTrans } = useTranslation('index');
+  const { t: collectionTrans } = useTranslation('collection');
   const { t: warningTrans } = useTranslation('warning');
   const { t: warningTrans } = useTranslation('warning');
   const classes = getStyles();
   const classes = getStyles();
 
 
@@ -331,6 +335,18 @@ const SearchParams: FC<SearchParamsProps> = ({
           handleMetricTypeChange(metricType);
           handleMetricTypeChange(metricType);
         }}
         }}
       />
       />
+      {/* consistency level */}
+      <CustomSelector
+        options={CONSISTENCY_LEVEL_OPTIONS}
+        value={consistency_level}
+        label={collectionTrans('consistencyLevel')}
+        wrapperClass={classes.selector}
+        variant="filled"
+        onChange={(e: { target: { value: unknown } }) => {
+          const consistency = e.target.value as string;
+          handleConsistencyChange(consistency);
+        }}
+      />
       <div className={classes.inlineInputWrapper}>
       <div className={classes.inlineInputWrapper}>
         {/* dynamic params, now every type only has one param except metric type */}
         {/* dynamic params, now every type only has one param except metric type */}
         {searchParams.map(param => (
         {searchParams.map(param => (

+ 2 - 0
client/src/pages/search/Types.ts

@@ -19,8 +19,10 @@ export interface SearchParamsProps {
   topK: number;
   topK: number;
   handleFormChange: (form: { [key in string]: number }) => void;
   handleFormChange: (form: { [key in string]: number }) => void;
   handleMetricTypeChange: (type: string) => void;
   handleMetricTypeChange: (type: string) => void;
+  handleConsistencyChange: (type: string) => void;
   wrapperClass?: string;
   wrapperClass?: string;
   setParamsDisabled: (isDisabled: boolean) => void;
   setParamsDisabled: (isDisabled: boolean) => void;
+  consistency_level: string;
 }
 }
 
 
 export interface SearchResultView {
 export interface SearchResultView {

+ 13 - 3
client/src/pages/search/VectorSearch.tsx

@@ -162,6 +162,8 @@ const VectorSearch = () => {
   }, [searchResult, primaryKeyField, orderArray]);
   }, [searchResult, primaryKeyField, orderArray]);
 
 
   const [selectedMetricType, setSelectedMetricType] = useState<string>('');
   const [selectedMetricType, setSelectedMetricType] = useState<string>('');
+  const [selectedConsistencyLevel, setSelectedConsistencyLevel] =
+    useState<string>('');
 
 
   const {
   const {
     indexType,
     indexType,
@@ -293,6 +295,9 @@ const VectorSearch = () => {
     if (selectedCollection !== '') {
     if (selectedCollection !== '') {
       fetchFieldsWithIndex(selectedCollection, collections);
       fetchFieldsWithIndex(selectedCollection, collections);
     }
     }
+    const level = collections.find(c => c.collectionName == selectedCollection)
+      ?.consistency_level!;
+    setSelectedConsistencyLevel(level);
   }, [selectedCollection, collections, fetchFieldsWithIndex]);
   }, [selectedCollection, collections, fetchFieldsWithIndex]);
 
 
   // set default collection value if is from overview page
   // set default collection value if is from overview page
@@ -351,9 +356,10 @@ const VectorSearch = () => {
       search_params: searchParamPairs,
       search_params: searchParamPairs,
       vectors: [parseValue(vectors)],
       vectors: [parseValue(vectors)],
       vector_type: fieldType,
       vector_type: fieldType,
-      consistency_level: collections.find(
-        c => c.collectionName == selectedCollection
-      )?.consistency_level!,
+      consistency_level:
+        selectedConsistencyLevel ||
+        collections.find(c => c.collectionName == selectedCollection)
+          ?.consistency_level!,
     };
     };
 
 
     setTableLoading(true);
     setTableLoading(true);
@@ -472,6 +478,10 @@ const VectorSearch = () => {
                 | DataTypeEnum.BinaryVector
                 | DataTypeEnum.BinaryVector
                 | DataTypeEnum.FloatVector
                 | DataTypeEnum.FloatVector
             }
             }
+            consistency_level={selectedConsistencyLevel}
+            handleConsistencyChange={(level: string) => {
+              setSelectedConsistencyLevel(level);
+            }}
             indexType={indexType}
             indexType={indexType}
             indexParams={indexParams!}
             indexParams={indexParams!}
             searchParamsForm={searchParam}
             searchParamsForm={searchParam}