Skip to content

Commit 120276f

Browse files
committed
Removed tobytes
1 parent 191bee7 commit 120276f

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

pgvector/halfvec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def dimensions(self) -> int:
4141

4242
def to_list(self) -> list[float]:
4343
dim = len(self._value)
44-
return list(struct.unpack(f'{dim}e', self._value.tobytes()))
44+
return list(struct.unpack(f'{dim}e', self._value))
4545

4646
def to_numpy(self) -> np.ndarray[tuple[int], np.dtype[np.float16]]:
4747
return np.frombuffer(self._value, dtype=np.float16)
@@ -55,7 +55,7 @@ def to_binary(self) -> bytes:
5555
else:
5656
value = array.array('H', self._value)
5757
value.byteswap()
58-
return struct.pack(f'>HH', len(value), 0) + value.tobytes()
58+
return struct.pack(f'>HH', len(value), 0) + memoryview(value)
5959

6060
@classmethod
6161
def from_text(cls, value: str) -> HalfVector:

pgvector/vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def to_binary(self) -> bytes:
5353
else:
5454
value = array.array('f', self._value)
5555
value.byteswap()
56-
return struct.pack(f'>HH', len(value), 0) + value.tobytes()
56+
return struct.pack(f'>HH', len(value), 0) + memoryview(value)
5757

5858
@classmethod
5959
def from_text(cls, value: str) -> Vector:

0 commit comments

Comments
 (0)