dto.ts 2.8 KB

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