We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b1e3669 commit 90ed89cCopy full SHA for 90ed89c
1 file changed
pgvector/sparsevec.py
@@ -129,6 +129,13 @@ def from_text(cls, value: str) -> SparseVector:
129
@classmethod
130
def from_binary(cls, value: bytes) -> SparseVector:
131
dim, nnz, unused = unpack_from('>iii', value)
132
+
133
+ if len(value) != 12 + 8 * nnz:
134
+ raise ValueError('invalid length')
135
136
+ if unused != 0:
137
+ raise ValueError('expected unused to be 0')
138
139
indices = unpack_from(f'>{nnz}i', value, 12)
140
values = unpack_from(f'>{nnz}f', value, 12 + nnz * 4)
141
return cls._from_parts(int(dim), list(indices), list(values))
0 commit comments