Skip to content

Commit e831c58

Browse files
authored
Merge pull request #102 from psqlpy-python/feature/support_pg_vector
Added PgVector integration
2 parents 335e591 + b50c4fb commit e831c58

File tree

7 files changed

+189
-86
lines changed

7 files changed

+189
-86
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ itertools = "0.12.1"
5656
openssl-src = "300.2.2"
5757
openssl-sys = "0.9.102"
5858
pg_interval = { git = "https://github.com/chandr-andr/rust-postgres-interval.git", branch = "psqlpy" }
59+
pgvector = { git = "https://github.com/chandr-andr/pgvector-rust.git", branch = "psqlpy", features = [
60+
"postgres",
61+
] }

python/psqlpy/_internal/extra_types.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,16 @@ class IntervalArray:
774774
### Parameters:
775775
- `inner`: inner value, sequence of timedelta values.
776776
"""
777+
778+
class PgVector:
779+
"""Represent VECTOR in PostgreSQL."""
780+
781+
def __init__(
782+
self: Self,
783+
inner: typing.Sequence[float | int],
784+
) -> None:
785+
"""Create new instance of PgVector.
786+
787+
### Parameters:
788+
- `inner`: inner value, sequence of float or int values.
789+
"""

python/psqlpy/extra_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
MoneyArray,
2727
NumericArray,
2828
PathArray,
29+
PgVector,
2930
PointArray,
3031
PyBox,
3132
PyCircle,
@@ -98,4 +99,5 @@
9899
"LsegArray",
99100
"CircleArray",
100101
"IntervalArray",
102+
"PgVector",
101103
]

python/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async def psql_pool_with_cert_file(
117117

118118

119119
@pytest.fixture(autouse=True)
120-
async def create_deafult_data_for_tests(
120+
async def create_default_data_for_tests(
121121
psql_pool: ConnectionPool,
122122
table_name: str,
123123
number_database_records: int,

src/extra_types.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ use crate::{
1818
},
1919
};
2020

21+
#[pyclass]
22+
#[derive(Clone)]
23+
pub struct PgVector(Vec<f32>);
24+
25+
#[pymethods]
26+
impl PgVector {
27+
#[new]
28+
fn new(vector: Vec<f32>) -> Self {
29+
Self(vector)
30+
}
31+
}
32+
33+
impl PgVector {
34+
#[must_use]
35+
pub fn inner_value(self) -> Vec<f32> {
36+
self.0
37+
}
38+
}
39+
2140
macro_rules! build_python_type {
2241
($st_name:ident, $rust_type:ty) => {
2342
#[pyclass]
@@ -412,5 +431,6 @@ pub fn extra_types_module(_py: Python<'_>, pymod: &Bound<'_, PyModule>) -> PyRes
412431
pymod.add_class::<LsegArray>()?;
413432
pymod.add_class::<CircleArray>()?;
414433
pymod.add_class::<IntervalArray>()?;
434+
pymod.add_class::<PgVector>()?;
415435
Ok(())
416436
}

0 commit comments

Comments
 (0)