Skip to content

Commit df8433e

Browse files
committed
Merge branch 'triage/pydantic-v2' of https://github.com/Triage-Staffing/redis-om-python into triage/pydantic-v2
2 parents 0040e7f + 055a084 commit df8433e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

aredis_om/model/model.py

+6-4
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
index = getattr(field_info, "index", None) is True
@@ -1515,7 +1515,7 @@ def find(
15151515
return FindQuery(expressions=expressions, knn=knn, model=cls)
15161516

15171517
@classmethod
1518-
def from_redis(cls, res: Any):
1518+
def from_redis(cls, res: Any, knn: Optional[KNNExpression] = None):
15191519
# TODO: Parsing logic copied from redisearch-py. Evaluate.
15201520
def to_string(s):
15211521
if isinstance(s, (str,)):
@@ -1541,7 +1541,9 @@ def to_string(s):
15411541
# $ means a json entry
15421542
if fields.get("$"):
15431543
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})
15451547
doc = cls(**json_fields)
15461548
else:
15471549
doc = cls(**fields)

0 commit comments

Comments
 (0)