FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pgvector-python/pgvector/sqlalchemy/sparsevec.py at master · secureonelabs/pgvector-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
secureonelabs
/
pgvector-python
Public
forked from
pgvector/pgvector-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pgvector-python
/
pgvector
/
sqlalchemy
/
sparsevec.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (37 loc) · 1.51 KB
Breadcrumbs
pgvector-python
/
pgvector
/
sqlalchemy
/
sparsevec.py
Copy path
File metadata and controls
51 lines (37 loc) · 1.51 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
sqlalchemy
.
dialects
.
postgresql
.
base
import
ischema_names
from
sqlalchemy
.
types
import
UserDefinedType
,
Float
,
String
from
..
import
SparseVector
class
SPARSEVEC
(
UserDefinedType
):
cache_ok
=
True
_string
=
String
()
def
__init__
(
self
,
dim
=
None
):
super
(
UserDefinedType
,
self
).
__init__
()
self
.
dim
=
dim
def
get_col_spec
(
self
,
**
kw
):
if
self
.
dim
is
None
:
return
'SPARSEVEC'
return
'SPARSEVEC(%d)'
%
self
.
dim
def
bind_processor
(
self
,
dialect
):
def
process
(
value
):
return
SparseVector
.
_to_db
(
value
,
self
.
dim
)
return
process
def
literal_processor
(
self
,
dialect
):
string_literal_processor
=
self
.
_string
.
_cached_literal_processor
(
dialect
)
def
process
(
value
):
return
string_literal_processor
(
SparseVector
.
_to_db
(
value
,
self
.
dim
))
return
process
def
result_processor
(
self
,
dialect
,
coltype
):
def
process
(
value
):
return
SparseVector
.
_from_db
(
value
)
return
process
class
comparator_factory
(
UserDefinedType
.
Comparator
):
def
l2_distance
(
self
,
other
):
return
self
.
op
(
'<->'
,
return_type
=
Float
)(
other
)
def
max_inner_product
(
self
,
other
):
return
self
.
op
(
'<#>'
,
return_type
=
Float
)(
other
)
def
cosine_distance
(
self
,
other
):
return
self
.
op
(
'<=>'
,
return_type
=
Float
)(
other
)
def
l1_distance
(
self
,
other
):
return
self
.
op
(
'<+>'
,
return_type
=
Float
)(
other
)
# for reflection
ischema_names
[
'sparsevec'
]
=
SPARSEVEC
Back
|
FazBrowse Home
|
New Git URL