diff --git a/milvus/grpc/Collection.ts b/milvus/grpc/Collection.ts index dc39f1a4..99d963dd 100644 --- a/milvus/grpc/Collection.ts +++ b/milvus/grpc/Collection.ts @@ -55,6 +55,7 @@ import { CreateCollectionWithSchemaReq, FieldSchema, DropCollectionPropertiesReq, + AlterCollectionFieldPropertiesReq, isVectorType, } from '../'; @@ -364,7 +365,7 @@ export class Collection extends Database { * const milvusClient = new milvusClient(MILUVS_ADDRESS); * const resStatus = await milvusClient.dropCollectionProperties({ * collection_name: 'my-collection', - * delete_keys: ["collection.ttl.seconds"] + * delete_keys: ["collection.ttl.seconds"] * }); * ``` * @@ -394,6 +395,54 @@ export class Collection extends Database { return promise; } + /** + * Modifies a collection field's properties. + * Note that this operation only modifies the properties of the field, not the field itself. + * + * @param {AlterCollectionFieldPropertiesReq} data - The request parameters. + * @param {string} data.collection_name - The name of the collection to modify. + * @param {string} data.field_name - The name of the field to modify. + * @param {Object} data.properties - The properties to modify. For example, to change field mmap setting and max_length, use { 'mmap.enabled', true, max_length: 128}. + * @param {string} [data.db_name] - The name of the database where the collection is located. + * @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 error occurs. Default is undefined. + * + * @returns {Promise} The response status of the operation. + * @returns {string} status.error_code - The error code of the operation. + * @returns {string} status.reason - The reason for the error, if any. + * + * @example + * ``` + * const milvusClient = new milvusClient(MILUVS_ADDRESS); + * const resStatus = await milvusClient.alterCollectionField({ + * collection_name: 'my-collection', + * field_name: 'my-field', + * properties: {"mmap.enabled": true} + * }); + * ``` + */ + async alterCollectionFieldProperties( + data: AlterCollectionFieldPropertiesReq + ): Promise { + const req: any = { + collection_name: data.collection_name, + field_name: data.field_name, + properties: parseToKeyValue(data.properties), + }; + + if (data.db_name) { + req.db_name = data.db_name; + } + + const promise = await promisify( + this.channelPool, + 'AlterCollectionField', + req, + data?.timeout || this.timeout + ); + + return promise; + } + // alias list_collections = this.showCollections; // alias diff --git a/milvus/types/Collection.ts b/milvus/types/Collection.ts index f5b11ac9..06a64daa 100644 --- a/milvus/types/Collection.ts +++ b/milvus/types/Collection.ts @@ -45,7 +45,8 @@ export type TypeParamKey = | 'max_capacity' | 'analyzer_params' | 'enable_analyzer' - | 'enable_match'; + | 'enable_match' + | 'mmap.enabled'; // returned from milvus export type FieldSchema = { @@ -268,6 +269,11 @@ export interface AlterCollectionReq extends collectionNameReq { delete_keys?: string[]; // optional, deleted properties, strings array } +export interface AlterCollectionFieldPropertiesReq extends collectionNameReq { + field_name: string; // required, field name + properties: Properties; // required, properties +} + export interface DropCollectionPropertiesReq extends collectionNameReq { properties: string[]; // required, deleted properties, strings array } diff --git a/milvus/utils/Format.ts b/milvus/utils/Format.ts index 5dbfc096..4a0c77e9 100644 --- a/milvus/utils/Format.ts +++ b/milvus/utils/Format.ts @@ -208,6 +208,7 @@ export const assignTypeParams = ( 'enable_match', 'enable_analyzer', 'analyzer_params', + 'mmap.enabled', ] ): FieldType => { const newField = cloneObj(field); diff --git a/test/grpc/Collection.spec.ts b/test/grpc/Collection.spec.ts index 0d3be8fe..9a46bcc7 100644 --- a/test/grpc/Collection.spec.ts +++ b/test/grpc/Collection.spec.ts @@ -15,7 +15,7 @@ import { } from '../tools'; import { timeoutTest } from '../tools'; -const milvusClient = new MilvusClient({ address: IP }); +const milvusClient = new MilvusClient({ address: IP, logLevel: 'info' }); const COLLECTION_NAME = GENERATE_NAME(); const NUMBER_DIM_COLLECTION_NAME = GENERATE_NAME(); const NEW_COLLECTION_NAME = GENERATE_NAME(); @@ -436,6 +436,49 @@ describe(`Collection API`, () => { ).toEqual(value2); }); + it(`Alter collection field properties should success`, async () => { + const key = 'mmap.enabled'; + const value = true; + + const alter = await milvusClient.alterCollectionFieldProperties({ + collection_name: LOAD_COLLECTION_NAME, + field_name: 'json', + properties: { [key]: value }, + db_name: 'Collection', // pass test case + }); + + expect(alter.error_code).toEqual(ErrorCode.SUCCESS); + + const describe = await milvusClient.describeCollection({ + collection_name: LOAD_COLLECTION_NAME, + }); + + // find json field + const jsonField = describe.schema.fields.find( + f => f.name === 'json' + ) as any; + expect(jsonField['mmap.enabled']).toEqual('true'); + + const alter2 = await milvusClient.alterCollectionFieldProperties({ + collection_name: LOAD_COLLECTION_NAME, + field_name: 'varChar', + properties: { max_length: 1024 }, + db_name: 'Collection', // pass test case + }); + expect(alter2.error_code).toEqual(ErrorCode.SUCCESS); + + const describe2 = await milvusClient.describeCollection({ + collection_name: LOAD_COLLECTION_NAME, + }); + + // find varChar field + const varCharField = describe2.schema.fields.find( + f => f.name === 'varChar' + ) as any; + + expect(varCharField['max_length']).toEqual('1024'); + }); + it(`Load Collection Sync throw COLLECTION_NAME_IS_REQUIRED`, async () => { try { await milvusClient.loadCollectionSync({} as any); diff --git a/test/utils/Format.spec.ts b/test/utils/Format.spec.ts index 8010a087..23395b8f 100644 --- a/test/utils/Format.spec.ts +++ b/test/utils/Format.spec.ts @@ -191,6 +191,7 @@ describe('utils/format', () => { enable_match: true, analyzer_params: { key: 'value' }, enable_analyzer: true, + 'mmap.enabled': true, } as FieldType; const expectedOutput = { name: 'vector', @@ -201,6 +202,7 @@ describe('utils/format', () => { enable_match: 'true', analyzer_params: JSON.stringify({ key: 'value' }), enable_analyzer: 'true', + 'mmap.enabled': 'true', }, }; expect(assignTypeParams(field)).toEqual(expectedOutput);