dto.ts 2.9 KB

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