FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pgvector-python/pgvector/psycopg/sparsevec.py at master · pgvector/pgvector-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pgvector
/
pgvector-python
Public
Notifications
You must be signed in to change notification settings
Fork
93
Star
1.5k
Code
Issues
0
Pull requests
4
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
pgvector-python
/
pgvector
/
psycopg
/
sparsevec.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (35 loc) · 1.54 KB
Breadcrumbs
pgvector-python
/
pgvector
/
psycopg
/
sparsevec.py
Copy path
File metadata and controls
51 lines (35 loc) · 1.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from
psycopg
import
BaseConnection
from
psycopg
.
abc
import
Buffer
from
psycopg
.
adapt
import
Loader
,
Dumper
from
psycopg
.
pq
import
Format
from
psycopg
.
types
import
TypeInfo
from
typing
import
Any
from
..
import
SparseVector
class
SparseVectorDumper
(
Dumper
):
format
=
Format
.
TEXT
def
dump
(
self
,
obj
:
SparseVector
)
->
Buffer
|
None
:
return
obj
.
to_text
().
encode
(
'utf8'
)
class
SparseVectorBinaryDumper
(
SparseVectorDumper
):
format
=
Format
.
BINARY
def
dump
(
self
,
obj
:
SparseVector
)
->
Buffer
|
None
:
return
obj
.
to_binary
()
class
SparseVectorLoader
(
Loader
):
format
=
Format
.
TEXT
def
load
(
self
,
data
:
Buffer
)
->
SparseVector
|
None
:
if
isinstance
(
data
,
memoryview
):
data
=
data
.
tobytes
()
return
SparseVector
.
from_text
(
data
.
decode
(
'utf8'
))
class
SparseVectorBinaryLoader
(
SparseVectorLoader
):
format
=
Format
.
BINARY
def
load
(
self
,
data
:
Buffer
)
->
SparseVector
|
None
:
return
SparseVector
.
from_binary
(
data
)
def
register_sparsevec_info
(
context
:
BaseConnection
[
Any
],
info
:
TypeInfo
,
/
)
->
None
:
info
.
register
(
context
)
# add oid to anonymous class for set_types
text_dumper
=
type
(
''
, (
SparseVectorDumper
,), {
'oid'
:
info
.
oid
})
binary_dumper
=
type
(
''
, (
SparseVectorBinaryDumper
,), {
'oid'
:
info
.
oid
})
adapters
=
context
.
adapters
adapters
.
register_dumper
(
SparseVector
,
text_dumper
)
adapters
.
register_dumper
(
SparseVector
,
binary_dumper
)
adapters
.
register_loader
(
info
.
oid
,
SparseVectorLoader
)
adapters
.
register_loader
(
info
.
oid
,
SparseVectorBinaryLoader
)
Back
|
FazBrowse Home
|
New Git URL