Skip to content

Commit 8f2ec85

Browse files
committed
Removed _to_db_binary methods [skip ci]
1 parent c912f50 commit 8f2ec85

4 files changed

Lines changed: 3 additions & 24 deletions

File tree

pgvector/asyncpg/register.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async def register_vector(conn: Connection, schema: str = 'public') -> None:
66
await conn.set_type_codec(
77
'vector',
88
schema=schema,
9-
encoder=Vector._to_db_binary,
9+
encoder=lambda v: (v if isinstance(v, Vector) else Vector(v)).to_binary(),
1010
decoder=Vector.from_binary,
1111
format='binary'
1212
)
@@ -15,15 +15,15 @@ async def register_vector(conn: Connection, schema: str = 'public') -> None:
1515
await conn.set_type_codec(
1616
'halfvec',
1717
schema=schema,
18-
encoder=HalfVector._to_db_binary,
18+
encoder=lambda v: (v if isinstance(v, HalfVector) else HalfVector(v)).to_binary(),
1919
decoder=HalfVector.from_binary,
2020
format='binary'
2121
)
2222

2323
await conn.set_type_codec(
2424
'sparsevec',
2525
schema=schema,
26-
encoder=SparseVector._to_db_binary,
26+
encoder=lambda v: (v if isinstance(v, SparseVector) else SparseVector(v)).to_binary(),
2727
decoder=SparseVector.from_binary,
2828
format='binary'
2929
)

pgvector/halfvec.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ def _to_db(cls, value: object) -> str | None:
9393

9494
return value.to_text()
9595

96-
@classmethod
97-
def _to_db_binary(cls, value: object) -> bytes:
98-
if not isinstance(value, cls):
99-
value = cls(value) # type: ignore
100-
101-
return value.to_binary()
102-
10396
@classmethod
10497
def _from_db(cls, value: str | HalfVector | None) -> list[float] | None:
10598
if value is None:

pgvector/sparsevec.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ def _to_db(cls, value: object) -> str | None:
158158

159159
return value.to_text()
160160

161-
@classmethod
162-
def _to_db_binary(cls, value: object) -> bytes:
163-
if not isinstance(value, cls):
164-
value = cls(value)
165-
166-
return value.to_binary()
167-
168161
@classmethod
169162
def _from_db(cls, value: str | SparseVector | None) -> SparseVector | None:
170163
if value is None or isinstance(value, SparseVector):

pgvector/vector.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ def _to_db(cls, value: object) -> str | None:
9191

9292
return value.to_text()
9393

94-
@classmethod
95-
def _to_db_binary(cls, value: object) -> bytes:
96-
if not isinstance(value, cls):
97-
value = cls(value) # type: ignore
98-
99-
return value.to_binary()
100-
10194
@classmethod
10295
def _from_db(cls, value: str | Vector | None) -> list[float] | None:
10396
if value is None:

0 commit comments

Comments
 (0)