diff --git a/milvus/const/error.ts b/milvus/const/error.ts index e8a95fc7..a33eedbf 100644 --- a/milvus/const/error.ts +++ b/milvus/const/error.ts @@ -70,4 +70,5 @@ export enum ErrorCode { UpsertAutoIDTrue = 'UpsertAutoIDTrue', CollectionNotExists = 'CollectionNotExists', IllegalArgument = 'IllegalArgument', + RateLimit = 'RateLimit', } diff --git a/milvus/http/Vector.ts b/milvus/http/Vector.ts index 1de986f7..8b8d394c 100644 --- a/milvus/http/Vector.ts +++ b/milvus/http/Vector.ts @@ -12,6 +12,7 @@ import { HttpBaseResponse, FetchOptions, HttpVectorUpsertResponse, + HttpVectorHybridSearchReq, } from '../types'; /** @@ -79,6 +80,14 @@ export function Vector>(Base: T) { return await this.POST(url, data, options); } + async hybridSearch( + data: HttpVectorHybridSearchReq, + options?: FetchOptions + ) { + const url = `${this.vectorPrefix}/hybrid_search`; + return await this.POST(url, data, options); + } + // POST delete collection async delete( data: HttpVectorDeleteReq, diff --git a/milvus/types/Http.ts b/milvus/types/Http.ts index f5037d11..74ed40b5 100644 --- a/milvus/types/Http.ts +++ b/milvus/types/Http.ts @@ -211,6 +211,27 @@ export interface HttpVectorSearchReq extends HttpVectorQueryReq { searchParams?: Record; } +// hybrid search request +interface HttpVectorHybridSearchParams { + data: FloatVector[]; + limit: number; + filter?: string; + outputFields?: string[]; + offset?: number; + annsField?: string; + ignoreGrowing?: boolean; + metricType?: string; + params?: Record; +} + +export interface HttpVectorHybridSearchReq extends HttpBaseReq { + search: HttpVectorHybridSearchParams[]; + rerank: Record; + partitionNames?: string[]; + outputFields?: string[]; + limit?: number; +} + export interface HttpVectorSearchResponse extends HttpVectorQueryResponse { data: QueryResult & { distance: number | string }; } diff --git a/package.json b/package.json index f27542e7..c63b805d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@zilliz/milvus2-sdk-node", "author": "ued@zilliz.com", "version": "2.4.4", - "milvusVersion": "v2.4.4", + "milvusVersion": "v2.4.6", "main": "dist/milvus", "files": [ "dist" diff --git a/test/grpc/Data.spec.ts b/test/grpc/Data.spec.ts index 701d6919..ef264cf7 100644 --- a/test/grpc/Data.spec.ts +++ b/test/grpc/Data.spec.ts @@ -144,7 +144,11 @@ describe(`Data.API`, () => { const res = await milvusClient.flush({ collection_names: [COLLECTION_NAME], }); - const segIDs = res.coll_segIDs[COLLECTION_NAME].data; + if (res.status.error_code === ErrorCode.RateLimit) { + expect(res.coll_segIDs[COLLECTION_NAME]).toBeUndefined(); + return; + } + const segIDs = res.coll_segIDs[COLLECTION_NAME]?.data; await milvusClient.getFlushState({ segmentIDs: segIDs, }); diff --git a/test/http/test.ts b/test/http/test.ts index 5661cdd9..9bca26b1 100644 --- a/test/http/test.ts +++ b/test/http/test.ts @@ -197,6 +197,30 @@ export function generateTests( expect(upsert.data.upsertIds).toEqual([target.id]); }); + it('should hybrid search data successfully', async () => { + const search = await client.hybridSearch({ + collectionName: createParams.collectionName, + outputFields: ['*'], + rerank: { + strategy: 'rrf', + params: { + k: 5, + }, + }, + search: [ + { + data: [[1, 2, 3, 4]], + outputFields: ['*'], + limit: 5, + }, + ], + }); + + expect(search.code).toEqual(0); + expect(search.data.length).toEqual(5); + expect(typeof search.data[0].distance).toEqual('number'); + }); + it('should query data and get data and delete successfully', async () => { const query = await client.query({ collectionName: createParams.collectionName,