Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 055a084

Browse files
committedApr 29, 2025
Include knn in model construction
1 parent 02b7b4b commit 055a084

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎aredis_om/model/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ async def execute(
885885
if return_raw_result:
886886
return raw_result
887887
count = raw_result[0]
888-
results = self.model.from_redis(raw_result)
888+
results = self.model.from_redis(raw_result, self.knn)
889889
self._model_cache += results
890890

891891
if not exhaust_results:
@@ -1375,7 +1375,7 @@ def outer_type_or_annotation(field: FieldInfo):
13751375
return field.annotation.__args__[0] # type: ignore
13761376

13771377

1378-
def should_index_field(field_info: PydanticFieldInfo) -> bool:
1378+
def should_index_field(field_info: FieldInfo) -> bool:
13791379
# for vector, full text search, and sortable fields, we always have to index
13801380
# We could require the user to set index=True, but that would be a breaking change
13811381
return (
@@ -1509,7 +1509,7 @@ def find(
15091509
return FindQuery(expressions=expressions, knn=knn, model=cls)
15101510

15111511
@classmethod
1512-
def from_redis(cls, res: Any):
1512+
def from_redis(cls, res: Any, knn: Optional[KNNExpression] = None):
15131513
# TODO: Parsing logic copied from redisearch-py. Evaluate.
15141514
def to_string(s):
15151515
if isinstance(s, (str,)):
@@ -1535,7 +1535,9 @@ def to_string(s):
15351535
# $ means a json entry
15361536
if fields.get("$"):
15371537
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})
15391541
doc = cls(**json_fields)
15401542
else:
15411543
doc = cls(**fields)

0 commit comments

Comments
 (0)
Please sign in to comment.