From 00b774fbf20c2aa6a80c43db6cb05790b82ab93b Mon Sep 17 00:00:00 2001 From: ryjiang Date: Wed, 18 Dec 2024 16:01:41 +0800 Subject: [PATCH 1/2] WIP Signed-off-by: ryjiang --- milvus/grpc/MilvusIndex.ts | 50 ++++++++++++++++++++++++++++++++++++- milvus/types/MilvusIndex.ts | 5 ++++ test/grpc/Index.spec.ts | 17 +++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/milvus/grpc/MilvusIndex.ts b/milvus/grpc/MilvusIndex.ts index 48044bf4..b4cd44ed 100644 --- a/milvus/grpc/MilvusIndex.ts +++ b/milvus/grpc/MilvusIndex.ts @@ -8,6 +8,7 @@ import { GetIndexBuildProgressReq, GetIndexStateReq, AlterIndexReq, + DropIndexPropertiesReq, ResStatus, DescribeIndexResponse, GetIndexStateResponse, @@ -338,7 +339,7 @@ export class Index extends Data { * console.log(res); * ``` */ - async alterIndex(data: AlterIndexReq): Promise { + async alterIndexProperties(data: AlterIndexReq): Promise { checkCollectionName(data); const req = { collection_name: data.collection_name, @@ -358,4 +359,51 @@ export class Index extends Data { ); return promise; } + + /** + * @deprecated + */ + alterIndex = this.alterIndexProperties; + + /** + * Drop index properties. + * @param {DropIndexPropertiesReq} data - The data for dropping the index properties. + * @param {string} data.collection_name - The name of the collection. + * @param {string} data.index_name - The name of the index. + * @param {string[]} data.properties - The properties to be dropped. + * @param {string} [data.db_name] - The name of the database. + * @param {number} [data.timeout] - An optional duration of time in milliseconds to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or an error occurs. Default is undefined. + * @returns {Promise} - A promise that resolves to a response status object. + * + * @example + * ``` + * const milvusClient = new MilvusClient(MILUVS_ADDRESS); + * const dropIndexPropertiesReq = { + * collection_name: 'my_collection', + * index_name: 'my_index', + * properties: ['mmap.enabled'], + * }; + * const res = await milvusClient.dropIndexProperties(dropIndexPropertiesReq); + * console.log(res); + * ``` + */ + async dropIndexProperties(data: DropIndexPropertiesReq): Promise { + const req = { + collection_name: data.collection_name, + index_name: data.index_name, + delete_keys: data.properties, + } as any; + + if (data.db_name) { + req.db_name = data.db_name; + } + + const promise = await promisify( + this.channelPool, + 'AlterIndex', + req, + data.timeout || this.timeout + ); + return promise; + } } diff --git a/milvus/types/MilvusIndex.ts b/milvus/types/MilvusIndex.ts index 5ea81769..90c2b8e5 100644 --- a/milvus/types/MilvusIndex.ts +++ b/milvus/types/MilvusIndex.ts @@ -71,3 +71,8 @@ export interface AlterIndexReq extends collectionNameReq { index_name: string; params: Record; } + +export interface DropIndexPropertiesReq extends collectionNameReq { + index_name: string; + properties: string[]; +} diff --git a/test/grpc/Index.spec.ts b/test/grpc/Index.spec.ts index c420ba8b..d7e3cfcc 100644 --- a/test/grpc/Index.spec.ts +++ b/test/grpc/Index.spec.ts @@ -393,6 +393,23 @@ describe(`Milvus Index API`, () => { // console.log('describe', describe.index_descriptions[0].params); }); + it(`Drop Index properties with field name should be success`, async () => { + const res = await milvusClient.dropIndexProperties({ + collection_name: COLLECTION_NAME, + index_name: INDEX_NAME, + properties: ['mmap.enabled'], + }); + expect(res.error_code).toEqual(ErrorCode.SUCCESS); + + const describe = await milvusClient.describeIndex({ + collection_name: COLLECTION_NAME, + index_name: INDEX_NAME, + }); + + const params = describe.index_descriptions[0].params; + expect(findKeyValue(params, 'mmap.enabled')).toEqual(undefined); + }); + // @Deprecated // it(`Get Index progress with field name should be failed`, async () => { // const res = await milvusClient.getIndexBuildProgress({ From d35d78a8a0dd71e80b054b954239f5bc335647b2 Mon Sep 17 00:00:00 2001 From: ryjiang Date: Wed, 18 Dec 2024 16:18:24 +0800 Subject: [PATCH 2/2] add more test Signed-off-by: ryjiang --- test/grpc/Database.spec.ts | 23 ++++++++++++++++++++++- test/grpc/Index.spec.ts | 17 +++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/test/grpc/Database.spec.ts b/test/grpc/Database.spec.ts index 90dbd890..f60da33e 100644 --- a/test/grpc/Database.spec.ts +++ b/test/grpc/Database.spec.ts @@ -3,6 +3,7 @@ import { ErrorCode, DEFAULT_DB, formatKeyValueData, + findKeyValue, } from '../../milvus'; import { IP, @@ -194,7 +195,7 @@ describe(`Database API`, () => { expect(createIndex.error_code).toEqual(ErrorCode.SUCCESS); // alter index - const alterIndex = await milvusClient.alterIndex({ + const alterIndex = await milvusClient.alterIndexProperties({ collection_name: COLLECTION_NAME2, db_name: DB_NAME2, index_name: 'vector2', @@ -209,6 +210,26 @@ describe(`Database API`, () => { index_name: 'vector2', }); expect(describeIndex.index_descriptions[0].index_name).toEqual('vector2'); + const p1 = describeIndex.index_descriptions[0].params; + expect(findKeyValue(p1, 'mmap.enabled')).toEqual('true'); + + // drop index properties + const dropIndexProperties = await milvusClient.dropIndexProperties({ + collection_name: COLLECTION_NAME2, + db_name: DB_NAME2, + index_name: 'vector2', + properties: ['mmap.enabled'], + }); + expect(dropIndexProperties.error_code).toEqual(ErrorCode.SUCCESS); + + // describe index + const describeIndexAfterDrop = await milvusClient.describeIndex({ + collection_name: COLLECTION_NAME2, + db_name: DB_NAME2, + index_name: 'vector2', + }); + const p2 = describeIndexAfterDrop.index_descriptions[0].params; + expect(findKeyValue(p2, 'mmap.enabled')).toEqual(undefined); // load collection const loadCollection = await milvusClient.loadCollection({ diff --git a/test/grpc/Index.spec.ts b/test/grpc/Index.spec.ts index d7e3cfcc..34e35f2f 100644 --- a/test/grpc/Index.spec.ts +++ b/test/grpc/Index.spec.ts @@ -390,6 +390,23 @@ describe(`Milvus Index API`, () => { const params = describe.index_descriptions[0].params; expect(findKeyValue(params, 'mmap.enabled')).toEqual('true'); + const alter2 = await milvusClient.alterIndexProperties({ + collection_name: COLLECTION_NAME, + index_name: INDEX_NAME, + params: { + 'mmap.enabled': false, + }, + }); + + const describe2 = await milvusClient.describeIndex({ + collection_name: COLLECTION_NAME, + index_name: INDEX_NAME, + }); + + expect(alter2.error_code).toEqual(ErrorCode.SUCCESS); + const params2 = describe2.index_descriptions[0].params; + expect(findKeyValue(params2, 'mmap.enabled')).toEqual('false'); + // console.log('describe', describe.index_descriptions[0].params); });