Skip to content

Commit 86af42d

Browse files
committed
Added registerTypes function
1 parent c8ea95d commit 86af42d

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.1.5 (unreleased)
22

33
- Added support for `halfvec`, `bit`, and `sparsevec` types
4+
- Added `registerTypes` function
45

56
## 0.1.4 (2023-12-08)
67

src/main/java/com/pgvector/PGhalfvec.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,4 @@ public String getValue() {
100100
public float[] toArray() {
101101
return vec;
102102
}
103-
104-
/**
105-
* Registers the halfvec type
106-
*
107-
* @param conn connection
108-
* @throws SQLException exception
109-
*/
110-
public static void addHalfvecType(Connection conn) throws SQLException {
111-
conn.unwrap(PGConnection.class).addDataType("halfvec", PGhalfvec.class);
112-
}
113103
}

src/main/java/com/pgvector/PGsparsevec.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,4 @@ public int[] getIndices() {
278278
public float[] getValues() {
279279
return values;
280280
}
281-
282-
/**
283-
* Registers the sparsevec type
284-
*
285-
* @param conn connection
286-
* @throws SQLException exception
287-
*/
288-
public static void addSparsevecType(Connection conn) throws SQLException {
289-
conn.unwrap(PGConnection.class).addDataType("sparsevec", PGsparsevec.class);
290-
}
291281
}

src/main/java/com/pgvector/PGvector.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,17 @@ public float[] toArray() {
149149
public static void addVectorType(Connection conn) throws SQLException {
150150
conn.unwrap(PGConnection.class).addDataType("vector", PGvector.class);
151151
}
152+
153+
/**
154+
* Registers the vector, halfvec, and sparsevec types
155+
*
156+
* @param conn connection
157+
* @throws SQLException exception
158+
*/
159+
public static void registerTypes(Connection conn) throws SQLException {
160+
// bit type should be registered separately
161+
addVectorType(conn);
162+
conn.unwrap(PGConnection.class).addDataType("halfvec", PGhalfvec.class);
163+
conn.unwrap(PGConnection.class).addDataType("sparsevec", PGsparsevec.class);
164+
}
152165
}

src/test/java/com/pgvector/JDBCJavaTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void halfvecExample(boolean readBinary) throws SQLException {
9090
setupStmt.executeUpdate("CREATE EXTENSION IF NOT EXISTS vector");
9191
setupStmt.executeUpdate("DROP TABLE IF EXISTS jdbc_items");
9292

93-
PGhalfvec.addHalfvecType(conn);
93+
PGvector.registerTypes(conn);
9494

9595
Statement createStmt = conn.createStatement();
9696
createStmt.executeUpdate("CREATE TABLE jdbc_items (id bigserial PRIMARY KEY, embedding halfvec(3))");
@@ -191,7 +191,7 @@ void sparsevecExample(boolean readBinary) throws SQLException {
191191
setupStmt.executeUpdate("CREATE EXTENSION IF NOT EXISTS vector");
192192
setupStmt.executeUpdate("DROP TABLE IF EXISTS jdbc_items");
193193

194-
PGsparsevec.addSparsevecType(conn);
194+
PGvector.registerTypes(conn);
195195

196196
Statement createStmt = conn.createStatement();
197197
createStmt.executeUpdate("CREATE TABLE jdbc_items (id bigserial PRIMARY KEY, embedding sparsevec(3))");

0 commit comments

Comments
 (0)