@@ -885,7 +885,7 @@ async def execute(
885
885
if return_raw_result :
886
886
return raw_result
887
887
count = raw_result [0 ]
888
- results = self .model .from_redis (raw_result )
888
+ results = self .model .from_redis (raw_result , self . knn )
889
889
self ._model_cache += results
890
890
891
891
if not exhaust_results :
@@ -1375,7 +1375,7 @@ def outer_type_or_annotation(field: FieldInfo):
1375
1375
return field .annotation .__args__ [0 ] # type: ignore
1376
1376
1377
1377
1378
- def should_index_field (field_info : PydanticFieldInfo ) -> bool :
1378
+ def should_index_field (field_info : FieldInfo ) -> bool :
1379
1379
# for vector, full text search, and sortable fields, we always have to index
1380
1380
# We could require the user to set index=True, but that would be a breaking change
1381
1381
return (
@@ -1509,7 +1509,7 @@ def find(
1509
1509
return FindQuery (expressions = expressions , knn = knn , model = cls )
1510
1510
1511
1511
@classmethod
1512
- def from_redis (cls , res : Any ):
1512
+ def from_redis (cls , res : Any , knn : Optional [ KNNExpression ] = None ):
1513
1513
# TODO: Parsing logic copied from redisearch-py. Evaluate.
1514
1514
def to_string (s ):
1515
1515
if isinstance (s , (str ,)):
@@ -1535,7 +1535,9 @@ def to_string(s):
1535
1535
# $ means a json entry
1536
1536
if fields .get ("$" ):
1537
1537
json_fields = json .loads (fields .pop ("$" ))
1538
- json_fields .update (fields )
1538
+ if knn :
1539
+ score = fields .get (knn .score_field_name )
1540
+ json_fields .update ({knn .score_field_name : score })
1539
1541
doc = cls (** json_fields )
1540
1542
else :
1541
1543
doc = cls (** fields )
0 commit comments