@@ -330,13 +330,19 @@ export type AggregateResult<T, M extends PropertiesMetrics<T> | undefined = unde
330330 totalCount : number ;
331331} ;
332332
333+ export type AggregatedGeoCoordinate = {
334+ latitude : number ;
335+ longitude : number ;
336+ distance : number ;
337+ } ;
338+
333339export type AggregateGroupByResult <
334340 T ,
335341 M extends PropertiesMetrics < T > | undefined = undefined
336342> = AggregateResult < T , M > & {
337343 groupedBy : {
338344 prop : string ;
339- value : string ;
345+ value : string | number | boolean | AggregatedGeoCoordinate | string [ ] | number [ ] | boolean [ ] ;
340346 } ;
341347} ;
342348
@@ -365,10 +371,22 @@ class AggregateManager<T> implements Aggregate<T> {
365371 this . grpcChecker = this . dbVersionSupport . supportsAggregateGRPC ( ) . then ( ( res ) => res . supports ) ;
366372
367373 this . groupBy = {
368- hybrid : < M extends PropertiesMetrics < T > | undefined = undefined > (
374+ hybrid : async < M extends PropertiesMetrics < T > > (
369375 query : string ,
370376 opts : AggregateGroupByHybridOptions < T , M >
371377 ) : Promise < AggregateGroupByResult < T , M > [ ] > => {
378+ if ( await this . grpcChecker ) {
379+ const group = typeof opts . groupBy === 'string' ? { property : opts . groupBy } : opts . groupBy ;
380+ return this . grpc ( )
381+ . then ( ( aggregate ) =>
382+ aggregate . withHybrid ( {
383+ ...Serialize . aggregate . hybrid ( query , opts ) ,
384+ groupBy : Serialize . aggregate . groupBy ( group ) ,
385+ limit : group . limit ,
386+ } )
387+ )
388+ . then ( ( reply ) => Deserialize . aggregateGroupBy ( reply ) ) ;
389+ }
372390 let builder = this . base ( opts ?. returnMetrics , opts ?. filters , opts ?. groupBy ) . withHybrid ( {
373391 query : query ,
374392 alpha : opts ?. alpha ,
@@ -382,12 +400,25 @@ class AggregateManager<T> implements Aggregate<T> {
382400 }
383401 return this . doGroupBy ( builder ) ;
384402 } ,
385- nearImage : async < M extends PropertiesMetrics < T > | undefined = undefined > (
403+ nearImage : async < M extends PropertiesMetrics < T > > (
386404 image : string | Buffer ,
387405 opts : AggregateGroupByNearOptions < T , M >
388406 ) : Promise < AggregateGroupByResult < T , M > [ ] > => {
407+ const [ b64 , usesGrpc ] = await Promise . all ( [ await toBase64FromMedia ( image ) , await this . grpcChecker ] ) ;
408+ if ( usesGrpc ) {
409+ const group = typeof opts . groupBy === 'string' ? { property : opts . groupBy } : opts . groupBy ;
410+ return this . grpc ( )
411+ . then ( ( aggregate ) =>
412+ aggregate . withNearImage ( {
413+ ...Serialize . aggregate . nearImage ( b64 , opts ) ,
414+ groupBy : Serialize . aggregate . groupBy ( group ) ,
415+ limit : group . limit ,
416+ } )
417+ )
418+ . then ( ( reply ) => Deserialize . aggregateGroupBy ( reply ) ) ;
419+ }
389420 const builder = this . base ( opts ?. returnMetrics , opts ?. filters , opts ?. groupBy ) . withNearImage ( {
390- image : await toBase64FromMedia ( image ) ,
421+ image : b64 ,
391422 certainty : opts ?. certainty ,
392423 distance : opts ?. distance ,
393424 targetVectors : opts ?. targetVector ? [ opts . targetVector ] : undefined ,
@@ -397,10 +428,22 @@ class AggregateManager<T> implements Aggregate<T> {
397428 }
398429 return this . doGroupBy ( builder ) ;
399430 } ,
400- nearObject : < M extends PropertiesMetrics < T > | undefined = undefined > (
431+ nearObject : async < M extends PropertiesMetrics < T > > (
401432 id : string ,
402433 opts : AggregateGroupByNearOptions < T , M >
403434 ) : Promise < AggregateGroupByResult < T , M > [ ] > => {
435+ if ( await this . grpcChecker ) {
436+ const group = typeof opts . groupBy === 'string' ? { property : opts . groupBy } : opts . groupBy ;
437+ return this . grpc ( )
438+ . then ( ( aggregate ) =>
439+ aggregate . withNearObject ( {
440+ ...Serialize . aggregate . nearObject ( id , opts ) ,
441+ groupBy : Serialize . aggregate . groupBy ( group ) ,
442+ limit : group . limit ,
443+ } )
444+ )
445+ . then ( ( reply ) => Deserialize . aggregateGroupBy ( reply ) ) ;
446+ }
404447 const builder = this . base ( opts ?. returnMetrics , opts ?. filters , opts ?. groupBy ) . withNearObject ( {
405448 id : id ,
406449 certainty : opts ?. certainty ,
@@ -412,10 +455,22 @@ class AggregateManager<T> implements Aggregate<T> {
412455 }
413456 return this . doGroupBy ( builder ) ;
414457 } ,
415- nearText : < M extends PropertiesMetrics < T > | undefined = undefined > (
458+ nearText : async < M extends PropertiesMetrics < T > > (
416459 query : string | string [ ] ,
417460 opts : AggregateGroupByNearOptions < T , M >
418461 ) : Promise < AggregateGroupByResult < T , M > [ ] > => {
462+ if ( await this . grpcChecker ) {
463+ const group = typeof opts . groupBy === 'string' ? { property : opts . groupBy } : opts . groupBy ;
464+ return this . grpc ( )
465+ . then ( ( aggregate ) =>
466+ aggregate . withNearText ( {
467+ ...Serialize . aggregate . nearText ( query , opts ) ,
468+ groupBy : Serialize . aggregate . groupBy ( group ) ,
469+ limit : group . limit ,
470+ } )
471+ )
472+ . then ( ( reply ) => Deserialize . aggregateGroupBy ( reply ) ) ;
473+ }
419474 const builder = this . base ( opts ?. returnMetrics , opts ?. filters , opts ?. groupBy ) . withNearText ( {
420475 concepts : Array . isArray ( query ) ? query : [ query ] ,
421476 certainty : opts ?. certainty ,
@@ -427,10 +482,22 @@ class AggregateManager<T> implements Aggregate<T> {
427482 }
428483 return this . doGroupBy ( builder ) ;
429484 } ,
430- nearVector : < M extends PropertiesMetrics < T > | undefined = undefined > (
485+ nearVector : async < M extends PropertiesMetrics < T > > (
431486 vector : number [ ] ,
432487 opts : AggregateGroupByNearOptions < T , M >
433488 ) : Promise < AggregateGroupByResult < T , M > [ ] > => {
489+ if ( await this . grpcChecker ) {
490+ const group = typeof opts . groupBy === 'string' ? { property : opts . groupBy } : opts . groupBy ;
491+ return this . grpc ( )
492+ . then ( ( aggregate ) =>
493+ aggregate . withNearVector ( {
494+ ...Serialize . aggregate . nearVector ( vector , opts ) ,
495+ groupBy : Serialize . aggregate . groupBy ( group ) ,
496+ limit : group . limit ,
497+ } )
498+ )
499+ . then ( ( reply ) => Deserialize . aggregateGroupBy ( reply ) ) ;
500+ }
434501 const builder = this . base ( opts ?. returnMetrics , opts ?. filters , opts ?. groupBy ) . withNearVector ( {
435502 vector : vector ,
436503 certainty : opts ?. certainty ,
@@ -442,9 +509,22 @@ class AggregateManager<T> implements Aggregate<T> {
442509 }
443510 return this . doGroupBy ( builder ) ;
444511 } ,
445- overAll : < M extends PropertiesMetrics < T > | undefined = undefined > (
512+ overAll : async < M extends PropertiesMetrics < T > > (
446513 opts : AggregateGroupByOptions < T , M >
447514 ) : Promise < AggregateGroupByResult < T , M > [ ] > => {
515+ if ( await this . grpcChecker ) {
516+ const group = typeof opts . groupBy === 'string' ? { property : opts . groupBy } : opts . groupBy ;
517+ return this . grpc ( )
518+ . then ( ( aggregate ) =>
519+ aggregate . withFetch ( {
520+ ...Serialize . aggregate . overAll ( opts ) ,
521+
522+ groupBy : Serialize . aggregate . groupBy ( group ) ,
523+ limit : group . limit ,
524+ } )
525+ )
526+ . then ( ( reply ) => Deserialize . aggregateGroupBy ( reply ) ) ;
527+ }
448528 const builder = this . base ( opts ?. returnMetrics , opts ?. filters , opts ?. groupBy ) ;
449529 return this . doGroupBy ( builder ) ;
450530 } ,
0 commit comments