@@ -31,7 +31,9 @@ import {
3131 GenerativeGroupByReturn ,
3232 GenerativeReturn ,
3333 GroupByOptions ,
34+ ReturnVectors ,
3435} from '../types/index.js' ;
36+ import { IncludeVector } from '../types/internal.js' ;
3537import { Generate } from './types.js' ;
3638
3739class GenerateManager < T , V > implements Generate < T , V > {
@@ -53,19 +55,19 @@ class GenerateManager<T, V> implements Generate<T, V> {
5355 ) ;
5456 }
5557
56- private async parseReply ( reply : SearchReply ) {
58+ private async parseReply < RV > ( reply : SearchReply ) {
5759 const deserialize = await Deserialize . use ( this . check . dbVersionSupport ) ;
58- return deserialize . generate < T , V > ( reply ) ;
60+ return deserialize . generate < T , RV > ( reply ) ;
5961 }
6062
61- private async parseGroupByReply (
62- opts : SearchOptions < T , V > | GroupByOptions < T > | undefined ,
63+ private async parseGroupByReply < RV > (
64+ opts : SearchOptions < any , any > | GroupByOptions < any > | undefined ,
6365 reply : SearchReply
6466 ) {
6567 const deserialize = await Deserialize . use ( this . check . dbVersionSupport ) ;
6668 return Serialize . search . isGroupBy ( opts )
67- ? deserialize . generateGroupBy < T , V > ( reply )
68- : deserialize . generate < T , V > ( reply ) ;
69+ ? deserialize . generateGroupBy < T , RV > ( reply )
70+ : deserialize . generate < T , RV > ( reply ) ;
6971 }
7072
7173 public fetchObjects (
@@ -85,17 +87,21 @@ class GenerateManager<T, V> implements Generate<T, V> {
8587 . then ( ( reply ) => this . parseReply ( reply ) ) ;
8688 }
8789
88- public bm25 (
90+ public bm25 < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
8991 query : string ,
9092 generate : GenerateOptions < T > ,
91- opts ?: BaseBm25Options < T , V >
92- ) : Promise < GenerativeReturn < T , V > > ;
93- public bm25 (
93+ opts ?: BaseBm25Options < T , I >
94+ ) : Promise < GenerativeReturn < T , RV > > ;
95+ public bm25 < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
9496 query : string ,
9597 generate : GenerateOptions < T > ,
96- opts : GroupByBm25Options < T , V >
97- ) : Promise < GenerativeGroupByReturn < T , V > > ;
98- public bm25 ( query : string , generate : GenerateOptions < T > , opts ?: Bm25Options < T , V > ) : GenerateReturn < T , V > {
98+ opts : GroupByBm25Options < T , I >
99+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
100+ public bm25 < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
101+ query : string ,
102+ generate : GenerateOptions < T > ,
103+ opts ?: Bm25Options < T , I >
104+ ) : GenerateReturn < T , RV > {
99105 return this . check
100106 . bm25 ( opts )
101107 . then ( ( { search } ) => ( {
@@ -109,21 +115,21 @@ class GenerateManager<T, V> implements Generate<T, V> {
109115 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
110116 }
111117
112- public hybrid (
118+ public hybrid < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
113119 query : string ,
114120 generate : GenerateOptions < T > ,
115- opts ?: BaseHybridOptions < T , V >
116- ) : Promise < GenerativeReturn < T , V > > ;
117- public hybrid (
121+ opts ?: BaseHybridOptions < T , V , I >
122+ ) : Promise < GenerativeReturn < T , RV > > ;
123+ public hybrid < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
118124 query : string ,
119125 generate : GenerateOptions < T > ,
120- opts : GroupByHybridOptions < T , V >
121- ) : Promise < GenerativeGroupByReturn < T , V > > ;
122- public hybrid (
126+ opts : GroupByHybridOptions < T , V , I >
127+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
128+ public hybrid < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
123129 query : string ,
124130 generate : GenerateOptions < T > ,
125- opts ?: HybridOptions < T , V >
126- ) : GenerateReturn < T , V > {
131+ opts ?: HybridOptions < T , V , I >
132+ ) : GenerateReturn < T , RV > {
127133 return this . check
128134 . hybridSearch ( opts )
129135 . then (
@@ -154,21 +160,21 @@ class GenerateManager<T, V> implements Generate<T, V> {
154160 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
155161 }
156162
157- public nearImage (
163+ public nearImage < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
158164 image : string | Buffer ,
159165 generate : GenerateOptions < T > ,
160- opts ?: BaseNearOptions < T , V >
161- ) : Promise < GenerativeReturn < T , V > > ;
162- public nearImage (
166+ opts ?: BaseNearOptions < T , V , I >
167+ ) : Promise < GenerativeReturn < T , RV > > ;
168+ public nearImage < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
163169 image : string | Buffer ,
164170 generate : GenerateOptions < T > ,
165- opts : GroupByNearOptions < T , V >
166- ) : Promise < GenerativeGroupByReturn < T , V > > ;
167- public nearImage (
171+ opts : GroupByNearOptions < T , V , I >
172+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
173+ public nearImage < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
168174 image : string | Buffer ,
169175 generate : GenerateOptions < T > ,
170- opts ?: NearOptions < T , V >
171- ) : GenerateReturn < T , V > {
176+ opts ?: NearOptions < T , V , I >
177+ ) : GenerateReturn < T , RV > {
172178 return this . check
173179 . nearSearch ( opts )
174180 . then ( async ( { search, supportsTargets, supportsWeightsForTargets } ) => ( {
@@ -189,21 +195,21 @@ class GenerateManager<T, V> implements Generate<T, V> {
189195 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
190196 }
191197
192- public nearObject (
198+ public nearObject < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
193199 id : string ,
194200 generate : GenerateOptions < T > ,
195- opts ?: BaseNearOptions < T , V >
196- ) : Promise < GenerativeReturn < T , V > > ;
197- public nearObject (
201+ opts ?: BaseNearOptions < T , V , I >
202+ ) : Promise < GenerativeReturn < T , RV > > ;
203+ public nearObject < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
198204 id : string ,
199205 generate : GenerateOptions < T > ,
200- opts : GroupByNearOptions < T , V >
201- ) : Promise < GenerativeGroupByReturn < T , V > > ;
202- public nearObject (
206+ opts : GroupByNearOptions < T , V , I >
207+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
208+ public nearObject < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
203209 id : string ,
204210 generate : GenerateOptions < T > ,
205- opts ?: NearOptions < T , V >
206- ) : GenerateReturn < T , V > {
211+ opts ?: NearOptions < T , V , I >
212+ ) : GenerateReturn < T , RV > {
207213 return this . check
208214 . nearSearch ( opts )
209215 . then ( ( { search, supportsTargets, supportsWeightsForTargets } ) => ( {
@@ -224,21 +230,21 @@ class GenerateManager<T, V> implements Generate<T, V> {
224230 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
225231 }
226232
227- public nearText (
233+ public nearText < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
228234 query : string | string [ ] ,
229235 generate : GenerateOptions < T > ,
230- opts ?: BaseNearTextOptions < T , V >
231- ) : Promise < GenerativeReturn < T , V > > ;
232- public nearText (
236+ opts ?: BaseNearTextOptions < T , V , I >
237+ ) : Promise < GenerativeReturn < T , RV > > ;
238+ public nearText < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
233239 query : string | string [ ] ,
234240 generate : GenerateOptions < T > ,
235- opts : GroupByNearTextOptions < T , V >
236- ) : Promise < GenerativeGroupByReturn < T , V > > ;
237- public nearText (
241+ opts : GroupByNearTextOptions < T , V , I >
242+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
243+ public nearText < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
238244 query : string | string [ ] ,
239245 generate : GenerateOptions < T > ,
240- opts ?: NearOptions < T , V >
241- ) : GenerateReturn < T , V > {
246+ opts ?: NearOptions < T , V , I >
247+ ) : GenerateReturn < T , RV > {
242248 return this . check
243249 . nearSearch ( opts )
244250 . then ( ( { search, supportsTargets, supportsWeightsForTargets } ) => ( {
@@ -259,21 +265,21 @@ class GenerateManager<T, V> implements Generate<T, V> {
259265 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
260266 }
261267
262- public nearVector (
268+ public nearVector < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
263269 vector : number [ ] ,
264270 generate : GenerateOptions < T > ,
265- opts ?: BaseNearOptions < T , V >
266- ) : Promise < GenerativeReturn < T , V > > ;
267- public nearVector (
271+ opts ?: BaseNearOptions < T , V , I >
272+ ) : Promise < GenerativeReturn < T , RV > > ;
273+ public nearVector < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
268274 vector : number [ ] ,
269275 generate : GenerateOptions < T > ,
270- opts : GroupByNearOptions < T , V >
271- ) : Promise < GenerativeGroupByReturn < T , V > > ;
272- public nearVector (
276+ opts : GroupByNearOptions < T , V , I >
277+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
278+ public nearVector < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
273279 vector : number [ ] ,
274280 generate : GenerateOptions < T > ,
275- opts ?: NearOptions < T , V >
276- ) : GenerateReturn < T , V > {
281+ opts ?: NearOptions < T , V , I >
282+ ) : GenerateReturn < T , RV > {
277283 return this . check
278284 . nearVector ( vector , opts )
279285 . then (
@@ -304,24 +310,24 @@ class GenerateManager<T, V> implements Generate<T, V> {
304310 . then ( ( reply ) => this . parseGroupByReply ( opts , reply ) ) ;
305311 }
306312
307- public nearMedia (
313+ public nearMedia < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
308314 media : string | Buffer ,
309315 type : NearMediaType ,
310316 generate : GenerateOptions < T > ,
311- opts ?: BaseNearOptions < T , V >
312- ) : Promise < GenerativeReturn < T , V > > ;
313- public nearMedia (
317+ opts ?: BaseNearOptions < T , V , I >
318+ ) : Promise < GenerativeReturn < T , RV > > ;
319+ public nearMedia < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
314320 media : string | Buffer ,
315321 type : NearMediaType ,
316322 generate : GenerateOptions < T > ,
317- opts : GroupByNearOptions < T , V >
318- ) : Promise < GenerativeGroupByReturn < T , V > > ;
319- public nearMedia (
323+ opts : GroupByNearOptions < T , V , I >
324+ ) : Promise < GenerativeGroupByReturn < T , RV > > ;
325+ public nearMedia < I extends IncludeVector < V > , RV extends ReturnVectors < V , I > > (
320326 media : string | Buffer ,
321327 type : NearMediaType ,
322328 generate : GenerateOptions < T > ,
323- opts ?: NearOptions < T , V >
324- ) : GenerateReturn < T , V > {
329+ opts ?: NearOptions < T , V , I >
330+ ) : GenerateReturn < T , RV > {
325331 return this . check
326332 . nearSearch ( opts )
327333 . then ( ( { search, supportsTargets, supportsWeightsForTargets } ) => {
0 commit comments