Form.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Option } from '../components/customSelector/Types';
  2. import { METRIC_TYPES_VALUES } from '../consts/Milvus';
  3. import { IForm } from '../hooks/Form';
  4. import { DataType } from '../pages/collections/Types';
  5. import { IndexType } from '../pages/schema/Types';
  6. interface IInfo {
  7. [key: string]: any;
  8. }
  9. export const formatForm = (info: IInfo): IForm[] => {
  10. const form: IForm[] = Object.entries(info).map(item => {
  11. const [key, value] = item;
  12. return {
  13. key,
  14. value,
  15. needCheck: true,
  16. };
  17. });
  18. return form;
  19. };
  20. export const getMetricOptions = (
  21. indexType: IndexType,
  22. fieldType: DataType
  23. ): Option[] => {
  24. const baseFloatOptions = [
  25. {
  26. value: METRIC_TYPES_VALUES.L2,
  27. label: 'L2',
  28. },
  29. {
  30. value: METRIC_TYPES_VALUES.IP,
  31. label: 'IP',
  32. },
  33. ];
  34. const baseBinaryOptions = [
  35. {
  36. value: METRIC_TYPES_VALUES.HAMMING,
  37. label: 'HAMMING',
  38. },
  39. {
  40. value: METRIC_TYPES_VALUES.JACCARD,
  41. label: 'JACCARD',
  42. },
  43. {
  44. value: METRIC_TYPES_VALUES.TANIMOTO,
  45. label: 'TANIMOTO',
  46. },
  47. ];
  48. const type = fieldType === 'FloatVector' ? 'ALL' : indexType;
  49. const baseOptionsMap: { [key: string]: any } = {
  50. BinaryVector: {
  51. BIN_FLAT: [
  52. ...baseBinaryOptions,
  53. {
  54. value: METRIC_TYPES_VALUES.SUBSTRUCTURE,
  55. label: 'SUBSTRUCTURE',
  56. },
  57. {
  58. value: METRIC_TYPES_VALUES.SUPERSTRUCTURE,
  59. label: 'SUPERSTRUCTURE',
  60. },
  61. ],
  62. BIN_IVF_FLAT: baseBinaryOptions,
  63. },
  64. FloatVector: {
  65. ALL: baseFloatOptions,
  66. },
  67. };
  68. return baseOptionsMap[fieldType][type];
  69. };