dto.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {
  2. IsNotEmpty,
  3. IsString,
  4. IsBoolean,
  5. IsOptional,
  6. IsArray,
  7. ArrayNotEmpty,
  8. IsEnum,
  9. ArrayMinSize,
  10. } from 'class-validator';
  11. import {
  12. FieldType,
  13. ShowCollectionsType,
  14. } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
  15. import {
  16. DataType,
  17. KeyValuePair,
  18. } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
  19. import { ApiProperty } from '@nestjs/swagger';
  20. enum VectorTypes {
  21. Binary = DataType.BinaryVector,
  22. Float = DataType.FloatVector,
  23. }
  24. export class CreateCollection {
  25. @ApiProperty({
  26. description: 'Milvus collection name',
  27. })
  28. @IsString()
  29. @IsNotEmpty({
  30. message: 'collection_name is empty',
  31. })
  32. readonly collection_name: string;
  33. @ApiProperty({
  34. description: 'Generate ID automatically by milvus',
  35. type: Boolean,
  36. })
  37. @IsBoolean()
  38. @IsOptional()
  39. readonly autoID: boolean;
  40. @ApiProperty({
  41. description: 'Field data type',
  42. })
  43. @IsArray()
  44. @ArrayNotEmpty()
  45. @IsNotEmpty({
  46. message: 'fields is empty',
  47. })
  48. readonly fields: FieldType[];
  49. }
  50. export class ShowCollections {
  51. @ApiProperty({
  52. description: 'Type allow all->0 inmemory->1',
  53. enum: ShowCollectionsType,
  54. })
  55. @IsOptional()
  56. @IsEnum(ShowCollectionsType, { message: 'Type allow all->0 inmemory->1' })
  57. readonly type: ShowCollectionsType;
  58. }
  59. export class InsertData {
  60. @ApiProperty({
  61. description: 'Partition in this collection',
  62. })
  63. @IsOptional()
  64. readonly partition_names: string[];
  65. @ApiProperty({
  66. description: 'The fields data in this collection',
  67. default: [{ vector: [1, 2, 3], a: 1, b: 2 }],
  68. })
  69. readonly fields_data: any[];
  70. }
  71. export class VectorSearch {
  72. @ApiProperty({
  73. description: 'Milvus collection name',
  74. })
  75. @IsString()
  76. @IsNotEmpty({
  77. message: 'collection_name is empty',
  78. })
  79. collection_name: string;
  80. @ApiProperty({
  81. description: 'Partition in this collection',
  82. })
  83. @IsOptional()
  84. partition_names?: string[];
  85. @ApiProperty({
  86. description: 'Non vector fields filter.',
  87. })
  88. @IsString()
  89. expr?: string;
  90. @ApiProperty({
  91. description: 'Vector search params',
  92. default: [{ key: 'metric_type', value: 'L2' }],
  93. })
  94. @IsArray()
  95. @ArrayMinSize(1)
  96. search_params: KeyValuePair[];
  97. @ApiProperty({
  98. description: 'Searched vector value',
  99. default: [[1, 2, 3, 4]],
  100. })
  101. @IsArray()
  102. @ArrayMinSize(1)
  103. vectors: number[][];
  104. @ApiProperty({
  105. description:
  106. 'Define what non vector fields you want return in search results',
  107. default: ['a', 'b'],
  108. })
  109. @IsArray()
  110. @IsOptional()
  111. output_fields?: string[];
  112. @ApiProperty({
  113. description: 'Only support 101(binary) or 100(float)',
  114. enum: VectorTypes,
  115. })
  116. @IsEnum(VectorTypes, { message: 'Type allow all->0 inmemory->1' })
  117. vector_type: DataType.BinaryVector | DataType.FloatVector;
  118. }