| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e9232f9 commit 907f678
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,7 @@ | |||
| 1 | + ## 0.2.5 (unreleased) | ||
| 2 | + | ||
| 3 | + - Added literal binds support for SQLAlchemy | ||
| 4 | + | ||
| 1 | 5 | ## 0.2.4 (2023-11-24) | |
| 2 | 6 | ||
| 3 | 7 | - Improved reflection with SQLAlchemy | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,13 @@ | |||
| 1 | 1 | from sqlalchemy.dialects.postgresql.base import ischema_names | |
| 2 | - from sqlalchemy.types import UserDefinedType, Float | ||
| 2 | + from sqlalchemy.types import UserDefinedType, Float, String | ||
| 3 | 3 | from ..utils import from_db, to_db | |
| 4 | 4 | ||
| 5 | 5 | __all__ = ['Vector'] | |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | class Vector(UserDefinedType): | |
| 9 | 9 | cache_ok = True | |
| 10 | + _string = String() | ||
| 10 | 11 | ||
| 11 | 12 | def __init__(self, dim=None): | |
| 12 | 13 | super(UserDefinedType, self).__init__() | |
@@ -22,6 +23,12 @@ def process(value): | |||
| 22 | 23 | return to_db(value, self.dim) | |
| 23 | 24 | return process | |
| 24 | 25 | ||
| 26 | + def literal_processor(self, dialect): | ||
| 27 | + string_literal_processor = self._string._cached_literal_processor(dialect) | ||
| 28 | + def process(value): | ||
| 29 | + return string_literal_processor(to_db(value, self.dim)) | ||
| 30 | + return process | ||
| 31 | + | ||
| 25 | 32 | def result_processor(self, dialect, coltype): | |
| 26 | 33 | def process(value): | |
| 27 | 34 | return from_db(value) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -219,6 +219,10 @@ def test_inspect(self): | |||
| 219 | 219 | columns = inspect(engine).get_columns('orm_item') | |
| 220 | 220 | assert isinstance(columns[1]['type'], Vector) | |
| 221 | 221 | ||
| 222 | + def test_literal_binds(self): | ||
| 223 | + sql = select(Item).order_by(Item.embedding.l2_distance([1, 2, 3])).compile(compile_kwargs={'literal_binds': True}) | ||
| 224 | + assert "embedding <-> '[1.0,2.0,3.0]'" in str(sql) | ||
| 225 | + | ||
| 222 | 226 | @pytest.mark.asyncio | |
| 223 | 227 | async def test_async(self): | |
| 224 | 228 | engine = create_async_engine('postgresql+psycopg://localhost/pgvector_python_test') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments