Skip to content

Commit cf0f4e9

Browse files
committed
Improved to_text method for SparseVector [skip ci]
1 parent 66eef36 commit cf0f4e9

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

pgvector/sparsevec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def to_numpy(self) -> np.ndarray[tuple[int, ...], np.dtype[np.float32]]:
8080
return vec
8181

8282
def to_text(self) -> str:
83-
return '{' + ','.join([f'{int(i) + 1}:{float(v)}' for i, v in zip(self._indices, self._values)]) + '}/' + str(int(self._dim))
83+
elements = ','.join([f'{int(i) + 1}:{float(v)}' for i, v in zip(self._indices, self._values)])
84+
return f'{{{elements}}}/{int(self._dim)}'
8485

8586
def to_binary(self) -> bytes:
8687
nnz = len(self._indices)

0 commit comments

Comments
 (0)