Form.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Option } from '@/components/customSelector/Types';
  2. import {
  3. METRIC_TYPES_VALUES,
  4. DataTypeStringEnum,
  5. DataTypeEnum,
  6. } from '@/consts';
  7. import { IForm } from '@/hooks';
  8. import { IndexType } from '@/pages/databases/collections/overview/Types';
  9. interface IInfo {
  10. [key: string]: any;
  11. }
  12. export const formatForm = (info: IInfo): IForm[] => {
  13. const form: IForm[] = Object.entries(info).map(item => {
  14. const [key, value] = item;
  15. return {
  16. key,
  17. value,
  18. needCheck: true,
  19. };
  20. });
  21. return form;
  22. };
  23. export const getMetricOptions = (
  24. indexType: IndexType,
  25. fieldType: DataTypeEnum
  26. ): Option[] => {
  27. const baseFloatOptions = [
  28. {
  29. value: METRIC_TYPES_VALUES.L2,
  30. label: 'L2',
  31. },
  32. {
  33. value: METRIC_TYPES_VALUES.IP,
  34. label: 'IP',
  35. },
  36. {
  37. value: METRIC_TYPES_VALUES.COSINE,
  38. label: 'COSINE',
  39. },
  40. ];
  41. const baseBinaryOptions = [
  42. {
  43. value: METRIC_TYPES_VALUES.HAMMING,
  44. label: 'HAMMING',
  45. },
  46. {
  47. value: METRIC_TYPES_VALUES.JACCARD,
  48. label: 'JACCARD',
  49. },
  50. {
  51. value: METRIC_TYPES_VALUES.TANIMOTO,
  52. label: 'TANIMOTO',
  53. },
  54. ];
  55. switch (fieldType) {
  56. case DataTypeEnum.FloatVector:
  57. case DataTypeEnum.Float16Vector:
  58. case DataTypeEnum.BFloat16Vector:
  59. return baseFloatOptions;
  60. case DataTypeEnum.SparseFloatVector:
  61. return [
  62. {
  63. value: METRIC_TYPES_VALUES.IP,
  64. label: 'IP',
  65. },
  66. ];
  67. case DataTypeEnum.BinaryVector:
  68. switch (indexType) {
  69. case 'BIN_FLAT':
  70. return [
  71. ...baseBinaryOptions,
  72. {
  73. value: METRIC_TYPES_VALUES.SUBSTRUCTURE,
  74. label: 'SUBSTRUCTURE',
  75. },
  76. {
  77. value: METRIC_TYPES_VALUES.SUPERSTRUCTURE,
  78. label: 'SUPERSTRUCTURE',
  79. },
  80. ];
  81. case 'BIN_IVF_FLAT':
  82. return baseBinaryOptions;
  83. default:
  84. return baseBinaryOptions;
  85. }
  86. default:
  87. return [];
  88. }
  89. };