Form.ts 1.7 KB

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