@@ -76,6 +76,24 @@ class GenerateManager<T> implements Generate<T> {
7676 if ( ! check . supports ) throw new WeaviateUnsupportedFeatureError ( check . message ( query ) ) ;
7777 } ;
7878
79+ private checkSupportForMultiTargetVectorSearch = async ( opts ?: BaseNearOptions < T > ) => {
80+ if ( ! Serialize . isMultiTargetVector ( opts ) ) return false ;
81+ const check = await this . dbVersionSupport . supportsMultiTargetVectorSearch ( ) ;
82+ if ( ! check . supports ) throw new WeaviateUnsupportedFeatureError ( check . message ) ;
83+ return check . supports ;
84+ } ;
85+
86+ private nearSearch = async ( opts ?: BaseNearOptions < T > ) => {
87+ const [ _ , supportsTargets ] = await Promise . all ( [
88+ this . checkSupportForNamedVectors ( opts ) ,
89+ this . checkSupportForMultiTargetVectorSearch ( opts ) ,
90+ ] ) ;
91+ return {
92+ search : await this . connection . search ( this . name , this . consistencyLevel , this . tenant ) ,
93+ supportsTargets,
94+ } ;
95+ } ;
96+
7997 private async parseReply ( reply : SearchReply ) {
8098 const deserialize = await Deserialize . use ( this . dbVersionSupport ) ;
8199 return deserialize . generate < T > ( reply ) ;
@@ -150,7 +168,7 @@ class GenerateManager<T> implements Generate<T> {
150168 . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
151169 . then ( ( search ) =>
152170 search . withHybrid ( {
153- ...Serialize . hybrid ( { query, ...opts } ) ,
171+ ...Serialize . hybrid ( { query, supportsTargets : false , ...opts } ) ,
154172 generative : Serialize . generative ( generate ) ,
155173 groupBy : Serialize . isGroupBy < GroupByHybridOptions < T > > ( opts )
156174 ? Serialize . groupBy ( opts . groupBy )
@@ -175,12 +193,11 @@ class GenerateManager<T> implements Generate<T> {
175193 generate : GenerateOptions < T > ,
176194 opts ?: NearOptions < T >
177195 ) : GenerateReturn < T > {
178- return this . checkSupportForNamedVectors ( opts )
179- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
180- . then ( ( search ) =>
196+ return this . nearSearch ( opts )
197+ . then ( ( { search, supportsTargets } ) =>
181198 toBase64FromMedia ( image ) . then ( ( image ) =>
182199 search . withNearImage ( {
183- ...Serialize . nearImage ( { image, ...( opts ? opts : { } ) } ) ,
200+ ...Serialize . nearImage ( { image, supportsTargets , ...( opts ? opts : { } ) } ) ,
184201 generative : Serialize . generative ( generate ) ,
185202 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
186203 ? Serialize . groupBy ( opts . groupBy )
@@ -202,11 +219,10 @@ class GenerateManager<T> implements Generate<T> {
202219 opts : GroupByNearOptions < T >
203220 ) : Promise < GenerativeGroupByReturn < T > > ;
204221 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 ) =>
222+ return this . nearSearch ( opts )
223+ . then ( ( { search, supportsTargets } ) =>
208224 search . withNearObject ( {
209- ...Serialize . nearObject ( { id, ...( opts ? opts : { } ) } ) ,
225+ ...Serialize . nearObject ( { id, supportsTargets , ...( opts ? opts : { } ) } ) ,
210226 generative : Serialize . generative ( generate ) ,
211227 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
212228 ? Serialize . groupBy ( opts . groupBy )
@@ -231,11 +247,10 @@ class GenerateManager<T> implements Generate<T> {
231247 generate : GenerateOptions < T > ,
232248 opts ?: NearOptions < T >
233249 ) : GenerateReturn < T > {
234- return this . checkSupportForNamedVectors ( opts )
235- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
236- . then ( ( search ) =>
250+ return this . nearSearch ( opts )
251+ . then ( ( { search, supportsTargets } ) =>
237252 search . withNearText ( {
238- ...Serialize . nearText ( { query, ...( opts ? opts : { } ) } ) ,
253+ ...Serialize . nearText ( { query, supportsTargets , ...( opts ? opts : { } ) } ) ,
239254 generative : Serialize . generative ( generate ) ,
240255 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
241256 ? Serialize . groupBy ( opts . groupBy )
@@ -260,11 +275,10 @@ class GenerateManager<T> implements Generate<T> {
260275 generate : GenerateOptions < T > ,
261276 opts ?: NearOptions < T >
262277 ) : GenerateReturn < T > {
263- return this . checkSupportForNamedVectors ( opts )
264- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
265- . then ( ( search ) =>
278+ return this . nearSearch ( opts )
279+ . then ( ( { search, supportsTargets } ) =>
266280 search . withNearVector ( {
267- ...Serialize . nearVector ( { vector, ...( opts ? opts : { } ) } ) ,
281+ ...Serialize . nearVector ( { vector, supportsTargets , ...( opts ? opts : { } ) } ) ,
268282 generative : Serialize . generative ( generate ) ,
269283 groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
270284 ? Serialize . groupBy ( opts . groupBy )
@@ -292,10 +306,10 @@ class GenerateManager<T> implements Generate<T> {
292306 generate : GenerateOptions < T > ,
293307 opts ?: NearOptions < T >
294308 ) : GenerateReturn < T > {
295- return this . checkSupportForNamedVectors ( opts )
296- . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
297- . then ( ( search ) => {
309+ return this . nearSearch ( opts )
310+ . then ( ( { search, supportsTargets } ) => {
298311 let reply : Promise < SearchReply > ;
312+ const args = { supportsTargets, ...( opts ? opts : { } ) } ;
299313 const generative = Serialize . generative ( generate ) ;
300314 const groupBy = Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
301315 ? Serialize . groupBy ( opts . groupBy )
@@ -304,7 +318,7 @@ class GenerateManager<T> implements Generate<T> {
304318 case 'audio' :
305319 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
306320 search . withNearAudio ( {
307- ...Serialize . nearAudio ( { audio : media , ...( opts ? opts : { } ) } ) ,
321+ ...Serialize . nearAudio ( { audio : media , ...args } ) ,
308322 generative,
309323 groupBy,
310324 } )
@@ -313,7 +327,7 @@ class GenerateManager<T> implements Generate<T> {
313327 case 'depth' :
314328 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
315329 search . withNearDepth ( {
316- ...Serialize . nearDepth ( { depth : media , ...( opts ? opts : { } ) } ) ,
330+ ...Serialize . nearDepth ( { depth : media , ...args } ) ,
317331 generative,
318332 groupBy,
319333 } )
@@ -322,7 +336,7 @@ class GenerateManager<T> implements Generate<T> {
322336 case 'image' :
323337 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
324338 search . withNearImage ( {
325- ...Serialize . nearImage ( { image : media , ...( opts ? opts : { } ) } ) ,
339+ ...Serialize . nearImage ( { image : media , ...args } ) ,
326340 generative,
327341 groupBy,
328342 } )
@@ -331,7 +345,7 @@ class GenerateManager<T> implements Generate<T> {
331345 case 'imu' :
332346 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
333347 search . withNearIMU ( {
334- ...Serialize . nearIMU ( { imu : media , ...( opts ? opts : { } ) } ) ,
348+ ...Serialize . nearIMU ( { imu : media , ...args } ) ,
335349 generative,
336350 groupBy,
337351 } )
@@ -340,7 +354,7 @@ class GenerateManager<T> implements Generate<T> {
340354 case 'thermal' :
341355 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
342356 search . withNearThermal ( {
343- ...Serialize . nearThermal ( { thermal : media , ...( opts ? opts : { } ) } ) ,
357+ ...Serialize . nearThermal ( { thermal : media , ...args } ) ,
344358 generative,
345359 groupBy,
346360 } )
@@ -349,7 +363,7 @@ class GenerateManager<T> implements Generate<T> {
349363 case 'video' :
350364 reply = toBase64FromMedia ( media ) . then ( ( media ) =>
351365 search . withNearVideo ( {
352- ...Serialize . nearVideo ( { video : media , ...( opts ? opts : { } ) } ) ,
366+ ...Serialize . nearVideo ( { video : media , ...args } ) ,
353367 generative,
354368 groupBy,
355369 } )
0 commit comments