diff --git a/libs/checkpoint-postgres/langgraph/store/postgres/base.py b/libs/checkpoint-postgres/langgraph/store/postgres/base.py index e78ac6fe9..9c88d3a79 100644 --- a/libs/checkpoint-postgres/langgraph/store/postgres/base.py +++ b/libs/checkpoint-postgres/langgraph/store/postgres/base.py @@ -925,6 +925,32 @@ def _row_to_search_item( ) +def _row_to_search_item( + namespace: tuple[str, ...], + row: Row, + *, + loader: Optional[Callable[[Union[bytes, orjson.Fragment]], dict[str, Any]]] = None, +) -> SearchItem: + """Convert a row from the database into an Item.""" + loader = loader or _json_loads + val = row["value"] + score = row.get("score") + if score is not None: + try: + score = float(score) # type: ignore[arg-type] + except ValueError: + logger.warning("Invalid score: %s", score) + score = None + return SearchItem( + value=val if isinstance(val, dict) else loader(val), + key=row["key"], + namespace=namespace, + created_at=row["created_at"], + updated_at=row["updated_at"], + score=score, + ) + + def _group_ops(ops: Iterable[Op]) -> tuple[dict[type, list[tuple[int, Op]]], int]: grouped_ops: dict[type, list[tuple[int, Op]]] = defaultdict(list) tot = 0