Browse Source

update node sdk to latest

nameczz 3 years ago
parent
commit
9cb30d652d

+ 1 - 1
server/package.json

@@ -32,7 +32,7 @@
     "@nestjs/websockets": "^8.0.4",
     "@nestjs/websockets": "^8.0.4",
     "@types/passport-jwt": "^3.0.5",
     "@types/passport-jwt": "^3.0.5",
     "@types/passport-local": "^1.0.33",
     "@types/passport-local": "^1.0.33",
-    "@zilliz/milvus2-sdk-node": "^1.0.7",
+    "@zilliz/milvus2-sdk-node": "^1.0.11",
     "body-parser": "^1.19.0",
     "body-parser": "^1.19.0",
     "cache-manager": "^3.4.4",
     "cache-manager": "^3.4.4",
     "class-transformer": "^0.4.0",
     "class-transformer": "^0.4.0",

+ 1 - 1
server/src/cache/config.ts

@@ -2,4 +2,4 @@ export const ttl = 10; //seconds
 export const cacheKeys = {
 export const cacheKeys = {
   LOADEDCOLLECTIONS: 'LOADEDCOLLECTIONS',
   LOADEDCOLLECTIONS: 'LOADEDCOLLECTIONS',
   ALLCOLLECTIONS: 'ALLCOLLECTIONS',
   ALLCOLLECTIONS: 'ALLCOLLECTIONS',
-};
+};

+ 20 - 12
server/src/collections/collections.service.ts

@@ -22,60 +22,68 @@ import {
 export class CollectionsService {
 export class CollectionsService {
   constructor(private milvusService: MilvusService) {}
   constructor(private milvusService: MilvusService) {}
 
 
-  get milvusClient() {
-    return this.milvusService.milvusClientGetter;
+  get collectionManager() {
+    return this.milvusService.collectionManager;
+  }
+
+  get dataManager() {
+    return this.milvusService.dataManager;
+  }
+
+  get indexManager() {
+    return this.milvusService.indexManager;
   }
   }
 
 
   async getCollectionNames(data?: ShowCollectionsReq) {
   async getCollectionNames(data?: ShowCollectionsReq) {
-    const res = await this.milvusClient.showCollections(data);
+    const res = await this.collectionManager.showCollections(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async createCollection(data: CreateCollectionReq) {
   async createCollection(data: CreateCollectionReq) {
-    const res = await this.milvusClient.createCollection(data);
+    const res = await this.collectionManager.createCollection(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async describeCollection(data: DescribeCollectionReq) {
   async describeCollection(data: DescribeCollectionReq) {
-    const res = await this.milvusClient.describeCollection(data);
+    const res = await this.collectionManager.describeCollection(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async dropCollection(data: DropCollectionReq) {
   async dropCollection(data: DropCollectionReq) {
-    const res = await this.milvusClient.dropCollection(data);
+    const res = await this.collectionManager.dropCollection(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async loadCollection(data: LoadCollectionReq) {
   async loadCollection(data: LoadCollectionReq) {
-    const res = await this.milvusClient.loadCollection(data);
+    const res = await this.collectionManager.loadCollection(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async releaseCollection(data: ReleaseLoadCollectionReq) {
   async releaseCollection(data: ReleaseLoadCollectionReq) {
-    const res = await this.milvusClient.releaseCollection(data);
+    const res = await this.collectionManager.releaseCollection(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async getCollectionStatistics(data: GetCollectionStatisticsReq) {
   async getCollectionStatistics(data: GetCollectionStatisticsReq) {
-    const res = await this.milvusClient.getCollectionStatistics(data);
+    const res = await this.collectionManager.getCollectionStatistics(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async insert(data: InsertReq) {
   async insert(data: InsertReq) {
-    const res = await this.milvusClient.insert(data);
+    const res = await this.dataManager.insert(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async vectorSearch(data: SearchReq) {
   async vectorSearch(data: SearchReq) {
-    const res = await this.milvusClient.search(data);
+    const res = await this.dataManager.search(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
@@ -88,7 +96,7 @@ export class CollectionsService {
    * @returns
    * @returns
    */
    */
   async getIndexStatus(data: GetIndexStateReq) {
   async getIndexStatus(data: GetIndexStateReq) {
-    const res = await this.milvusClient.getIndexState(data);
+    const res = await this.indexManager.getIndexState(data);
     return res;
     return res;
   }
   }
 
 

+ 3 - 5
server/src/collections/dto.ts

@@ -12,11 +12,9 @@ import {
   FieldType,
   FieldType,
   ShowCollectionsType,
   ShowCollectionsType,
 } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
 } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
-import {
-  DataType,
-  KeyValuePair,
-} from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
+import { DataType } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
 import { ApiProperty } from '@nestjs/swagger';
 import { ApiProperty } from '@nestjs/swagger';
+import { SearchParam } from '@zilliz/milvus2-sdk-node/dist/milvus/types';
 
 
 enum VectorTypes {
 enum VectorTypes {
   Binary = DataType.BinaryVector,
   Binary = DataType.BinaryVector,
@@ -103,7 +101,7 @@ export class VectorSearch {
   })
   })
   @IsArray()
   @IsArray()
   @ArrayMinSize(1)
   @ArrayMinSize(1)
-  search_params: KeyValuePair[];
+  search_params: SearchParam[];
 
 
   @ApiProperty({
   @ApiProperty({
     description: 'Searched vector value',
     description: 'Searched vector value',

+ 19 - 2
server/src/milvus/milvus.service.ts

@@ -18,11 +18,28 @@ export class MilvusService {
     return this.milvusClient;
     return this.milvusClient;
   }
   }
 
 
+  get collectionManager() {
+    return this.milvusClient.collectionManager;
+  }
+
+  get partitionManager() {
+    return this.milvusClient.partitionManager;
+  }
+
+  get indexManager() {
+    return this.milvusClient.indexManager;
+  }
+
+  get dataManager() {
+    return this.milvusClient.dataManager;
+  }
+
   async connectMilvus(address: string) {
   async connectMilvus(address: string) {
+    // grpc only need address without http
     const milvusAddress = address.replace(/(http|https):\/\//, '');
     const milvusAddress = address.replace(/(http|https):\/\//, '');
     try {
     try {
       this.milvusClient = new MilvusClient(milvusAddress);
       this.milvusClient = new MilvusClient(milvusAddress);
-      await this.milvusClient.hasCollection({
+      await this.milvusClient.collectionManager.hasCollection({
         collection_name: 'not_exist',
         collection_name: 'not_exist',
       });
       });
       this.milvusAddress = address;
       this.milvusAddress = address;
@@ -43,7 +60,7 @@ export class MilvusService {
   }
   }
 
 
   async flush(data: FlushReq) {
   async flush(data: FlushReq) {
-    const res = await this.milvusClient.flush(data);
+    const res = await this.milvusClient.dataManager.flush(data);
     return res;
     return res;
   }
   }
 }
 }

+ 8 - 8
server/src/partitions/partitions.service.ts

@@ -16,8 +16,8 @@ import { ROW_COUNT } from '../utils/Const';
 export class PartitionsService {
 export class PartitionsService {
   constructor(private milvusService: MilvusService) {}
   constructor(private milvusService: MilvusService) {}
 
 
-  get milvusClient() {
-    return this.milvusService.milvusClientGetter;
+  get partitionManager() {
+    return this.milvusService.partitionManager;
   }
   }
 
 
   async getPatitionsInfo(data: ShowPartitionsReq) {
   async getPatitionsInfo(data: ShowPartitionsReq) {
@@ -41,37 +41,37 @@ export class PartitionsService {
   }
   }
 
 
   async getPartitions(data: ShowPartitionsReq) {
   async getPartitions(data: ShowPartitionsReq) {
-    const res = await this.milvusClient.showPartitions(data);
+    const res = await this.partitionManager.showPartitions(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async createParition(data: CreatePartitionReq) {
   async createParition(data: CreatePartitionReq) {
-    const res = await this.milvusClient.createPartition(data);
+    const res = await this.partitionManager.createPartition(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async deleteParition(data: DropPartitionReq) {
   async deleteParition(data: DropPartitionReq) {
-    const res = await this.milvusClient.dropPartition(data);
+    const res = await this.partitionManager.dropPartition(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async getPartitionStatistics(data: GetPartitionStatisticsReq) {
   async getPartitionStatistics(data: GetPartitionStatisticsReq) {
-    const res = await this.milvusClient.getPartitionStatistics(data);
+    const res = await this.partitionManager.getPartitionStatistics(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async loadPartitions(data: LoadPartitionsReq) {
   async loadPartitions(data: LoadPartitionsReq) {
-    const res = await this.milvusClient.loadPartitions(data);
+    const res = await this.partitionManager.loadPartitions(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async releasePartitions(data: ReleasePartitionsReq) {
   async releasePartitions(data: ReleasePartitionsReq) {
-    const res = await this.milvusClient.releasePartitions(data);
+    const res = await this.partitionManager.releasePartitions(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }

+ 2 - 1
server/src/schema/dto.ts

@@ -1,4 +1,5 @@
 import { ApiProperty } from '@nestjs/swagger';
 import { ApiProperty } from '@nestjs/swagger';
+import { CreateIndexParam } from '@zilliz/milvus2-sdk-node/dist/milvus/types';
 import {
 import {
   IsNotEmpty,
   IsNotEmpty,
   IsString,
   IsString,
@@ -47,7 +48,7 @@ export class ManageIndex {
   })
   })
   @IsArray()
   @IsArray()
   @IsOptional()
   @IsOptional()
-  readonly extra_params?: KeyValuePair[];
+  readonly extra_params?: CreateIndexParam[];
 }
 }
 
 
 export class DescribeIndex {
 export class DescribeIndex {

+ 5 - 5
server/src/schema/schema.controller.ts

@@ -20,7 +20,7 @@ import { SchemaService } from './schema.service';
 @ApiTags('schema')
 @ApiTags('schema')
 @Controller('schema')
 @Controller('schema')
 export class SchemaController {
 export class SchemaController {
-  constructor(private schemaService: SchemaService) { }
+  constructor(private schemaService: SchemaService) {}
 
 
   @Post('index')
   @Post('index')
   @UsePipes(new ValidationPipe())
   @UsePipes(new ValidationPipe())
@@ -28,10 +28,10 @@ export class SchemaController {
     const { type, collection_name, extra_params, field_name } = body;
     const { type, collection_name, extra_params, field_name } = body;
     return type === ManageType.CREATE
     return type === ManageType.CREATE
       ? await this.schemaService.createIndex({
       ? await this.schemaService.createIndex({
-        collection_name,
-        extra_params,
-        field_name,
-      })
+          collection_name,
+          extra_params,
+          field_name,
+        })
       : await this.schemaService.dropIndex({ collection_name, field_name });
       : await this.schemaService.dropIndex({ collection_name, field_name });
   }
   }
 
 

+ 8 - 8
server/src/schema/schema.service.ts

@@ -11,20 +11,20 @@ import { MilvusService } from '../milvus/milvus.service';
 
 
 @Injectable()
 @Injectable()
 export class SchemaService {
 export class SchemaService {
-  constructor(private milvusService: MilvusService) { }
+  constructor(private milvusService: MilvusService) {}
 
 
-  get milvusClient() {
-    return this.milvusService.milvusClientGetter;
+  get indexManager() {
+    return this.milvusService.indexManager;
   }
   }
 
 
   async createIndex(data: CreateIndexReq) {
   async createIndex(data: CreateIndexReq) {
-    const res = await this.milvusClient.createIndex(data);
+    const res = await this.indexManager.createIndex(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async describeIndex(data: DescribeIndexReq) {
   async describeIndex(data: DescribeIndexReq) {
-    const res = await this.milvusClient.describeIndex(data);
+    const res = await this.indexManager.describeIndex(data);
     if (res.status.error_code === 'IndexNotExist') {
     if (res.status.error_code === 'IndexNotExist') {
       return res;
       return res;
     }
     }
@@ -33,19 +33,19 @@ export class SchemaService {
   }
   }
 
 
   async dropIndex(data: DropIndexReq) {
   async dropIndex(data: DropIndexReq) {
-    const res = await this.milvusClient.dropIndex(data);
+    const res = await this.indexManager.dropIndex(data);
     throwErrorFromSDK(res);
     throwErrorFromSDK(res);
     return res;
     return res;
   }
   }
 
 
   async getIndexState(data: GetIndexStateReq) {
   async getIndexState(data: GetIndexStateReq) {
-    const res = await this.milvusClient.getIndexState(data);
+    const res = await this.indexManager.getIndexState(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }
 
 
   async getIndexBuildProgress(data: GetIndexBuildProgressReq) {
   async getIndexBuildProgress(data: GetIndexBuildProgressReq) {
-    const res = await this.milvusClient.getIndexBuildProgress(data);
+    const res = await this.indexManager.getIndexBuildProgress(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
     return res;
     return res;
   }
   }

+ 4 - 4
server/yarn.lock

@@ -1319,10 +1319,10 @@
   resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
   resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
   integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
   integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
 
 
-"@zilliz/milvus2-sdk-node@^1.0.7":
-  version "1.0.7"
-  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-1.0.7.tgz#b3d0bedbf9e35662e76e716ddb99dc3fc781fc00"
-  integrity sha512-4DFNqDkELG/s4JHqlT6/yZOtMxBWSca1G+RGfj3UC3pg7ncAUuw7HSpScLJ0uWhdUABWroQC6AD0DLnHNGhjFQ==
+"@zilliz/milvus2-sdk-node@^1.0.11":
+  version "1.0.11"
+  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-1.0.11.tgz#a8545c2b5d5474de60a5ae2cb65cd06d5cdfba87"
+  integrity sha512-SmpB8txE0mgztxgnL0ssTMij9biji+7ZxmdhN3b0VwrghxfeCvSTRrBYmSE7WTPOK143G4k/trSrESSmcBM+cQ==
   dependencies:
   dependencies:
     "@grpc/grpc-js" "^1.2.12"
     "@grpc/grpc-js" "^1.2.12"
     "@grpc/proto-loader" "^0.6.0"
     "@grpc/proto-loader" "^0.6.0"