Browse Source

hide create index action if there are multiple vectors in the collection (#486)

ryjiang 1 year ago
parent
commit
df429047d1

+ 1 - 1
client/src/consts/Milvus.ts

@@ -25,7 +25,7 @@ export enum DataTypeEnum {
   Array = 22,
   Array = 22,
 }
 }
 
 
-export const vectorTypes = [
+export const VectorTypes = [
   DataTypeEnum.BinaryVector,
   DataTypeEnum.BinaryVector,
   DataTypeEnum.FloatVector,
   DataTypeEnum.FloatVector,
   DataTypeEnum.BFloat16Vector,
   DataTypeEnum.BFloat16Vector,

+ 2 - 2
client/src/i18n/cn/collection.ts

@@ -127,8 +127,8 @@ const collectionTrans = {
     '它确保在同一会话中所有数据写入可以立即在读取中感知。',
     '它确保在同一会话中所有数据写入可以立即在读取中感知。',
   consistencyEventuallyTooltip:
   consistencyEventuallyTooltip:
     '没有保证读写的顺序,副本最终会在没有进一步写操作的情况下收敛到相同的状态。',
     '没有保证读写的顺序,副本最终会在没有进一步写操作的情况下收敛到相同的状态。',
-  releaseCollectionFirst: '请先释放collection.',
-  noVectorIndexTooltip: '没有向量索引,请先创建一个。',
+  releaseCollectionFirst: '请先释放collection',
+  noVectorIndexTooltip: '请保证所有向量列都有索引。',
 
 
   clickToLoad: '点击加载collection。',
   clickToLoad: '点击加载collection。',
   clickToRelease: '点击释放collection。',
   clickToRelease: '点击释放collection。',

+ 1 - 1
client/src/i18n/en/collection.ts

@@ -126,7 +126,7 @@ const collectionTrans = {
   consistencySessionTooltip: `It ensures that all data writes can be immediately perceived in reads during the same session.`,
   consistencySessionTooltip: `It ensures that all data writes can be immediately perceived in reads during the same session.`,
   consistencyEventuallyTooltip: `There is no guaranteed order of reads and writes, and replicas eventually converge to the same state given that no further write operations are done.`,
   consistencyEventuallyTooltip: `There is no guaranteed order of reads and writes, and replicas eventually converge to the same state given that no further write operations are done.`,
   releaseCollectionFirst: `Please release your collection first.`,
   releaseCollectionFirst: `Please release your collection first.`,
-  noVectorIndexTooltip: `No vector index, create one first.`,
+  noVectorIndexTooltip: `Please make sure all vector fields have index.`,
 
 
   clickToLoad: 'Click to load the collection.',
   clickToLoad: 'Click to load the collection.',
   clickToRelease: 'Click to release the collection.',
   clickToRelease: 'Click to release the collection.',

+ 3 - 3
client/src/pages/databases/collections/CreateFields.tsx

@@ -24,7 +24,7 @@ import {
   VECTOR_FIELDS_OPTIONS,
   VECTOR_FIELDS_OPTIONS,
 } from './Constants';
 } from './Constants';
 import { CreateFieldsProps, CreateFieldType, FieldType } from './Types';
 import { CreateFieldsProps, CreateFieldType, FieldType } from './Types';
-import { DataTypeEnum, vectorTypes } from '@/consts';
+import { DataTypeEnum, VectorTypes } from '@/consts';
 import {
 import {
   DEFAULT_ATTU_DIM,
   DEFAULT_ATTU_DIM,
   DEFAULT_ATTU_MAX_CAPACITY,
   DEFAULT_ATTU_MAX_CAPACITY,
@@ -243,7 +243,7 @@ const CreateFields: FC<CreateFieldsProps> = ({
     className?: string
     className?: string
   ) => {
   ) => {
     const defaultLabal = collectionTrans(
     const defaultLabal = collectionTrans(
-      vectorTypes.includes(field.data_type) ? 'vectorFieldName' : 'fieldName'
+      VectorTypes.includes(field.data_type) ? 'vectorFieldName' : 'fieldName'
     );
     );
 
 
     return getInput({
     return getInput({
@@ -464,7 +464,7 @@ const CreateFields: FC<CreateFieldsProps> = ({
 
 
       // remove dimension, if not vector
       // remove dimension, if not vector
       if (
       if (
-        !vectorTypes.includes(updatedField.data_type) ||
+        !VectorTypes.includes(updatedField.data_type) ||
         updatedField.data_type === DataTypeEnum.SparseFloatVector
         updatedField.data_type === DataTypeEnum.SparseFloatVector
       ) {
       ) {
         delete updatedField.dimension;
         delete updatedField.dimension;

+ 4 - 4
client/src/pages/databases/collections/overview/Create.tsx

@@ -10,7 +10,7 @@ import {
   INDEX_TYPES_ENUM,
   INDEX_TYPES_ENUM,
   DataTypeEnum,
   DataTypeEnum,
   DataTypeStringEnum,
   DataTypeStringEnum,
-  vectorTypes,
+  VectorTypes,
 } from '@/consts';
 } from '@/consts';
 import { useFormValidation } from '@/hooks';
 import { useFormValidation } from '@/hooks';
 import { getCreateIndexJSCode } from '@/utils/code/Js';
 import { getCreateIndexJSCode } from '@/utils/code/Js';
@@ -115,7 +115,7 @@ const CreateIndex = (props: {
   }, [indexSetting.index_type]);
   }, [indexSetting.index_type]);
 
 
   const metricOptions = useMemo(() => {
   const metricOptions = useMemo(() => {
-    return vectorTypes.includes(dataType)
+    return VectorTypes.includes(dataType)
       ? getMetricOptions(indexSetting.index_type, dataType)
       ? getMetricOptions(indexSetting.index_type, dataType)
       : [];
       : [];
   }, [indexSetting.index_type, fieldType]);
   }, [indexSetting.index_type, fieldType]);
@@ -156,7 +156,7 @@ const CreateIndex = (props: {
   }, [fieldType]);
   }, [fieldType]);
 
 
   const checkedForm = useMemo(() => {
   const checkedForm = useMemo(() => {
-    if (!vectorTypes.includes(dataType)) {
+    if (!VectorTypes.includes(dataType)) {
       return [];
       return [];
     }
     }
     const paramsForm: any = { metric_type: indexSetting.metric_type };
     const paramsForm: any = { metric_type: indexSetting.metric_type };
@@ -171,7 +171,7 @@ const CreateIndex = (props: {
    * create index code mode
    * create index code mode
    */
    */
   const codeBlockData: CodeViewData[] = useMemo(() => {
   const codeBlockData: CodeViewData[] = useMemo(() => {
-    const isScalarField = !vectorTypes.includes(dataType);
+    const isScalarField = !VectorTypes.includes(dataType);
     const getCodeParams = {
     const getCodeParams = {
       collectionName,
       collectionName,
       fieldName,
       fieldName,

+ 23 - 13
client/src/pages/databases/collections/overview/Overview.tsx

@@ -257,6 +257,28 @@ const Overview = () => {
     },
     },
   ];
   ];
 
 
+
+  // only show create index element when there is only one vector field
+  let CreateIndexElement = null;
+  if (
+    collection &&
+    collection.schema &&
+    collection.schema.vectorFields.length === 1
+  ) {
+    CreateIndexElement = (
+      <IndexTypeElement
+        field={
+          (collection.schema && collection.schema.vectorFields[0]) ||
+          ({} as FieldObject)
+        }
+        collectionName={collectionName}
+        cb={async () => {
+          await fetchCollection(collectionName);
+        }}
+      />
+    );
+  }
+
   // get loading state label
   // get loading state label
   return (
   return (
     <section className={classes.wrapper}>
     <section className={classes.wrapper}>
@@ -280,19 +302,7 @@ const Overview = () => {
                 percentage={collection.loadedPercentage}
                 percentage={collection.loadedPercentage}
                 collection={collection}
                 collection={collection}
                 showExtraAction={true}
                 showExtraAction={true}
-                createIndexElement={
-                  <IndexTypeElement
-                    field={
-                      (collection.schema &&
-                        collection.schema.vectorFields[0]) ||
-                      ({} as FieldObject)
-                    }
-                    collectionName={collectionName}
-                    cb={async () => {
-                      await fetchCollection(collectionName);
-                    }}
-                  />
-                }
+                createIndexElement={CreateIndexElement}
               />
               />
             </div>
             </div>
           </section>
           </section>

+ 2 - 2
client/src/pages/dialogs/CreateCollectionDialog.tsx

@@ -17,7 +17,7 @@ import {
   DataTypeEnum,
   DataTypeEnum,
   ConsistencyLevelEnum,
   ConsistencyLevelEnum,
   DEFAULT_ATTU_DIM,
   DEFAULT_ATTU_DIM,
-  vectorTypes,
+  VectorTypes,
 } from '@/consts';
 } from '@/consts';
 import CreateFields from '../databases/collections/CreateFields';
 import CreateFields from '../databases/collections/CreateFields';
 import {
 import {
@@ -233,7 +233,7 @@ const CreateCollectionDialog: FC<CollectionCreateProps> = ({ onCreate }) => {
 
 
         v.is_primary_key && (data.autoID = form.autoID);
         v.is_primary_key && (data.autoID = form.autoID);
 
 
-        const param = vectorTypes.includes(v.data_type)
+        const param = VectorTypes.includes(v.data_type)
           ? {
           ? {
               ...data,
               ...data,
               type_params: {
               type_params: {

+ 2 - 3
client/src/utils/Format.ts

@@ -2,8 +2,7 @@ import {
   BYTE_UNITS,
   BYTE_UNITS,
   DEFAULT_MILVUS_PORT,
   DEFAULT_MILVUS_PORT,
   DEFAULT_PROMETHEUS_PORT,
   DEFAULT_PROMETHEUS_PORT,
-  DataTypeEnum,
-  vectorTypes,
+  VectorTypes,
 } from '@/consts';
 } from '@/consts';
 import {
 import {
   CreateFieldType,
   CreateFieldType,
@@ -108,7 +107,7 @@ export const getCreateFieldType = (config: CreateField): CreateFieldType => {
     return 'defaultVector';
     return 'defaultVector';
   }
   }
 
 
-  if (vectorTypes.includes(config.data_type)) {
+  if (VectorTypes.includes(config.data_type)) {
     return 'vector';
     return 'vector';
   }
   }
 
 

+ 3 - 5
server/src/collections/collections.service.ts

@@ -39,6 +39,7 @@ import {
   DYNAMIC_FIELD,
   DYNAMIC_FIELD,
   SimpleQueue,
   SimpleQueue,
   MIN_INT64,
   MIN_INT64,
+  VectorTypes,
 } from '../utils';
 } from '../utils';
 import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';
 import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';
 import {
 import {
@@ -112,10 +113,7 @@ export class CollectionsService {
         ) || -1;
         ) || -1;
 
 
       // classify fields
       // classify fields
-      if (
-        field.data_type === 'BinaryVector' ||
-        field.data_type === 'FloatVector'
-      ) {
+      if (VectorTypes.includes(field.data_type)) {
         vectorFields.push(field);
         vectorFields.push(field);
       } else {
       } else {
         scalarFields.push(field);
         scalarFields.push(field);
@@ -127,7 +125,7 @@ export class CollectionsService {
     });
     });
 
 
     // add extra data to schema
     // add extra data to schema
-    res.schema.hasVectorIndex = vectorFields.some(v => v.index);
+    res.schema.hasVectorIndex = vectorFields.every(v => v.index);
     res.schema.scalarFields = scalarFields;
     res.schema.scalarFields = scalarFields;
     res.schema.vectorFields = vectorFields;
     res.schema.vectorFields = vectorFields;
     res.schema.dynamicFields = res.schema.enable_dynamic_field
     res.schema.dynamicFields = res.schema.enable_dynamic_field

+ 8 - 0
server/src/utils/Const.ts

@@ -156,3 +156,11 @@ export enum LOADING_STATE {
 
 
 export const MIN_INT64 = `-9223372036854775807`; // safe int64 min value
 export const MIN_INT64 = `-9223372036854775807`; // safe int64 min value
 export const DYNAMIC_FIELD = `$meta`;
 export const DYNAMIC_FIELD = `$meta`;
+
+export const VectorTypes = [
+  'BinaryVector',
+  'FloatVector',
+  'SpaseFloatVector',
+  'Float16Vector',
+  'BFloat16Vector',
+];