@@ -4,6 +4,7 @@ import { ConsistencyLevel } from '../../data/index.js';
44import { DbVersionSupport } from '../../utils/dbVersion.js' ;
55
66import { WeaviateInvalidInputError , WeaviateUnsupportedFeatureError } from '../../errors.js' ;
7+ import { toBase64FromMedia } from '../../index.js' ;
78import { SearchReply } from '../../proto/v1/search_get.js' ;
89import { Deserialize } from '../deserialize/index.js' ;
910import {
@@ -160,26 +161,32 @@ class GenerateManager<T> implements Generate<T> {
160161 }
161162
162163 public nearImage (
163- image : string ,
164+ image : string | Buffer ,
164165 generate : GenerateOptions < T > ,
165166 opts ?: BaseNearOptions < T >
166167 ) : Promise < GenerativeReturn < T > > ;
167168 public nearImage (
168- image : string ,
169+ image : string | Buffer ,
169170 generate : GenerateOptions < T > ,
170171 opts : GroupByNearOptions < T >
171172 ) : Promise < GenerativeGroupByReturn < T > > ;
172- public nearImage ( image : string , generate : GenerateOptions < T > , opts ?: NearOptions < T > ) : GenerateReturn < T > {
173+ public nearImage (
174+ image : string | Buffer ,
175+ generate : GenerateOptions < T > ,
176+ opts ?: NearOptions < T >
177+ ) : GenerateReturn < T > {
173178 return this . checkSupportForNamedVectors ( opts )
174179 . then ( ( ) => this . connection . search ( this . name , this . consistencyLevel , this . tenant ) )
175180 . then ( ( search ) =>
176- search . withNearImage ( {
177- ...Serialize . nearImage ( { image, ...( opts ? opts : { } ) } ) ,
178- generative : Serialize . generative ( generate ) ,
179- groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
180- ? Serialize . groupBy ( opts . groupBy )
181- : undefined ,
182- } )
181+ toBase64FromMedia ( image ) . then ( ( image ) =>
182+ search . withNearImage ( {
183+ ...Serialize . nearImage ( { image, ...( opts ? opts : { } ) } ) ,
184+ generative : Serialize . generative ( generate ) ,
185+ groupBy : Serialize . isGroupBy < GroupByNearOptions < T > > ( opts )
186+ ? Serialize . groupBy ( opts . groupBy )
187+ : undefined ,
188+ } )
189+ )
183190 )
184191 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
185192 }
@@ -268,19 +275,19 @@ class GenerateManager<T> implements Generate<T> {
268275 }
269276
270277 public nearMedia (
271- media : string ,
278+ media : string | Buffer ,
272279 type : NearMediaType ,
273280 generate : GenerateOptions < T > ,
274281 opts ?: BaseNearOptions < T >
275282 ) : Promise < GenerativeReturn < T > > ;
276283 public nearMedia (
277- media : string ,
284+ media : string | Buffer ,
278285 type : NearMediaType ,
279286 generate : GenerateOptions < T > ,
280287 opts : GroupByNearOptions < T >
281288 ) : Promise < GenerativeGroupByReturn < T > > ;
282289 public nearMedia (
283- media : string ,
290+ media : string | Buffer ,
284291 type : NearMediaType ,
285292 generate : GenerateOptions < T > ,
286293 opts ?: NearOptions < T >
@@ -295,46 +302,58 @@ class GenerateManager<T> implements Generate<T> {
295302 : undefined ;
296303 switch ( type ) {
297304 case 'audio' :
298- reply = search . withNearAudio ( {
299- ...Serialize . nearAudio ( { audio : media , ...( opts ? opts : { } ) } ) ,
300- generative,
301- groupBy,
302- } ) ;
305+ reply = toBase64FromMedia ( media ) . then ( ( media ) =>
306+ search . withNearAudio ( {
307+ ...Serialize . nearAudio ( { audio : media , ...( opts ? opts : { } ) } ) ,
308+ generative,
309+ groupBy,
310+ } )
311+ ) ;
303312 break ;
304313 case 'depth' :
305- reply = search . withNearDepth ( {
306- ...Serialize . nearDepth ( { depth : media , ...( opts ? opts : { } ) } ) ,
307- generative,
308- groupBy,
309- } ) ;
314+ reply = toBase64FromMedia ( media ) . then ( ( media ) =>
315+ search . withNearDepth ( {
316+ ...Serialize . nearDepth ( { depth : media , ...( opts ? opts : { } ) } ) ,
317+ generative,
318+ groupBy,
319+ } )
320+ ) ;
310321 break ;
311322 case 'image' :
312- reply = search . withNearImage ( {
313- ...Serialize . nearImage ( { image : media , ...( opts ? opts : { } ) } ) ,
314- generative,
315- groupBy,
316- } ) ;
323+ reply = toBase64FromMedia ( media ) . then ( ( media ) =>
324+ search . withNearImage ( {
325+ ...Serialize . nearImage ( { image : media , ...( opts ? opts : { } ) } ) ,
326+ generative,
327+ groupBy,
328+ } )
329+ ) ;
317330 break ;
318331 case 'imu' :
319- reply = search . withNearIMU ( {
320- ...Serialize . nearIMU ( { imu : media , ...( opts ? opts : { } ) } ) ,
321- generative,
322- groupBy,
323- } ) ;
332+ reply = toBase64FromMedia ( media ) . then ( ( media ) =>
333+ search . withNearIMU ( {
334+ ...Serialize . nearIMU ( { imu : media , ...( opts ? opts : { } ) } ) ,
335+ generative,
336+ groupBy,
337+ } )
338+ ) ;
324339 break ;
325340 case 'thermal' :
326- reply = search . withNearThermal ( {
327- ...Serialize . nearThermal ( { thermal : media , ...( opts ? opts : { } ) } ) ,
328- generative,
329- groupBy,
330- } ) ;
341+ reply = toBase64FromMedia ( media ) . then ( ( media ) =>
342+ search . withNearThermal ( {
343+ ...Serialize . nearThermal ( { thermal : media , ...( opts ? opts : { } ) } ) ,
344+ generative,
345+ groupBy,
346+ } )
347+ ) ;
331348 break ;
332349 case 'video' :
333- reply = search . withNearVideo ( {
334- ...Serialize . nearVideo ( { video : media , ...( opts ? opts : { } ) } ) ,
335- generative,
336- groupBy,
337- } ) ;
350+ reply = toBase64FromMedia ( media ) . then ( ( media ) =>
351+ search . withNearVideo ( {
352+ ...Serialize . nearVideo ( { video : media , ...( opts ? opts : { } ) } ) ,
353+ generative,
354+ groupBy,
355+ } )
356+ ) ;
338357 break ;
339358 default :
340359 throw new WeaviateInvalidInputError ( `Invalid media type: ${ type } ` ) ;
0 commit comments