Skip to content

Commit

Permalink
Add alterIndexProperties and dropIndexProperties (#388)
Browse files Browse the repository at this point in the history
* WIP

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* add more test

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

---------

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid committed Dec 18, 2024
1 parent dc57be7 commit 780cfcf
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
50 changes: 49 additions & 1 deletion milvus/grpc/MilvusIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
GetIndexBuildProgressReq,
GetIndexStateReq,
AlterIndexReq,
DropIndexPropertiesReq,
ResStatus,
DescribeIndexResponse,
GetIndexStateResponse,
Expand Down Expand Up @@ -338,7 +339,7 @@ export class Index extends Data {
* console.log(res);
* ```
*/
async alterIndex(data: AlterIndexReq): Promise<ResStatus> {
async alterIndexProperties(data: AlterIndexReq): Promise<ResStatus> {
checkCollectionName(data);
const req = {
collection_name: data.collection_name,
Expand All @@ -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<ResStatus>} - 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<ResStatus> {
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;
}
}
5 changes: 5 additions & 0 deletions milvus/types/MilvusIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ export interface AlterIndexReq extends collectionNameReq {
index_name: string;
params: Record<string, number | string | boolean>;
}

export interface DropIndexPropertiesReq extends collectionNameReq {
index_name: string;
properties: string[];
}
23 changes: 22 additions & 1 deletion test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ErrorCode,
DEFAULT_DB,
formatKeyValueData,
findKeyValue,
} from '../../milvus';
import {
IP,
Expand Down Expand Up @@ -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',
Expand All @@ -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({
Expand Down
34 changes: 34 additions & 0 deletions test/grpc/Index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,43 @@ 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);
});

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({
Expand Down

0 comments on commit 780cfcf

Please sign in to comment.