@@ -13,13 +13,17 @@ def __init__(
13
13
return_fields : Optional [List [str ]] = None ,
14
14
num_results : int = 10 ,
15
15
dialect : int = 2 ,
16
+ sort_by : Optional [str ] = None ,
17
+ in_order : bool = False ,
16
18
):
17
19
"""Base query class used to subclass many query types."""
18
20
self ._return_fields = return_fields if return_fields is not None else []
19
21
self ._num_results = num_results
20
22
self ._dialect = dialect
21
23
self ._first = 0
22
24
self ._limit = num_results
25
+ self ._sort_by = sort_by
26
+ self ._in_order = in_order
23
27
24
28
def __str__ (self ) -> str :
25
29
return " " .join ([str (x ) for x in self .query .get_args ()])
@@ -137,6 +141,7 @@ def __init__(
137
141
num_results : int = 10 ,
138
142
dialect : int = 2 ,
139
143
sort_by : Optional [str ] = None ,
144
+ in_order : bool = False ,
140
145
params : Optional [Dict [str , Any ]] = None ,
141
146
):
142
147
"""A query for a running a filtered search with a filter expression.
@@ -149,6 +154,9 @@ def __init__(
149
154
return. Defaults to 10.
150
155
sort_by (Optional[str]): The field to order the results by. Defaults
151
156
to None. Results will be ordered by vector distance.
157
+ in_order (bool): Requires the terms in the field to have
158
+ the same order as the terms in the query filter, regardless of
159
+ the offsets between them. Defaults to False.
152
160
params (Optional[Dict[str, Any]], optional): The parameters for the
153
161
query. Defaults to None.
154
162
@@ -165,9 +173,8 @@ def __init__(
165
173
q = FilterQuery(return_fields=["brand", "price"], filter_expression=t)
166
174
167
175
"""
168
- super ().__init__ (return_fields , num_results , dialect )
176
+ super ().__init__ (return_fields , num_results , dialect , sort_by , in_order )
169
177
self .set_filter (filter_expression )
170
- self ._sort_by = sort_by
171
178
self ._params = params or {}
172
179
173
180
@property
@@ -186,6 +193,10 @@ def query(self) -> Query:
186
193
)
187
194
if self ._sort_by :
188
195
query = query .sort_by (self ._sort_by )
196
+
197
+ if self ._in_order :
198
+ query = query .in_order ()
199
+
189
200
return query
190
201
191
202
@@ -208,13 +219,13 @@ def __init__(
208
219
return_score : bool = True ,
209
220
dialect : int = 2 ,
210
221
sort_by : Optional [str ] = None ,
222
+ in_order : bool = False ,
211
223
):
212
- super ().__init__ (return_fields , num_results , dialect )
224
+ super ().__init__ (return_fields , num_results , dialect , sort_by , in_order )
213
225
self .set_filter (filter_expression )
214
226
self ._vector = vector
215
227
self ._field = vector_field_name
216
228
self ._dtype = dtype .lower ()
217
- self ._sort_by = sort_by
218
229
219
230
if return_score :
220
231
self ._return_fields .append (self .DISTANCE_ID )
@@ -232,6 +243,7 @@ def __init__(
232
243
return_score : bool = True ,
233
244
dialect : int = 2 ,
234
245
sort_by : Optional [str ] = None ,
246
+ in_order : bool = False ,
235
247
):
236
248
"""A query for running a vector search along with an optional filter
237
249
expression.
@@ -254,6 +266,9 @@ def __init__(
254
266
Defaults to 2.
255
267
sort_by (Optional[str]): The field to order the results by. Defaults
256
268
to None. Results will be ordered by vector distance.
269
+ in_order (bool): Requires the terms in the field to have
270
+ the same order as the terms in the query filter, regardless of
271
+ the offsets between them. Defaults to False.
257
272
258
273
Raises:
259
274
TypeError: If filter_expression is not of type redisvl.query.FilterExpression
@@ -271,6 +286,7 @@ def __init__(
271
286
return_score ,
272
287
dialect ,
273
288
sort_by ,
289
+ in_order ,
274
290
)
275
291
276
292
@property
@@ -291,6 +307,10 @@ def query(self) -> Query:
291
307
query = query .sort_by (self ._sort_by )
292
308
else :
293
309
query = query .sort_by (self .DISTANCE_ID )
310
+
311
+ if self ._in_order :
312
+ query = query .in_order ()
313
+
294
314
return query
295
315
296
316
@property
@@ -323,6 +343,7 @@ def __init__(
323
343
return_score : bool = True ,
324
344
dialect : int = 2 ,
325
345
sort_by : Optional [str ] = None ,
346
+ in_order : bool = False ,
326
347
):
327
348
"""A query for running a filtered vector search based on semantic
328
349
distance threshold.
@@ -348,6 +369,10 @@ def __init__(
348
369
Defaults to 2.
349
370
sort_by (Optional[str]): The field to order the results by. Defaults
350
371
to None. Results will be ordered by vector distance.
372
+ in_order (bool): Requires the terms in the field to have
373
+ the same order as the terms in the query filter, regardless of
374
+ the offsets between them. Defaults to False.
375
+
351
376
Raises:
352
377
TypeError: If filter_expression is not of type redisvl.query.FilterExpression
353
378
@@ -365,6 +390,7 @@ def __init__(
365
390
return_score ,
366
391
dialect ,
367
392
sort_by ,
393
+ in_order ,
368
394
)
369
395
self .set_distance_threshold (distance_threshold )
370
396
@@ -415,6 +441,10 @@ def query(self) -> Query:
415
441
query = query .sort_by (self ._sort_by )
416
442
else :
417
443
query = query .sort_by (self .DISTANCE_ID )
444
+
445
+ if self ._in_order :
446
+ query = query .in_order ()
447
+
418
448
return query
419
449
420
450
@property
0 commit comments