@@ -76,6 +76,43 @@ class GenerateManager<T> implements Generate<T> {
7676 if ( ! check . supports ) throw new WeaviateUnsupportedFeatureError ( check . message ( query ) ) ;
7777 } ;
7878
79+ private checkSupportForHybridNearTextAndNearVectorSubSearches = async ( opts ?: HybridOptions < T > ) => {
80+ if ( opts ?. vector === undefined || Array . isArray ( opts . vector ) ) return ;
81+ const check = await this . dbVersionSupport . supportsHybridNearTextAndNearVectorSubsearchQueries ( ) ;
82+ if ( ! check . supports ) throw new WeaviateUnsupportedFeatureError ( check . message ) ;
83+ } ;
84+
85+ private checkSupportForMultiTargetVectorSearch = async ( opts ?: BaseNearOptions < T > ) => {
86+ if ( ! Serialize . isMultiTargetVector ( opts ) ) return false ;
87+ const check = await this . dbVersionSupport . supportsMultiTargetVectorSearch ( ) ;
88+ if ( ! check . supports ) throw new WeaviateUnsupportedFeatureError ( check . message ) ;
89+ return check . supports ;
90+ } ;
91+
92+ private nearSearch = async ( opts ?: BaseNearOptions < T > ) => {
93+ const [ _ , supportsTargets ] = await Promise . all ( [
94+ this . checkSupportForNamedVectors ( opts ) ,
95+ this . checkSupportForMultiTargetVectorSearch ( opts ) ,
96+ ] ) ;
97+ return {
98+ search : await this . connection . search ( this . name , this . consistencyLevel , this . tenant ) ,
99+ supportsTargets,
100+ } ;
101+ } ;
102+
103+ private hybridSearch = async ( opts ?: BaseHybridOptions < T > ) => {
104+ const [ supportsTargets ] = await Promise . all ( [
105+ this . checkSupportForMultiTargetVectorSearch ( opts ) ,
106+ this . checkSupportForNamedVectors ( opts ) ,
107+ this . checkSupportForBm25AndHybridGroupByQueries ( 'Hybrid' , opts ) ,
108+ this . checkSupportForHybridNearTextAndNearVectorSubSearches ( opts ) ,
109+ ] ) ;
110+ return {
111+ search : await this . connection . search ( this . name , this . consistencyLevel , this . tenant ) ,
112+ supportsTargets,
113+ } ;
114+ } ;
115+
79116 private async parseReply ( reply : SearchReply ) {
80117 const deserialize = await Deserialize . use ( this . dbVersionSupport ) ;
81118 return deserialize . generate < T > ( reply ) ;
@@ -143,14 +180,10 @@ class GenerateManager<T> implements Generate<T> {
143180 opts : GroupByHybridOptions < T >
144181 ) : Promise < GenerativeGroupByReturn < T > > ;
145182 public hybrid ( query : string , generate : GenerateOptions < T > , opts ?: HybridOptions < T > ) : GenerateReturn < T > {
146- return Promise . all ( [
147- this . checkSupportForNamedVectors ( opts ) ,
148- this . checkSupportForBm25AndHybridGroupByQueries ( 'Bm25' , opts ) ,
149- ] )
150- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
151- . then ( ( search ) =>
183+ return this . hybridSearch ( opts )
184+ . then ( ( { search, supportsTargets } ) =>
152185 search . withHybrid ( {
153- ...Serialize . hybrid ( { query, ...opts } ) ,
186+ ...Serialize . hybrid ( { query, supportsTargets , ...opts } ) ,
154187 generative : Serialize . generative ( generate ) ,
155188 groupBy : Serialize . isGroupBy < GroupByHybridOptions < T > > ( opts )
156189 ? Serialize . groupBy ( opts . groupBy )
@@ -175,12 +208,11 @@ class GenerateManager<T> implements Generate<T> {
175208 generate : GenerateOptions < T > ,
176209 opts ?: NearOptions < T >
177210 ) : GenerateReturn < T > {
178- return this . checkSupportForNamedVectors ( opts )
179- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
180- . then ( ( search ) =>
211+ return this . nearSearch ( opts )
212+ . then ( ( { search, supportsTargets } ) =>
181213 toBase64FromMedia ( image ) . then ( ( image ) =>
182214 search . withNearImage ( {
183- ...Serialize . nearImage ( { image, ...( opts ? opts : { } ) } ) ,
215+ ...Serialize . nearImage ( { image, supportsTargets , ...( opts ? opts : { } ) } ) ,
184216 generative : Serialize . generative ( generate ) ,
185217 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
186218 ? Serialize . groupBy ( opts . groupBy )
@@ -202,11 +234,10 @@ class GenerateManager<T> implements Generate<T> {
202234 opts : GroupByNearOptions < T >
203235 ) : Promise < GenerativeGroupByReturn < T > > ;
204236 public nearObject ( id : string , generate : GenerateOptions < T > , opts ?: NearOptions < T > ) : GenerateReturn < T > {
205- return this . checkSupportForNamedVectors ( opts )
206- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
207- . then ( ( search ) =>
237+ return this . nearSearch ( opts )
238+ . then ( ( { search, supportsTargets } ) =>
208239 search . withNearObject ( {
209- ...Serialize . nearObject ( { id, ...( opts ? opts : { } ) } ) ,
240+ ...Serialize . nearObject ( { id, supportsTargets , ...( opts ? opts : { } ) } ) ,
210241 generative : Serialize . generative ( generate ) ,
211242 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
212243 ? Serialize . groupBy ( opts . groupBy )
@@ -231,11 +262,10 @@ class GenerateManager<T> implements Generate<T> {
231262 generate : GenerateOptions < T > ,
232263 opts ?: NearOptions < T >
233264 ) : GenerateReturn < T > {
234- return this . checkSupportForNamedVectors ( opts )
235- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
236- . then ( ( search ) =>
265+ return this . nearSearch ( opts )
266+ . then ( ( { search, supportsTargets } ) =>
237267 search . withNearText ( {
238- ...Serialize . nearText ( { query, ...( opts ? opts : { } ) } ) ,
268+ ...Serialize . nearText ( { query, supportsTargets , ...( opts ? opts : { } ) } ) ,
239269 generative : Serialize . generative ( generate ) ,
240270 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
241271 ? Serialize . groupBy ( opts . groupBy )
@@ -260,11 +290,10 @@ class GenerateManager<T> implements Generate<T> {
260290 generate : GenerateOptions < T > ,
261291 opts ?: NearOptions < T >
262292 ) : GenerateReturn < T > {
263- return this . checkSupportForNamedVectors ( opts )
264- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
265- . then ( ( search ) =>
293+ return this . nearSearch ( opts )
294+ . then ( ( { search, supportsTargets } ) =>
266295 search . withNearVector ( {
267- ...Serialize . nearVector ( { vector, ...( opts ? opts : { } ) } ) ,
296+ ...Serialize . nearVector ( { vector, supportsTargets , ...( opts ? opts : { } ) } ) ,
268297 generative : Serialize . generative ( generate ) ,
269298 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
270299 ? Serialize . groupBy ( opts . groupBy )
@@ -292,10 +321,10 @@ class GenerateManager<T> implements Generate<T> {
292321 generate : GenerateOptions < T > ,
293322 opts ?: NearOptions < T >
294323 ) : GenerateReturn < T > {
295- return this . checkSupportForNamedVectors ( opts )
296- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
297- . then ( ( search ) => {
324+ return this . nearSearch ( opts )
325+ . then ( ( { search, supportsTargets } ) => {
298326 let reply : Promise < SearchReply > ;
327+ const args = { supportsTargets, ...( opts ? opts : { } ) } ;
299328 const generative = Serialize . generative ( generate ) ;
300329 const groupBy = Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
301330 ? Serialize . groupBy ( opts . groupBy )
@@ -304,7 +333,7 @@ class GenerateManager<T> implements Generate<T> {
304333 case 'audio' :
305334 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
306335 search . withNearAudio ( {
307- ...Serialize . nearAudio ( { audio : media , ...( opts ? opts : { } ) } ) ,
336+ ...Serialize . nearAudio ( { audio : media , ...args } ) ,
308337 generative,
309338 groupBy,
310339 } )
@@ -313,7 +342,7 @@ class GenerateManager<T> implements Generate<T> {
313342 case 'depth' :
314343 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
315344 search . withNearDepth ( {
316- ...Serialize . nearDepth ( { depth : media , ...( opts ? opts : { } ) } ) ,
345+ ...Serialize . nearDepth ( { depth : media , ...args } ) ,
317346 generative,
318347 groupBy,
319348 } )
@@ -322,7 +351,7 @@ class GenerateManager<T> implements Generate<T> {
322351 case 'image' :
323352 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
324353 search . withNearImage ( {
325- ...Serialize . nearImage ( { image : media , ...( opts ? opts : { } ) } ) ,
354+ ...Serialize . nearImage ( { image : media , ...args } ) ,
326355 generative,
327356 groupBy,
328357 } )
@@ -331,7 +360,7 @@ class GenerateManager<T> implements Generate<T> {
331360 case 'imu' :
332361 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
333362 search . withNearIMU ( {
334- ...Serialize . nearIMU ( { imu : media , ...( opts ? opts : { } ) } ) ,
363+ ...Serialize . nearIMU ( { imu : media , ...args } ) ,
335364 generative,
336365 groupBy,
337366 } )
@@ -340,7 +369,7 @@ class GenerateManager<T> implements Generate<T> {
340369 case 'thermal' :
341370 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
342371 search . withNearThermal ( {
343- ...Serialize . nearThermal ( { thermal : media , ...( opts ? opts : { } ) } ) ,
372+ ...Serialize . nearThermal ( { thermal : media , ...args } ) ,
344373 generative,
345374 groupBy,
346375 } )
@@ -349,7 +378,7 @@ class GenerateManager<T> implements Generate<T> {
349378 case 'video' :
350379 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
351380 search . withNearVideo ( {
352- ...Serialize . nearVideo ( { video : media , ...( opts ? opts : { } ) } ) ,
381+ ...Serialize . nearVideo ( { video : media , ...args } ) ,
353382 generative,
354383 groupBy,
355384 } )
0 commit comments