Index.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. IndexCreateParam,
  3. IndexManageParam,
  4. IndexView,
  5. ParamPair,
  6. } from '../pages/schema/Types';
  7. import { ManageRequestMethods } from '../types/Common';
  8. import { IndexState } from '../types/Milvus';
  9. import { findKeyValue } from '../utils/Common';
  10. import { getKeyValueListFromJsonString } from '../utils/Format';
  11. import BaseModel from './BaseModel';
  12. export class IndexHttp extends BaseModel implements IndexView {
  13. params!: ParamPair[];
  14. field_name!: string;
  15. constructor(props: {}) {
  16. super(props);
  17. Object.assign(this, props);
  18. }
  19. static BASE_URL = `/schema/index`;
  20. static async getIndexStatus(
  21. collectionName: string,
  22. fieldName: string
  23. ): Promise<IndexState> {
  24. const path = `${this.BASE_URL}/state`;
  25. return super.findAll({
  26. path,
  27. params: { collection_name: collectionName, field_name: fieldName },
  28. });
  29. }
  30. static async getIndexInfo(collectionName: string): Promise<IndexHttp[]> {
  31. const path = this.BASE_URL;
  32. const res = await super.findAll({
  33. path,
  34. params: { collection_name: collectionName },
  35. });
  36. return res.index_descriptions.map((index: any) => new this(index));
  37. }
  38. static async createIndex(param: IndexCreateParam) {
  39. const path = this.BASE_URL;
  40. const type: ManageRequestMethods = ManageRequestMethods.CREATE;
  41. return super.create({
  42. path,
  43. data: { ...param, type },
  44. });
  45. }
  46. static async deleteIndex(param: IndexManageParam) {
  47. const path = this.BASE_URL;
  48. const type: ManageRequestMethods = ManageRequestMethods.DELETE;
  49. return super.batchDelete({ path, data: { ...param, type } });
  50. }
  51. get _indexType() {
  52. return this.params.find(p => p.key === 'index_type')?.value || '';
  53. }
  54. get _indexParameterPairs() {
  55. const metricType = this.params.filter(v => v.key === 'metric_type');
  56. // parms is json string, so we need parse it to key value array
  57. const params = findKeyValue(this.params, 'params');
  58. if (params) {
  59. return [...metricType, ...getKeyValueListFromJsonString(params)];
  60. }
  61. return metricType;
  62. }
  63. get _fieldName() {
  64. return this.field_name;
  65. }
  66. get _metricType() {
  67. return this.params.find(p => p.key === 'metric_type')?.value || '';
  68. }
  69. }