Skip to content

Commit c399b60

Browse files
committed
Improved code [skip ci]
1 parent 4dba27b commit c399b60

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

pgvector/halfvec.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ def _from_db(cls, value: str | HalfVector | None) -> list[float] | None:
108108
if value is None:
109109
return value
110110

111-
if isinstance(value, str):
112-
return cls._list_from_text(value)
111+
# Handle conversion from low-level driver
112+
if isinstance(value, HalfVector):
113+
return value.to_list()
113114

114-
return value.to_list()
115+
return cls._list_from_text(value)
115116

116117
@classmethod
117118
def _list_from_text(cls, value: str) -> list[float]:

pgvector/vector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ def _from_db(cls, value: str | Vector | None) -> list[float] | None:
106106
if value is None:
107107
return value
108108

109-
if isinstance(value, str):
110-
return cls._list_from_text(value)
109+
# Handle conversion from low-level driver
110+
if isinstance(value, Vector):
111+
return value.to_list()
111112

112-
return value.to_list()
113+
return cls._list_from_text(value)
113114

114115
@classmethod
115116
def _list_from_text(cls, value: str) -> list[float]:

0 commit comments

Comments
 (0)