@@ -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
index = getattr (field_info , "index" , None ) is True
@@ -1515,7 +1515,7 @@ def find(
1515
1515
return FindQuery (expressions = expressions , knn = knn , model = cls )
1516
1516
1517
1517
@classmethod
1518
- def from_redis (cls , res : Any ):
1518
+ def from_redis (cls , res : Any , knn : Optional [ KNNExpression ] = None ):
1519
1519
# TODO: Parsing logic copied from redisearch-py. Evaluate.
1520
1520
def to_string (s ):
1521
1521
if isinstance (s , (str ,)):
@@ -1541,7 +1541,9 @@ def to_string(s):
1541
1541
# $ means a json entry
1542
1542
if fields .get ("$" ):
1543
1543
json_fields = json .loads (fields .pop ("$" ))
1544
- json_fields .update (fields )
1544
+ if knn :
1545
+ score = fields .get (knn .score_field_name )
1546
+ json_fields .update ({knn .score_field_name : score })
1545
1547
doc = cls (** json_fields )
1546
1548
else :
1547
1549
doc = cls (** fields )
0 commit comments