forked from pgvector/pgvector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhalfvec.py
More file actions
25 lines (16 loc) · 715 Bytes
/
halfvec.py
File metadata and controls
25 lines (16 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from psycopg2.extensions import adapt, new_array_type, new_type, register_adapter, register_type
from ..utils import HalfVector
class HalfvecAdapter:
def __init__(self, value):
self._value = value
def getquoted(self):
return adapt(HalfVector._to_db(self._value)).getquoted()
def cast_halfvec(value, cur):
return HalfVector._from_db(value)
def register_halfvec_info(oid, array_oid, scope):
halfvec = new_type((oid,), 'HALFVEC', cast_halfvec)
register_type(halfvec, scope)
if array_oid is not None:
halfvecarray = new_array_type((array_oid,), 'HALFVECARRAY', halfvec)
register_type(halfvecarray, scope)
register_adapter(HalfVector, HalfvecAdapter)