aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to '.venv/lib/python3.12/site-packages/pgvector/sqlalchemy')
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/__init__.py19
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/bit.py26
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/functions.py14
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/halfvec.py51
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/sparsevec.py51
-rw-r--r--.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/vector.py51
6 files changed, 212 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/__init__.py b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/__init__.py
new file mode 100644
index 00000000..4955eeb9
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/__init__.py
@@ -0,0 +1,19 @@
+from .bit import BIT
+from .functions import avg, sum
+from .halfvec import HALFVEC
+from .sparsevec import SPARSEVEC
+from .vector import VECTOR
+from .vector import VECTOR as Vector
+from ..utils import HalfVector, SparseVector
+
+__all__ = [
+ 'Vector',
+ 'VECTOR',
+ 'HALFVEC',
+ 'BIT',
+ 'SPARSEVEC',
+ 'HalfVector',
+ 'SparseVector',
+ 'avg',
+ 'sum'
+]
diff --git a/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/bit.py b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/bit.py
new file mode 100644
index 00000000..0f83f3c6
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/bit.py
@@ -0,0 +1,26 @@
+from sqlalchemy.dialects.postgresql.base import ischema_names
+from sqlalchemy.types import UserDefinedType, Float
+
+
+class BIT(UserDefinedType):
+ cache_ok = True
+
+ def __init__(self, length=None):
+ super(UserDefinedType, self).__init__()
+ self.length = length
+
+ def get_col_spec(self, **kw):
+ if self.length is None:
+ return 'BIT'
+ return 'BIT(%d)' % self.length
+
+ class comparator_factory(UserDefinedType.Comparator):
+ def hamming_distance(self, other):
+ return self.op('<~>', return_type=Float)(other)
+
+ def jaccard_distance(self, other):
+ return self.op('<%>', return_type=Float)(other)
+
+
+# for reflection
+ischema_names['bit'] = BIT
diff --git a/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/functions.py b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/functions.py
new file mode 100644
index 00000000..72e3ca7e
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/functions.py
@@ -0,0 +1,14 @@
+# https://docs.sqlalchemy.org/en/20/core/functions.html
+# include sum for a consistent API
+from sqlalchemy.sql.functions import ReturnTypeFromArgs, sum
+
+
+class avg(ReturnTypeFromArgs):
+ inherit_cache = True
+ package = 'pgvector'
+
+
+__all__ = [
+ 'avg',
+ 'sum'
+]
diff --git a/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/halfvec.py b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/halfvec.py
new file mode 100644
index 00000000..639f77bd
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/halfvec.py
@@ -0,0 +1,51 @@
+from sqlalchemy.dialects.postgresql.base import ischema_names
+from sqlalchemy.types import UserDefinedType, Float, String
+from ..utils import HalfVector
+
+
+class HALFVEC(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 'HALFVEC'
+ return 'HALFVEC(%d)' % self.dim
+
+ def bind_processor(self, dialect):
+ def process(value):
+ return HalfVector._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(HalfVector._to_db(value, self.dim))
+ return process
+
+ def result_processor(self, dialect, coltype):
+ def process(value):
+ return HalfVector._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['halfvec'] = HALFVEC
diff --git a/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/sparsevec.py b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/sparsevec.py
new file mode 100644
index 00000000..370f5d14
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/sparsevec.py
@@ -0,0 +1,51 @@
+from sqlalchemy.dialects.postgresql.base import ischema_names
+from sqlalchemy.types import UserDefinedType, Float, String
+from ..utils 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
diff --git a/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/vector.py b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/vector.py
new file mode 100644
index 00000000..f57a045d
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/pgvector/sqlalchemy/vector.py
@@ -0,0 +1,51 @@
+from sqlalchemy.dialects.postgresql.base import ischema_names
+from sqlalchemy.types import UserDefinedType, Float, String
+from ..utils import Vector
+
+
+class VECTOR(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 'VECTOR'
+ return 'VECTOR(%d)' % self.dim
+
+ def bind_processor(self, dialect):
+ def process(value):
+ return Vector._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(Vector._to_db(value, self.dim))
+ return process
+
+ def result_processor(self, dialect, coltype):
+ def process(value):
+ return Vector._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['vector'] = VECTOR