diff --git a/milvus/Data.ts b/milvus/Data.ts index b568ab29..c5a347f1 100644 --- a/milvus/Data.ts +++ b/milvus/Data.ts @@ -335,6 +335,16 @@ export class Data extends Client { throw new Error(ERROR_REASONS.SEARCH_DIM_NOT_MATCH); } + const round_decimal = data.search_params.round_decimal; + if ( + round_decimal !== undefined && + (!Number.isInteger(round_decimal) || + round_decimal < -1 || + round_decimal > 6) + ) { + throw new Error(ERROR_REASONS.SEARCH_ROUND_DECIMAL_NOT_VALID); + } + // when data type is bytes , we need use protobufjs to transform data to buffer bytes. const PlaceholderGroup = root.lookupType( 'milvus.proto.common.PlaceholderGroup' @@ -377,7 +387,6 @@ export class Data extends Client { * And if Milvus return like 3.142, Node will add more number after this like 3.142000047683716. * So the score need to slice by round_decimal */ - const round_decimal = data.search_params.round_decimal; if (promise.results) { /** * fields_data: what you pass in output_fields, only support non vector fields. diff --git a/milvus/const/ErrorReason.ts b/milvus/const/ErrorReason.ts index 0cb04ef0..d52758aa 100644 --- a/milvus/const/ErrorReason.ts +++ b/milvus/const/ErrorReason.ts @@ -20,6 +20,7 @@ export enum ERROR_REASONS { SEARCH_NOT_FIND_VECTOR_FIELD = 'Your anns_field cannot find in this collection.', SEARCH_DIM_NOT_MATCH = 'Your vector dimension is not match your anns_field dimension', SEARCH_PARAMS_IS_REQUIRED = 'search_params must contains anns_field, metric_type, topk and params.', + SEARCH_ROUND_DECIMAL_NOT_VALID = 'round_decimal should be an integer greater than -2 and less than 7', DELETE_PARAMS_CHECK = 'Collection name and expr is required.', diff --git a/test/Data.spec.ts b/test/Data.spec.ts index 518f5d47..b7ff341c 100644 --- a/test/Data.spec.ts +++ b/test/Data.spec.ts @@ -202,6 +202,27 @@ describe('Data.ts Test', () => { } }); + it('Expr Search should throw SEARCH_ROUND_DECIMAL_NOT_VALID', async () => { + try { + await milvusClient.dataManager.search({ + collection_name: COLLECTION_NAME, + expr: '', + vectors: [[1, 2, 3, 4]], + search_params: { + anns_field: VECTOR_FIELD_NAME, + topk: '4', + metric_type: 'L2', + params: JSON.stringify({ nprobe: 1024 }), + round_decimal: 7, + }, + output_fields: ['age'], + vector_type: DataType.FloatVector, + }); + } catch (err) { + expect(err.message).toEqual(ERROR_REASONS.SEARCH_ROUND_DECIMAL_NOT_VALID); + } + }); + it('Query ', async () => { await milvusClient.dataManager.deleteEntities({ collection_name: COLLECTION_NAME,